At this point, you might be wondering how to modify an existing script to make it work with Feedback 360° servos. For example, what if you wanted to update scripts from Touch Navigation for the cyber:bot or maybe Cybersecurity: Radio Tilt Control? In this activity, you will learn the simple steps for updating any cyber:bot application script to work with the Feedback 360° servos.
MEMORY WARNING! Your cyber:bot will need to use a micro:bit v2 or newer for most cyber:bot applications that use the F360° servos; the v1.5 micro:bit does not have enough memory.
Here is a summary and diagram of how to adjust an existing cyber:bot script so that it runs with the Feedback 360° servos. Starting with the feedback_360_template.hex, add from feedback360 import * and drive.connect() just below from cyberbot import *. Then, any time you see bot(18).servo_speed(vL) and bot(19).servo_speed(vR), use the vL and vR values in drive.speed(int(vL/2), -int(vR/2)). The term int(vL/2) means divide the original vL by 2 and round down. The term int(-vR/2) means divide the original vR by 2 and round down, and take its negative value. Important: replace None with 0.
In this activity you will follow this procedure, broken into five steps. Examples with both constant values (like 75), and variables (like vL and vR) will be used. It should encompass just about any script you might want to adapt to your new Feedback 360° servos.
Parts
A cyber:bot robot with two Feedback 360° High Speed Servos installed following the instructions in the Swap and Test the Servos section.
Steps to Update a Script for the Feedback 360° Servos
Here are the steps you can follow to adapt just about any existing cyber:bot application script to Feedback 360° servos.
Step 1: Download and start with the feedback_360_template.hex, and enter the original script. Note: the template already has the cyberbot and feedback360 modules added by the procedure in Add modules to your micro:bit. (Remember to always right-click and chose Save As to download hex files.)
Step 2: Add two lines just below from cyberbot import *:
from feedback360 import * drive.connect()
Step 3: Take the vL and vR values from these two statements:
bot(18).servo_speed(vL) bot(19).servo_speed(vR)
…and add this statement immediately below them:
drive.speed(int(vL/2), -int(vR/2))
IMPORTANT! If you see None as either the vL or vR value, replace it with 0.
NOTE: The term int(vL/2) means "divide by 2 and round down."
Step 4: Use the # symbol to comment the bot(18).servo_speed(vL) and bot(19).servo_speed(vR) statements.
Step 5 (optional): After you have verified that your adjustments work properly, optionally remove all the bot(18/19).servo_speed… calls.