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
  • Avoid Ring’s Edge with QTI Sensors

Avoid Ring’s Edge with QTI Sensors

Navigate with QTIs -Avoid the Border

In the previous activity, you wrote a BlocklyProp program that turned lights on and off depending on the detection state of each QTI.  To make the SumoBot avoid the white border, this activity will guide you through adding another switch…case block for maneuvers.  It will use the same qtis variable with switch and the same case values, but the do (then break  ✓) inputs will contain CR servo PIN speed and pause (ms) blocks for maneuver wheel speeds and run times.  

Program

  • Watch this animation for tips on how to modify QTIs Test Front BW Detect.svg to make the LED indicator lights turn on if they are above the white sumo ring border.

 

  • Change the text in the upper-right name field from QTIs Front LED Indicators to QTIs Front Nav with LED Indicators.
  • Modify the program so that it matches this image.
  • Click save to save a copy of your work.
  • Click the Load & Run (Save code to EEPROM)  button  to load the program into your SumoBot.

 
Tests

  • Disconnect the SumoBot from the USB cable.
  • Set it on the sumo ring.
  • Set POWER to 2.
  • Verify that the SumoBot:
    • Backs up and turns right when the left QTI detects the white border.
    • Backs up and turns further to the right when both QTIs detect the white border.
    • Backs up and turns left when the right QTI detects the white border.
    • Continues forward when no QTIs detect the border.

How It Works

This code example adds a switch…case block that performs maneuvers immediately after the one that decides which LED lights to turn on/off.  

With each run function block, the program jumps to the function, executes the blocks contained by the function block, and then jumps back to continue at the next block below the run function block.  Looking inside the repeat forever…block, the first block is run function “QTIs Front”.  Even though the function QTIs Front block is collapsed, the blocks it contains still get run.  So, it checks the QTI sensors and sets binary 1s and 0s in the qtis variable.  When it’s done, the program picks up where it left off below the run function “QTIs Front” block.

Note that a disabled block does not run.  So the run function “QTIs Front Terminal” block gets skipped, and the next block is run function “QTI LED Indicators”.  The program jumps to that function block and goes through the switch…case block to turn the LED lights on/off.  When that’s done, the program jumps back to the next block in the repeat forever loop, which is the switch…case block for the maneuvers you added.

The maneuvers switch…case block executes a different set of blocks depending on the “case” of the qtis variable.  In the case where qtis is 11, it means both QTIs are over a black surface, so the SumoBot goes forward with no pauses.  After that, the (then break ✓) leaves the switch block.  At that point, the code reaches the end of the repeat forever block, and it starts over at the beginning.  So, the QTIs get rechecked again, the LED lights get updated, and then the program comes back to this switch…case block in a few thousandths of a second.  That allows the program to respond immediately to a case where one of the binary digits in the qtis variable is 0, indicating the white sumo ring border is detected.  For example, if the right QTI detects white, the case might be 10.  The blocks in that case make the SumoBot back up for 600 ms, then turn left for 600 ms before breaking from the switch…case and repeating the loop.      

 


Printer-friendly version
Test Front QTI Binary Values with LEDs
Prev

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress