Script for the Tilt & Grip Controller with F360 Servos
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.
- Right-click the radio_tilt_grip_controller.hex link below, chose Save As, and then save the file to your computer.
radio_tilt_grip_controller.hex
- Open the saved file with the micro:bit Python Editor editor.
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. The Script Name was set to radio_tilt_grip_controller before saving it as a .hex file as shown in Save & Edit Scripts.
- Connect the micro:bit with battery pack to the USB cable (or your second cyber:bot that you plan to use as a tilt controller).
- Click Send to micro:bit.
- Disconnect the USB from the micro:bit module.
- Make sure the battery holder is connected to the micro:bit, and that it has some relatively new alkaline AA batteries. (Or, make sure the cyber:bot robot’s batteries are connected. The cyber:bot board switch should be in position 1.)
Project script: radio_tilt_grip_controller
# 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)