The receiver script is also adapted from a previous tutorial.
Starting with the countdown_receiver.py from the Send and Receive Packets [1] activity, you can replace its countdown while loop and printed message with the servo_speed and sleep(ms) calls from terminal_controlled_bot_tethered_try_this. You will also need to update the dictionary parsing so that it gets the vL, vR, and ms values using the 'vL', 'vR', and 'ms' keys. That’s the most crucial part of incorporating the radio-in to cyber:bot navigation-out part of your tethered app into script that wirelessly receives.
Here's a GIF showing the modification taking place:
You will also need to make a few other adjustments. Here they are step-by-step:
bot(18).servo_speed(vL) bot(19).servo_speed(-vR) sleep(ms) bot(18).servo_speed(None) bot(19).servo_speed(None)
print("value = ", value) print("message = ", message, "\n") while value >= 0: print(value) sleep(1000) value = value - 1 print(message)
value = dictionary['start'] message = dictionary['after']
vL = dictionary['vL'] vR = dictionary['vR'] ms = dictionary['ms']
print() print("Parse: ")
print("Countdown App") print("micro:bit sender")
print("Ready...\n")
radio.config(channel=7,length=50)
It should look like this:
radio.config(channel=7,length=64)
Now, your script should be ready.
# terminal_controlled_bot_wireless from cyberbot import * import radio radio.on() radio.config(channel=7,length=64) sleep(1000) print("Ready...\n") while True: packet = radio.receive() if packet is not None: print("Receive: ", packet) dictionary = eval(packet) vL = dictionary['vL'] vR = dictionary['vR'] ms = dictionary['ms'] bot(18).servo_speed(vL) bot(19).servo_speed(-vR) sleep(ms) bot(18).servo_speed(None) bot(19).servo_speed(None)
Links
[1] http://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-data/send-and-receive-packets