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
  • cyber:bot Sumo Contests

cyber:bot Sumo Contests

Simplify Navigation with a Maneuver Function

Functions with parameters can allow you to set not only wheel speeds but run times.  The can also adjust for making the right wheel turn the opposite direction to give you a more intuitive set of statements.  Here is an example of a function call that makes the cyber:bot roll full speed forward for 3 seconds.  Note that the right wheel speed is no longer negative.  The rule for the maneuver function is that positive values are for forward, for either wheel.  The 3rd argument (3000) is the number of milliseconds to execute the maneuver.

Script: general-maneuver-function

  • Make sure the cyber:bot board’s power switch is set to 1 and the battery pack is plugged into the cyber:bot board.
  • Open cyberbot-template-with-blink with the micro:bit Python Editor at http://python.microbit.org/v/3
  • Replace its default script with individual-maneuver-functions-example shown below.
  • Click the Save button to save a copy of your work.

Tests

  • Click the Send to micro:bit button to flash the script into the micro:bit.
  • Disconnect the programing cable and put the cyber:bot on the floor.
  • Move the switch to position 2 and press/release the reset button on the micro:bit. (Or, set PWR to 0, then back to 2.).
  • Verify that the script makes the cyber:bot roll forward for 3 seconds, then turn in place to the right.
  • Set the PWR switch to 0 when the cyber:bot is not in use, and remember to unplug the battery pack from the cyber:bot board if you are done for the day.

How It Works

On line 5, the maneuver function definition has three parameters: vL (velocity left) vR (velocity right), and t (time, in milliseconds).  The three arguments in the function call on line 12 get passed to those parameters.  Likewise with the function call on line 13.  Line 7 takes the negative of vR, which is how the function takes positive values for forward and negative ones for backward.  The if vR is not None: statement prevents the vR = -vR statement from being executed when vR is None.  vR = -None would cause an exception because None is not a number and does not work with arithmetic operators.

Try This

Allowing the motors to come to a full stop can make maneuvers more predictable.  This next script makes the cyber:bot go forward, left, right, left, backwards, stop.  Between each actual maneuver, there’s a call setting the wheel speeds to None for 0.5 s.  This allows the wheels to come to a full stop before the next maneuver.

  • Try this script as-is first.
  • Then, comment all but the last maneuver(None, None, 500) call by adding a hashtag symbol to its left. Then, re-run the script.
  • What differences did you notice in the cyber:bot robot’s navigation?

Your Turn

While your cyber:bot SumoBot is searching for its opponent, splitting up maneuvers into little pieces will be important.  By checking the sensors between each 26 ms maneuver() call, your bot can keep rolling while searching for an opponent.  Here is an example where the cyber:bot calls the maneuver function 100 times, which takes about 2.6 seconds.  Adding sensor measurements between each call will make it take longer, but your robot will still be able to check for its opponent or the sumo ring’s border many times per second.  More about this in upcoming activities.


Printer-friendly version
Overview: Autonomous Sumo with the cyber:bot Robot
Prev
Connect and Test QTI Sensors
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress