Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Navigation Control from a Keyboard

Cybersecurity: Navigation Control from a Keyboard

How the Wireless Controlled Bot Script Works

Like the transmitter script, the wireless receiver script’s import and radio calls are also similar to countdown_receiver.py.  The radio.config call’s length is set to 64 to accommodate longer strings if needed.  More importantly, since it has to actually control the cyber:bot, from microbit import * was changed to from cyberbot import *.

# terminal_controlled_bot_wireless

from cyberbot import *
import radio

radio.on()
radio.config(channel=7,length=64)

sleep(1000)

print("Ready...\n")

Inside the main loop, the script rapidly and repeatedly checks the radio.receive() method.  If the micro:bit has not received a radio message, it returns None.  If the micro:bit receives a packet (because you finished typing all three values and pressed Enter), then radio.receive returns a string that contains the dictionary.  That gets stored in a variable named packet.

while True:
    packet = radio.receive()

When radio.receive returns None, the rest of the script gets skipped and the while(True) loop repeats.  When radio.receive returns a string (with characters that represent a dictionary), the statements under if packet is not non are executed, starting with printing the packet.  (You can only see that if you have the cyber:bot tethered and connected to a terminal.)

    if packet is not None:
        print("Receive: ", packet)

This statement converts a string containing a dictionary into an actual dictionary.  The result is named dictionary.

        dictionary = eval(packet)

Assuming you typed 25, -25, 1000 in response to the prompts, the dictionary will be something like {‘vL’: 25, ‘vR’: -25, ‘ms’: 1000}.  (Again, the order of the key-value pairs doesn’t matter since you use the key to find its corresponding value.)  These statements use the ‘vL’, ‘vR’, and ‘ms’ keys to fetch the 25, -25, and 1000 values.

        vL = dictionary['vL']
        vR = dictionary['vR']
        ms = dictionary['ms']

With the variables named vL, vR, and ms now storing the correct values, all that’s left is to make the left and right wheels turn at 25 and -25. And, keep that maneuver going for 1000 ms with sleep before stopping the servos again.

        bot(18).servo_speed(vL)
        bot(19).servo_speed(-vR)
        sleep(ms)
        bot(18).servo_speed(None)
        bot(19).servo_speed(None)

 


Printer-friendly version
How the Wireless Controller Script Works
Prev
Try This: Test Transmitter Exceptions
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress