Script: cyber_bot_gripper_forward_object
This script makes the Gripper-equipped cyber:bot:
- roll forward for 0.5 seconds,
- pick up an object,
- roll forward for another 1.25 seconds,
- set down the object,
- and back up for 0.5 seconds.
Let's give it a try.
- Right-click the cyber_bot_gripper_forward_object.hex link below, choose Save As, and then save the file to your computer.
cyber_bot_gripper_forward_object.hex
- Open the saved file with the micro:bit Python Editor editor.
The script was created by entering the text below into the python.microbit.org editor. The cyberbot.py module was also added to the Project Files as shown in Add modules to your micro:bit. The Script Name was set to cyber_bot_gripper_forward_object before saving it as a .hex file as shown in Save & Edit Scripts.
- Plug the battery pack’s barrel plug into the cyber:bot board’s barrel jack.
- Set the cyber:bot board’s PWR switch to 0.
- Click Send to micro:bit.
# cyber_bot_gripper_forward_object from cyberbot import * display.show(Image.ARROW_E) while True: if button_b.was_pressed(): display.clear() bot(16).servo_angle(150) # lower & open gripper sleep(1500) bot(18).servo_speed(130) # Forward 0.5 s bot(19).servo_speed(-130) sleep(500) bot(18).servo_speed(None) bot(19).servo_speed(None) sleep(1000) bot(16).servo_angle(30) # close gripper & lift sleep(1500) bot(18).servo_speed(130) # Forward 1.25 s bot(19).servo_speed(-130) sleep(1250) bot(18).servo_speed(None) bot(19).servo_speed(None) sleep(1000) bot(16).servo_angle(150) # lower & open gripper sleep(1500) bot(18).servo_speed(-130) # Backward 0.5 s bot(19).servo_speed(130) sleep(500) bot(18).servo_speed(None) bot(19).servo_speed(None) display.show(Image.ARROW_E)
Tests
Your cyber:bot robot might curve to the left or the right during these maneuvers. If it does, it can be straightened by slowing the servo that’s going faster and causing the curve. A remedy for this is included in the step-by-step instructions below.
- Disconnect the USB from the cyber:bot robot’s micro:bit module.
- Set the PWR switch to 2.
- Press/release the micro:bit module’s B button and verify that:
- The cyber:bot rolls forward half a second and then stops.
- The Gripper paddles close and lift an object.
- The cyber:bot rolls forward for another 1.25 seconds and then stops.
- The Gripper paddles lower and open to set down and release the object.
- The cyber:bot rolls backward for a half a second.
- If the cyber:bot curved right, the 130 value in bot(18).servo_speed(130) can be reduced to straighten its travel. Try reducing the speed by increments of 10 until it travels straight ahead. If it starts curving the other direction, increase by smaller increments until you are satisfied with the cyber:bot robot’s trajectory.
- If the cyber:bot curved to the left, the -130 value in bot(19).servo_speed(-130) will need to be reduced to straighten out its travel. Try -120, -110, etc. If one of the increments of 10 overcorrects, and it starts curving the other direction, back off by an increment of 5 and try again. Again, keep tuning until you are satisfied with the cyber:bot robot’s trajectory.
- When you are done, set the cyber:bot board’s PWR switch to 0 to conserve battery power.