This project is written especially for cyber:bot robots that have been upgraded with Parallax Feedback 360° servos. If your cyber:bot instead has the continuous rotation servos that came in the regular kit, go to Tilt-Controlled Gripper with the cyber:bot Robot [1]instead.
The activities in this project will help you test and tune your Gripper with a cyber:bot that has been upgraded with Feedback 360° servos. They also introduce expanding basic cyber:bot maneuvers by picking up and setting down objects along the way. If you have an extra micro:bit GO Bundle (or a second cyber:bot robot with micro:bit), try the fourth activity too. It extends the Cybersecurity: Radio Tilt Control [2] project by adding remote button control to pick up and set down objects.
You will need:
Complete these tutorials first:
You will be able to:
Gripper control with the cyber:bot robot can be a great first step toward robotics contests that involve fetching and sorting objects. Gripper control with the cyber:bot robot also introduces the basics of robotic arm control. Vending machines, manufacturing, medical research, underwater remotely operated vehicle “hands and arms,” these devices and machines have engineer designers and technical staff to make sure they run properly. So, this could even be the first step toward a variety of job opportunities.
The three main goals of this activity are to:
(1) Resistor - 220 Ω (red-red-brown-gold)
(1) 3-pin header
(1) Jumper wire - red
(1) Jumper wire - black
(1) cyber:bot robot with micro:bit v2, and with the Gripper kit installed following the instructions in these chapters:
The script will turn the Gripper control servo to its 30° position to make the gripper close and lift, and to its 150° position to make the Gripper paddles lower and open. If your Gripper does not properly complete both motions, the troubleshooting section (just below this section) has a script you can run while making mechanical adjustments.
test_gripper_angles_buttons_with_fb360.hex [13]
Note: The script was created by entering the python script below and adding the cyberbot.py and feedback360.py modules to the Project Files as shown in Add modules to your micro:bit [8]. The Script Name was set to test_gripper_angles_buttons_with_fb360 before saving it as a .hex file as shown in How to Save and Reopen a Script in Python Editor v2 [9].
# test_gripper_angles_buttons_with_fb360 from cyberbot import * display.show(Image.ARROW_E) while True: if button_b.was_pressed(): bot(15).servo_angle(30) # Close gripper & lift display.show(Image.ARROW_W) elif button_a.was_pressed(): bot(15).servo_angle(150) # Lower gripper & open display.show(Image.ARROW_E)
The main purpose of these tests is to verify that the script makes the Gripper paddles complete both the close/lift and lower/open motions. If it doesn’t do both correctly, try the Troubleshooting section below.
If your Gripper passed the Tests section and does not need troubleshooting, continue to the next section. Otherwise, continue below.
In the Gripper 3.0 Assembly Instructions [12], there’s a Tuning and Programming [15] activity with a Physically Position the Servo and Gripper section. It has instructions to “Move the servo through its range of motion and make sure it is centered when the Gripper is the closed, lowered position.” Here are some steps you can follow to make sure this was done correctly:
center_grippper_with_fb360.hex [16]
# center_gripper_with_fb360 from cyberbot import * display.show('C') bot(15).servo_angle(90) # Lower only, leave closed
If you answered “No.” to either of the two questions, here’s how to fix it:
After importing the cyberbot module, the script uses display.show(Image.ARROW_E) to point at the micro:bit module’s B button.
# test_gripper_angles_buttons_with_fb360 from cyberbot import * display.show(Image.ARROW_E)
The main loop repeatedly checks if either the A or B buttons have been pressed. If the B button was pressed since the last time it checked, the bot(15).servo_angle(30) call closes and lifts the Gripper. If the A button was pressed since the last time it checked, the bot(15).servo_angle(150) call lowers and opens the Fripper. Both servo_angle calls can be considered “set it and forget it” so the servo will hold the position it was most recently set set to. Whenever a particular button is pressed, the arrow is updated to point at the other button.
while True: if button_b.was_pressed(): bot(15).servo_angle(30) # Close gripper & lift display.show(Image.ARROW_W) elif button_a.was_pressed(): bot(15).servo_angle(150) # Lower gripper & open display.show(Image.ARROW_E)
Some objects need to be lifted and set down more carefully, like objects with narrower bases. As an example of how you might accomplish this with the Gripper, try modifying the test script to make the Gripper paddles open and close more gradually. Since there's no servo_speed for the standard servos, we have to use a loop to slow the servo's rotation.
A standard servo turns to and holds a certain angle in response to a rapid series of timed on/off signals from the cyber:bot board. This is the kind of servo that controls the Gripper. The Parallax Standard Servo can turn to and hold positions in the 0° to 180° range.
A continuous rotation servo turns at certain approximate speeds in response to a rapid series of timed on/off signals from the cyber:bot board. This was the kind of servo that controlled the cyber:bot robot’s wheels before you upgraded them to Feedback 360° servos.
A feedback servo is a continuous rotation servo that can measure and report its angular position as “feedback.” The cyber:bot board uses the Feedback 360° servos’ angular position reports to adjust the speed control signals to make them maintain certain speeds and travel certain distances.
Instead of you having to hold down the A/B buttons, the script can make the gripper gradually open and close on its own automatically after a button press-release. Simply put the statements updating the degrees variable and servo degree angle in a while loop that continues while the angle is greater than 30. A similar loop could also be written for button A that continues while degrees is less than 150.
In this activity, you will add cyber:bot navigation techniques to make the cyber:bot robot roll to, pick up, move, and set down objects. The example scripts will control the Feedback 360° servos much like the normal continuous rotation servos, by setting speeds for certain run times. In the next activity after this one, you use the distance travel features that are only available with the Feedback 360° servos.
(1) cyber:bot with gripper installed, and tested and tuned by following the Parts, Circuit, Script and Tests sections in the previous activity.
This script rolls forward for 0.5 seconds, picks up an object, rolls forward for another 1.25 seconds, sets down the object, backs up for 0.5 seconds, and then stops.
cyber_bot_gripper_forward_object_with_fb360.hex [17]
The script was created by entering the text below into the python.microbit.org/v/2 [14] editor. The cyberbot and feedback360 modules were also added to the Project Files as shown in Add modules to your micro:bit [8]. The Script Name was set to cyber_bot_gripper_forward_object_with_fb360 before saving it as a .hex file as shown in How to Save and Reopen a Script in Python Editor v2 [9].
# cyber_bot_gripper_forward_object_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.speed(64, 64) # Forward 0.5 s sleep(500) drive.speed(0, 0) sleep(1000) bot(15).servo_angle(30) # Close gripper & lift sleep(1500) drive.speed(64, 64) # Forward 1.25 s sleep(1250) drive.speed(0, 0) sleep(1000) bot(15).servo_angle(150) # Lower & open gripper sleep(1500) drive.speed(-64, -64) # Backward 0.5 s sleep(500) drive.speed(0, 0) display.show(Image.ARROW_E)
Feedback 360° servos correct to match each other’s speed, so there is no need to adjust for speed differences that would cause significant curving in the navigation. That is only a symptom of non-feedback continuous rotation servos. That isn't 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, subtle bends in the chassis, and slight slippages accumulating over distances.
After importing the cyberbot feedback 360 modules, starting the feedback360.drive system with drive.connect(), and pointing toward the B button, the script goes into an endless while True: loop that monitors the micro:bit module’s B button.
# cyber_bot_gripper_forward_object_with_fb360 from cyberbot import * from feedback360 import * drive.connect() display.show(Image.ARROW_E) while True:
If the B button was pressed, the cyber:bot starts by rolling forward at 64 increments per second for ½ a second, then stops. An increment is a 64th of a turn, so it means the wheel is turning one revolution per second, or 60 revolutions per minute (RPM).
The routine is appended with a sleep(1000) call to make sure the cyber:bot has completely come to rest. Once at full stop, the script uses bot(15).servo_angle(30) to close the Gripper. It is followed by sleep(1500) to give the gripper time to close and lift, and also to make a slight pause between picking up the object and starting to move.
if button_b.was_pressed(): display.clear() bot(15).servo_angle(150) # lower & open gripper sleep(1500) drive.speed(64, 64) # Forward 0.5 s sleep(500) drive.speed(0, 0) sleep(1000) 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 for 1.25 s. Then, it lowers and opens the Gripper, setting down the object.
drive.speed(64, 64) # Forward 1.25 s sleep(1250) drive.speed(0, 0) sleep(1000) bot(15).servo_angle(150) # Lower & open gripper sleep(1500)
Finally, it backs up for 0.5 s so that the object is no longer between the Gripper paddles.
drive.speed(-64, -64) # Backward 0.5 s sleep(500) drive.speed(0, 0) display.show(Image.ARROW_E)
Let's add a button A feature to make the cyber:bot take an object and place it back where it started before you pressed button B.
Your Gripper-equipped cyber:bot with Feedback 360° servos is by no means limited to forward and backward. With some modifications to the script, you can add any of the turns introduced in the Upgrade Your cyber:bot with Feedback 360 Servos [11] project’s Maneuvers with Speed Control [18] and More Turning Maneuvers [19] activities.
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 [20] 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 [21]
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 [8]. 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 [9].
# 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 [22] activity.
This project allows you to use a second micro:bit to tilt control the cyber:bot robot and use its B and A buttons to remotely close and lift and lower and open.
For those who have a class set of cyber:bot robots, a second cyber:bot with batteries can be used as a tilt controller if an extra micro:bit GO kit is not available on its own.
This is the script to run on the cyber:bot robot. It receives values from the micro:bit tilt controller that are used for its Feedback 360 drive servos and Gripper servo.
radio_tilt_grip_controlled_cyberbot_with_fb360.hex [24]
The .hex file download was created by entering the Python script below into the python.microbit.org/v/2 editor, and also adding the cyberbot.py and Feedback360.py modules to the Project File as shown in Add Modules to your micro:bit. [8] The Script Name was set to radio_tilt_grip_controller before saving it as a .hex file as shown in How to Save and Reopen a Script in Python Editor v2 [9].
# radio_tilt_grip_controlled_cyberbot_with_fb360 from cyberbot import * from feedback360 import * import radio drive.connect() radio.on() radio.config(channel=7, queue=1, length=64) while True: packet = radio.receive() if packet: try: dictionary = eval(packet) x = dictionary.get('x') y = dictionary.get('y') needle = dictionary.get('needle') fb = y / 10 lr = x / 10 button = dictionary['button'] # added except Exception as e: display.show(Image.SAD) print("Exception e:", e) print("Type:", type(e)) continue else: if abs(y) > 80: display.show(Image.ALL_CLOCKS[needle]) vL = fb vR = -fb if(fb < 0): lr = -lr vL = vL - lr/2 # Reduced lr term by 2 vR = vR - lr/2 # Reduced lr term by 2 else: display.show(Image.DIAMOND_SMALL) vL = 0 vR = 0 if button == 'B': # added bot(15).servo_angle(30) # added Gripper close & lift elif button == 'A': # added bot(15).servo_angle(150) # added Gripper lower & open finally: drive.speed(vL/2, -vR/2)
This is the script to run on the micro:bit module serving as the tilt controller for the Gripper-equipped cyber:bot robot with Feedback 360° servos. It takes measurements from its onboard tilt sensor and sends radio data values to the cyber:bot for its Feedback 360° drive servos and Gripper servo.
radio_tilt_grip_controller.hex [26]
The .hex file download was created by entering the Python script below into the python.microbit.org/v/2 editor, and also adding the radio and math modules to the Project File as shown in Add Modules to your micro:bit. [8] The Script Name was set to radio_tilt_grip_controller before saving it as a .hex file as shown in How to Save and Reopen a Script in Python Editor v2 [9].
# radio_tilt_grip_controller from microbit import * import math import radio radio.on() radio.config(channel=7, queue=1, length=64) while True: x = accelerometer.get_x() y = accelerometer.get_y() angle = round( math.degrees( math.atan2(y, x) ) ) needle = ( angle + 90 + 15 ) // 30 if abs(y) > 80: display.show(Image.ALL_CLOCKS[needle]) else: display.show(Image.DIAMOND_SMALL) dictionary = { } dictionary['x'] = x dictionary['y'] = y dictionary['needle'] = needle if button_b.was_pressed(): # add dictionary['button'] = 'B' # add elif button_a.was_pressed(): # add dictionary['button'] = 'A' # add else: dictionary['button'] = 'None' # add packet = str(dictionary) radio.send(packet) sleep(50)
Follow these step-by-step instructions to test the tilt-drive and Gripper control features of the remote controlled cyber:bot with Gripper and Feedback 360° servos.
The scripts in this activity are just slightly expanded versions of the ones from the Cybersecurity: Radio Tilt Control [2] tutorial’s Radio Tilt Controlled cyber:bot App [27] activity.
First, the script had to be ported from continuous rotation servo control to Feedback 360° servo control. The changes to the script that have to be made to work with the new servos are explained in the How to Update Scripts for Feedback 360° Servos [28] activity.
To add button control to the Radio Tilt Controller Code [29], the routine below was added to the transmitting tilt controller app. It expands the dictionary to contain data indicating which of the micro:bit module’s buttons were pressed. Before this, it just contained x, y, and needle key value pairs.
if button_b.was_pressed(): # add dictionary['button'] = 'B' # add elif button_a.was_pressed(): # add dictionary['button'] = 'A' # add else: dictionary['button'] = 'None' # add
This line was added to the Radio Controlled cyber:bot Code.
button = dictionary['button'] # added
These lines were added to respond to the button values by opening or closing the Gripper.
if button == 'B': # added bot(15).servo_angle(30) # added Gripper close & lift elif button == 'A': # added bot(15).servo_angle(150) # added Gripper lower & open
The tilt controller might be a little too responsive, but slowing it down isn’t hard. There are two facets to slowing it down.
First, the "stay still" range where there’s no no motion and the micro:bit displays a diamond can be extended from 80 to 200. This will help prevent accidentally moving the cyber:bot when you press a button on the micro:bit tilt controller.
Second, instead of dividing x and y tilts by 10 for a speed range of -100 to 100, you can divide them by 20 for half the speed range. This is helpful especially when you are getting used to controlling the cyber:bot with the Gripper.
In radio_tilt_grip_controller:
if abs(y) > 80: # Change from 80 to 200
In radio_tilt_grip_controlled_cyberbot:
fb = y / 10 # change divide by 20 instead of 10 lr = x / 10 # change divide by 20 instead of 10 … if abs(y) > 80: # change to if abs(y) > 200:
A dictionary with key-value pairs is a powerful way to organize data before exchanging it with another device. That’s the main reason why it took so few extra Python statements to add gripper functionality to the existing Radio Tilt Controlled cyber:bot project.
Here are a few ideas for putting your Tilt Controlled Gripper cyber:bot with Feedback 360° servos to use and having some fun!
Links
[1] https://learn.parallax.com/tutorials/robot/cyberbot/tilt-controlled-gripper-cyberbot-robot
[2] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-tilt-control
[3] https://www.parallax.com/product/32700
[4] https://www.parallax.com/product/parallax-feedback-360-high-speed-servo/
[5] https://www.parallax.com/product/28203
[6] https://www.parallax.com/product/microbit-2-0-go-bundle/
[7] https://learn.parallax.com/tutorials/robot/cyberbot/writing-microbit-programs
[8] https://learn.parallax.com/tutorials/robot/cyberbot/add-modules-your-microbit
[9] https://learn.parallax.com/tutorials/robot/cyberbot/how-save-and-reopen-script-python-editor-v2
[10] https://learn.parallax.com/tutorials/robot/cyberbot/build-your-cyberbot-rev-c-board
[11] https://learn.parallax.com/tutorials/robot/cyberbot/upgrade-your-cyberbot-feedback-360-servos
[12] https://learn.parallax.com/gripper
[13] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/test_gripper_angles_buttons_with_fb360.hex
[14] https://python.microbit.org/v/2
[15] https://learn.parallax.com/tutorials/gripper-30-assembly-instructions/tuning-and-programming
[16] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/center_gripper_with_fb360.hex
[17] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/cyber_bot_gripper_forward_object_with_fb360.hex
[18] https://learn.parallax.com/tutorials/robot/cyberbot/upgrade-your-cyberbot-feedback-360-servos/maneuvers-speed-control
[19] https://learn.parallax.com/tutorials/robot/cyberbot/upgrade-your-cyberbot-feedback-360-servos/maneuvers-speed-control/more
[20] https://learn.parallax.com/tutorials/robot/cyberbot/tilt-control-gripper-cyberbot-feedback-360%C2%B0-servos/test-and-tune-gripper
[21] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/cyber_bot_gripper_forward_object_distance_with_fb360.hex
[22] https://learn.parallax.com/tutorials/robot/cyberbot/upgrade-your-cyberbot-feedback-360-servos/maneuvers-distance-control
[23] https://learn.parallax.com/tutorials/robot/cyberbot/tilt-control-gripper-cyberbot-feedback-360%C2%B0-servos/go-and-get-object-speed
[24] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/radio_tilt_grip_controlled_cyberbot_with_fb360.hex
[25] https://python.micrbit.org/v/2
[26] https://learn.parallax.com/sites/default/files/content/cyberbot/GripperF360/Hex/radio_tilt_grip_controller.hex
[27] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-tilt-control/radio-tilt-controlled-cyberbot-app
[28] https://learn.parallax.com/tutorials/robot/cyberbot/upgrade-your-cyberbot-feedback-360-servos/how-update-scripts-feedback-360-1
[29] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-tilt-control/radio-tilt-controlled-cyberbot-app/radio-0