This is a simple tethered application where you type in left and right wheel speeds, and run time in milliseconds, into a terminal. When you press Enter, your text gets parsed and executed by the micro:bit, which then makes the cyber:bot execute the maneuver.
Example Script: terminal_controlled_bot_tethered_intro
- Make sure the cyber:bot’s batteries are connected, and its 3-position switch is set to 2.
- Add the cyber:bot module to your project.
- Enter this script and save it as terminal_controlled_bot_tethered_intro.
- Flash the script into the micro:bit.
Example Script: terminal_controlled_bot_tethered_intro
# terminal_controlled_bot_tethered_intro from cyberbot import * sleep(1000) print("\nSpeeds are -100 to 100\n") while(True): text = input("Enter left speed: ") vL = int(text) text = input("Enter right speed: ") vR = int(text) text = input("Enter ms to run: ") ms = int(text) bot(18).servo_speed(vL) bot(19).servo_speed(-vR) sleep(ms) bot(18).servo_speed(None) bot(19).servo_speed(None) print()
Since your cyber:bot is currently tethered, it’s best to use low speeds and short run times. Otherwise, your cyber:bot might try to roll beyond the tether length. In other words, it’ll try to unplug itself from the USB cable, or maybe roll off the table.
- Use the Open Serial button to start the terminal.
- Click in the terminal and type 25 in response to the Enter right speed: prompt, then press Enter.
- Type 25 in response to the Enter left speed: prompt, then press Enter.
- Type 750 in response to the Enter ms to run: prompt, and press Enter.
- Verify that your cyber:bot rolled forward for about ¾ of a second.
- Next, try -25, -25, and 750. Did it roll backwards?
- Now, try 25, -25, 750. Did it pivot to the right?
- Try 25, 10, 750 for a curving motion.
- Can you make it turn in place left and right?
- Try causing an exception by typing non-digits in response to one of the prompts.
For example, what happens if you type abc and press enter? For now, you can press/release the reset button to restart the app. You will add some exception handling in the your turn section to prevent this from happening.