Connect and Test QTI Sensors
Since the infrared detectors are busy looking forward for opponents, how can the cyber:bot detect the edge of the SumoBot ring and turn away. One way is with the QTI line sensors, which can detect the difference between black and white surfaces.
Parts
Two sets of the parts below come with each QTI Line Follower AppKit for the Small Robot kit.
6 jumper wires: 2 each – red, blue, black
2-each of the parts shown in the picture
Assembly
Attach the QTIs to the bottom of the robot as shown.
Schematic
This is the schematic for the left and right QTIs. You will see how they are connected in the Wiring section.
Wiring
Connect the servo extension cables to the QTIs, making sure that the white wire is plugged into the W pin, the red wire is plugged into the R pin, and the black wire is plugged into the black pin.
Double check this for both QTIs
Run the servo extension cables through the space between the tail ball and chassis.
Connect the extension cables to the 3-pin headers.
Make sure the cables do not cross at any point. This will ensure the P8 I/O pin is connected to the left QTI and the P7 I/O pin is connected to the right.
Make sure the servo extension cables are plugged onto the 3-pin headers so that the black wires are plugged onto the pins that share the same row.
Hardware Setup
- Set the cyber:bot board’s power (PWR) switch to Position 0.
- Make sure the battery holder is loaded with 5 AA batteries.
- Make sure the battery holder’s barrel plug is firmly plugged into the cyber:bot board’s barrel jack.
- Connect your micro:bit module to your computer with a USB cable.
Software Setup
- In a Google Chrome or Microsoft Edge browser, go to python.microbit.org to open the micro:bit Python Editor.
- Go to Add modules to your micro:bit and watch the video on how to add modules to a project in the micro:bit Python Editor. It’s in the section titled: Adding a Module to micro:bit Filesystem.
- Still on the Add modules to your micro:bit page, follow the instructions below the video to download and unzip the cyberbot-micropython archive and add the cyberbot module to the micro:bit Python Editor’s Project settings.
- Add two more cyberbot-micropython modules to the project settings: qti.py and intbits.py.
- If the project settings are not open, click the editor’s project tab.
- Verify that the Project settings and verify that they resemble this:
Example Script: cyberbot_sumo_test_qtis
- Set the project’s name to cyberbot_sumo_test_qtis, enter the script below, and then click Save.
(See Save & Edit Scripts and Flash Scripts with Python Editor.) - Click Send to micro:bit.
(See Flash Scripts with Python Editor.)
Tests
- Connect the cyber:bot to the computer with the USB cable.
- Click the Send to micro:bit button to load the script into the micro:bit.
- Set the PWR switch to 1.
- Set the cyber:bot on the sumo ring with both QTIs over the black central part, and verify that both indicator lights on the micro:bit are on.
- Verify that when the cyber:bot is positioned with one QTI over the white border, the light on that side turns off.
- Test each side separately over the white border, and verify that each light turns off.
- Test both lights over the white border together and verify that they both turn off.
Troubleshooting
If the lights do not behave as expected, double check all electrical connections and each line of code.
Try This: Robot Avoids the White Border
- Change the project name from cyberbot_sumo_test_qtis to cyberbot_sumo_avoid_edge.
- Enter the script below into the micro:bit Python editor, then click Save.
Don’t worry about errors on lines 15 and 16. The micro:bit module’s MicroPython runtime engine handles it just fine even though the editor’s syntax checker doesn’t recognize it.
- Click the Send to micro:bit button to load the script into the micro:bit.
- Set the PWR switch to 2.
- Verify that the cyber:bot travels across the sumo ring’s black surface and backs up and turns away whenever it reaches the white edge.
Your Turn: Adjust Speeds & Turn Times
Adjust speeds up to +/- 115.
If one QTI sees the line, try tuning so that it turns away by about 120°.
If both QTIs detect in at the same time, it’s best to have the cyber:bot turn closer to 180°.