It might seem like you can control the robot's distance by setting a drive speed for a certain amount of time, but there are periods of time when the cyber:bot has to speed up and slow down. So, some trial and error is required if you’re navigating with speed control. With distance control, the cyber:bot calculates acceleration, cruising speed, and deceleration times before executing the maneuver. It also makes some fine adjustments at the end of each distance maneuver.
In this activity, you will use cyber:bot distance navigation techniques to make the cyber:bot robot roll to, pick up, move, and set down an object. The maneuvers will be very similar to the speed control examples from the previous activity. The main difference will be that you can measure a distance and then update the script to make the cyber:bot travel that distance.
(1) cyber:bot with Gripper installed, tested and tuned by following the Parts, Circuit, Script and Tests sections in the previous Test and Tune the Gripper [1] activity.
This script moves the cyber:bot in 3.25 mm increments. First, it rolls forward 32 increments, then picks up an object. Next, it rolls forward 96 increments and sets down the object. Finally, it backs up 32 increments.
cyber_bot_gripper_forward_object_distance_with_fb360.hex [2]
The script was created by entering the text below into the python.microbit.org/v/2 editor. The cyberbot.py and feedback360.py modules were also added to the Project Files as shown in Add modules to your micro:bit [4]. The Script Name was set to cyber_bot_gripper_forward_object before saving it as a .hex file as shown in How to Save and Reopen a Script in Python Editor v2 [5].
# cyber_bot_gripper_forward_object_distance_with_fb360 from cyberbot import * from feedback360 import * drive.connect() display.show(Image.ARROW_E) while True: if button_b.was_pressed(): display.clear() bot(15).servo_angle(150) # Lower & open gripper sleep(1500) drive.goto(32, 32) # Forward 0.5 wheel turn bot(15).servo_angle(30) # Close gripper & lift sleep(1500) drive.goto(96, 96) # Forward 1.5 wheel turns bot(15).servo_angle(150) # Lower & open gripper sleep(1500) drive.goto(-32, -32) # Backward 0.5 wheel turns display.show(Image.ARROW_E)
Speed matching isn’t just something the Feedback 360° servos do during speed maneuvers. These servos also work to match each other during distance maneuvers. So again, the tendency to curve strongly to the left or right is only a symptom of non-feedback continuous rotation servos. Also, again, that’s also not to say that there will be no curving at all, but any curving you observe is going to more likely be a result of things like slop in the angle of the servo’s output spline, bends in the chassis, and slight slippages accumulating over distances.
First, the script begins by importing the cyberbot and feedback360 modules as expected. Next, the script starts the feedback360.drive system with drive.connect(). Then, the script enters an endless while True: loop that monitors the micro:bit module’s B button to see if it was pressed.
# cyber_bot_gripper_forward_object_distance_with_fb360 from cyberbot import * from feedback360 import * drive.connect() display.show(Image.ARROW_E) while True: if button_b.was_pressed():
If the B button was pressed, the cyber:bot starts by lowering and opening the Gripper. Next, it rolls forward for half of a wheel turn, then stops. Then, the script uses bot(15).servo_angle(30) to close the Gripper. That is followed by sleep(1500) to give the Gripper time to close and lift, and partially to make a slight pause between picking up the object and starting to move.
display.clear() bot(15).servo_angle(150) # Lower & open gripper sleep(1500) drive.goto(32, 32) # Forward 0.5 wheel turn bot(15).servo_angle(30) # Close gripper & lift sleep(1500)
After lifting the object, this part of the script makes the cyber:bot roll forward 1.5 wheel turns. Then, it lowers and opens the Gripper, letting go of the object.
drive.goto(96, 96) # Forward 1.5 wheel turns bot(15).servo_angle(150) # Lower & open gripper sleep(1500)
Finally, it backs up half a wheel turn so that the object is no longer between the Gripper paddles.
drive.goto(-32, -32) # Backward 0.5 wheel turns display.show(Image.ARROW_E)
Again, let's add a a button A feature to make the cyber:bot take the object and place it where it started before you pressed button B.
Just as your cyber:bot could make turns with speed control, it can also make turns with distance control. With some modifications to the script, you can add any of the turns introduced in the Upgrade Your cyber:bot with Feedback 360 Servo chapter’s Maneuvers with Distance Control [6] activity.
Links
[1] https://learn.parallax.com/tutorials/robot/cyberbot/tilt-control-gripper-cyberbot-feedback-360%C2%B0-servos/test-and-tune-gripper
[2] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/cyber_bot_gripper_forward_object_distance_with_fb360.hex
[3] https://python.microbit.org/v/2
[4] https://learn.parallax.com/tutorials/robot/cyberbot/add-modules-your-microbit
[5] https://learn.parallax.com/tutorials/robot/cyberbot/how-save-and-reopen-script-python-editor-v2
[6] https://learn.parallax.com/tutorials/robot/cyberbot/upgrade-your-cyberbot-feedback-360-servos/maneuvers-distance-control