How test_gripper_angles_buttons_with_fb360 Works
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)
Try This: Handling with Care
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.
- Modify the test_gripper_angles_buttons script as shown below.
- Make sure to change was_pressed to is_pressed in the if and elif conditions.
- Set the project name to test_gripper_angles_buttons_with_fb360_try_this.
- Save your work by clicking Save.
- Click Send to micro:bit.
- Set the cyber:bot board's PWR switch to 2.
- Test by holding the B button until the Gripper goes all the way up, and then holding the A button until the Gripper goes all the way down and opens.