In a sumo match, your SumoBot WX may have to detect and turn away from the sumo ring’s white circular border. The sensors it will use for this are called QTIs. In this section’s activities, you will:
In addition to items like a computer and SumoBot WX robot, you will also need experience (practice with earlier activities) before continuing here.
Items
Printable Sumo Ring Segment PDF [1]
YouTube video on making a Sumo Ring [2]
Experience
You will understand how to monitor the QTIs and use conditional switch...case blocks to execute different navigation routines, depending on what the QTI sensors report. You will also get some experience with loading prewritten functions that can do certain block code jobs for you, and creating and calling your own custom function blocks.
Like the servos, you’ll be using 3-wire cables to connect the QTI sensors to the SumoBot WX board. Unlike the servo cables, the cables for the QTIs have plugs on both ends. One end gets connected to the QTI, and the other gets connected to the SumoBot WX board.
The battery holder partially covers the slot for the cables to pass through, so the first step is to partially remove the battery holder to uncover the slot.
For best results, always test navigation and sensors separately before combining them in a robot app. Earlier, you built test programs that made the SumoBot perform a variety of maneuvers, so navigation testing is already done. Here, you will build a program that tests the values the QTI sensors measure and verify that they can detect the difference between the black and white sumo ring surfaces.
This first test will verify that your SumoBot robot’s QTIs return measurements that fall in the right ranges for indicating that they are over black or white surfaces.
It’s important to have a safety margin above and below that 230 threshold to identify black and white surfaces. For example, it would be best to ensure that white detection measurements are below 115 and black detections are above 460.
The height of the QTI’s light sensor surface above the sumo ring can have a big effect on the values. To adjust the QTI height, you can either adjust the plow height or add/remove nylon washers between the QTI and the standoff (or both).
The optimal range of distances above the sumo ring’s surface is between 1/20 and 1/10 inch (1.25 to 2.5 mm). So, it’s best to shoot for 1/16 of an inch (1.6 mm). Even if it’s up at ⅛ inch (3.175 mm), it should still work fine. Distances below 1/30 or above 3/16 of an inch (0.85 to 4.8 mm) start to approach those safety margin values or 115 for white and 460 for black).
The QRD1114 sensor’s datasheet actually says that the peak response is between 20 and 30 mils (thousandths of an inch). It’s not a good idea to mount it that close to the surface of the sumo ring because its sensitivity drops abruptly below 20 mils, but it declines gradually over 30 mils. Since the SumoBot could end up being pushed downward during a match, it’s better to have it riding higher above the surface than the datasheet specifies to make sure no incorrect measurements are reported. These factors and some additional testing all came into consideration when deciding on a 1/16 inch recommendation.
The QTI sensor takes a certain amount of time to respond depending on how reflective the surface is. (Remember, the QTI has to be facing the surface at about 1/16 of an inch away.) The QTI responds quickly over highly reflective white surfaces and slowly over less reflective dark surfaces. Even though the measurements are actually response time values, those values indicate how reflective the surface is.
To start a measurement, the QTI needs to be “primed” with a high signal. It’s the same kind of signal you will use to turn on an LED light in an upcoming activity, and it charges the QTI so that it can send a high signal. After the Propeller FLiP stops sending a high signal, it measures the amount of time the QTI continues to send that high signal back to the Propeller FLiP. That time indicates how reflective the surface is.
The make PIN 13 high block sends the high signal, and the pause (ms) 1 keeps that signal high for 1 millisecond, which is 1/1000 of a second. After that, the QTI is charged and ready to send the high signal back for a time that indicates reflectiveness of the surface. Next, the RC time PIN 13 discharge block makes the Propeller FLiP stop charging the QTI, and then measures how long the QTI continues to send that high signal back to the pin. It stores that microsecond (millionths of a second) time measurement in a variable named tLF. tLF is an abbreviation for time-left-front.
The same process is repeated for tRF and the QTI connected to P14.
This second test will verify that your SumoBot robot’s QTIs return the correct 1/0 measurements used in competition programs for detecting black/white surfaces. Instead of writing this program, you will download a pre-written example program, and then open it with BlocklyProp Solo.
QTIs Front Test BW Detect.svg [3]
Instead of the 230 magic number, this test will simply verify that each QTI measures 0 when over the white border or 1 over the black surface.
The run function "QTIs Front" block makes the program complete the blocks in the QTIs Front function container before continuing on to the Terminal clear screen block.
The QTIs Front function block sets two binary digits in a variable named qtis with 1 indicating a black surface and 0 indicating white. The left of the two binary digits indicates the 1/0 black/white state of the left QTI, and the right indicates the state of the right QTI.
Examples:
The QTIs Front function compares the QTI measurements to that 230 threshold. If the measurement is below 230, the function sets a digit in the qtis variable to 0. If it’s above 230, it sets that digit to 1.
In this activity, you will connect red light emitting diodes (LEDs) to the P5 and P6 sockets, and use them as visual indicators for sumo ring edge detection. In the next chapter, they will be removed and replaced with infrared LEDs as part of the infrared opponent detection system.
A switch...case block “switches” to different cases depending on the value in the block attached to switch. When a value attached to a case input matches the switch input, the blocks in the do (then break ✓) input are executed. If the (then break ✓) box is checked, the switch...case block does not check for any more cases after the first match.
In this switch...case block, if the qtis variable stores binary 00, it turns both LEDs on with the make PIN 5 high and make PIN 6 high blocks. After that, (then break ✓) causes it to skip all the other cases. In other words, the switch...case block only runs blocks for one case and ignores all the others. The next time through the repeat loop, the qtis variable might instead store binary 01. This time, the second case of 01 binary matches the qtis variable at the switch input. So, it runs the pair of blocks for that case: make PIN 5 high and make PIN 6 low. The result for each of these cases is that LEDs turn on to indicate that a given QTI is over a white surface, or off for a black surface.
For more info on the switch...case block, look it up in the Propeller BlocklyProp Reference control page [4].
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.
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.
Links
[1] https://learn.parallax.com/sites/default/files/content/Sumo/qti/SumoRingSegmentForTesting.pdf
[2] https://youtu.be/rJ-DPReqqEw
[3] https://learn.parallax.com/sites/default/files/content/Sumo/qti/QTIs%20Front%20Test%20BW%20Detect.svg
[4] https://learn.parallax.com/support/reference/propeller-blocklyprop-block-reference/control