Skip to content
Parallax Learn (Stage)

Parallax Learn (Stage)

This is the staging site. Please see https://learn.parallax.com for the official site.

  • 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 Tutorial Series
          • Cybersecurity: Radio Data tutorialCybersecurity Tutorial Series
          • cyber:bot Tutorial Series
          • Boe-Bot Tutorial SeriesBoe-Bot Tutorial Series
          • Arduino Shield-Bot Tutorial Series
          • ActivityBot with C TutorialsActivityBot with C Tutorials
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot with BlocklyProp Tutorial Series
          • Scribbler 3 Tutorial SeriesScribbler 3 Tutorial Series
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education Tutorial Series
          • Propeller C-Language BasicsPropeller C Basics and Projects
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit C Tutorial Series
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit BlocklyProp Tutorials
          • Badge WX Tutorial SeriesBadge WX Tutorial Series
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics and Projects
          • 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
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • Cybersecurity: Radio Tilt Control

Cybersecurity: Radio Tilt Control

Radio Tilt Controlled cyber:bot Code

This is the receiver script for your Radio Tilt Controlled cyber:bot.  You will also need to load the script on the next page into the tilt controller micro:bit (or cyber:bot) you will use to drive this receiver cyber:bot.

  • Set the cyber:bot board’s PWR switch to 0.
  • Make sure you are working in the browser with the micro:bit Python Editor that is connected to the radio tilt controlled cyber:bot.
  • Depending on the path you took to get here, your most recent script will either be radio_tilt_receive_test or  radio_tilt_bot_fb_lr_with_stop_range.  If your most recent script is not already open, click Open to load it into the editor.
  • Change the project name to radio_tilt_controlled_cyberbot.
  • Update the script to match the one below.
  • If you are in a classroom, adjust the channel= in the script to your assigned channel.
  • Click Save, and then click Send to micro:bit.  
# radio_tilt_controlled_cyberbot

from cyberbot import *
import radio

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

while True:

    packet = radio.receive()

    if packet:

        try:

            dictionary = eval(packet)
    
            x = dictionary.get('x')
            y = dictionary.get('y')
            needle = dictionary.get('needle')
            
            fb = y / 10
            lr = x / 10

        except Exception as e:

            display.show(Image.SAD)
            print("Exception e:", e)
            print("Type:", type(e))
            continue

        else:

            if abs(fb) > 8:
                display.show(Image.ALL_CLOCKS[needle])
                vL = fb
                vR = -fb

                if(fb < 0): lr = -lr
                vL = vL - lr
                vR = vR - lr

            else:

                display.show(Image.DIAMOND_SMALL)
                vL = None
                vR = None

        finally:

            bot(18).servo_speed(vL)
            bot(19).servo_speed(vR)

 

How it Works

If you came straight here to run the application, this section only explains finishing touches.  You can start at the beginning of this tutorial and read through or actually do the activities that introduce one concept at a time and incrementally build the scripts.

The radio_tilt_controlled_cyberbot script started as radio_tilt_bot_fb_lr_with_stop_range from the Add Right/Left Tilt Control activity.  Along with How It Works sections in some of the earlier activities, it will allow you to take a closer look at the mechanics of the tilt control app.  

As mentioned earlier, exception handling helps prevent other radio messages on the same channel from causing your tilt controlled cyber:bot from throwing an exception in the middle of a maneuver.  The only change to the script is that try…except…else… and finally were added at key points, and the code below each was indented.  For details on how try…except…else…finally works, read or better still, try the activities in the Exception Handling Primer.

 


Printer-friendly version
Radio Tilt Controlled cyber:bot App
Prev
Radio Tilt Controller Code
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn (Stage) • Built with GeneratePress