Build this program --->
Sensors ... Left Reflectance, Right Reflectance
Text ... create text with.
Click the gear icon in the block to add more text items.
Run the program
Move your fingers over the line sensors.
Are the numbers changing?
If not, check your wiring. Refer to:
Wiring the sensors
Use a sheet of white paper (8.5" x 11") and (3) strips of 1/2" wide matte black tape to make a test track like this -->
Place your XRP over the paper in various positions and observe the sensor values:
Both sensors over white
Both sensors over the tape
Left sensor over the tape and right sensor over white
Right sensor over the tape and left sensor over white
Lift the XRP up off the paper
Slowly move the sensor from over white to over the edge over tap
What do you notice from the values you measured?
The documentation for the reflectance module in XRPLib states that the get_left() and get_right() functions return a number between 0 and 1.
Did your values ever reach exactly 0 or exactly 1?
Can you tell which range of numbers corresponds to seeing white and which range of numbers corresponds to seeing the tape? And what range of numbers is in between?
Write a program that moves forward until the line sensor(s) find the tape, then stops
Use a variable names "threshold" to hold the value that indicates that the line sensor is over the tape.
Be careful that your XRP does not crash into anything or fall off the table.
Start with the motors off.
Start the forward motion when the user button has been pressed. Wait one second before moving.
You can use "Set Effort 0.25 0.25" to move the motors
Use a function and name it "lineFound" with a "thresholdIn" parameter that returns "True" if a line is detected and "False" if no line.
Print the line sensor values to the shell/console for debugging
Use a loop to call the lineFound function repeatedly; include a sleep(0.1) so you can read the sensor values.
Test the program. Do you need to adjust the line sensor threshold to reliably detect the line?
If you are having trouble, ask someone who has a working program to explain what they've done.
Or, in the last resort, here's a program you can download that should work: find_line.blocks
Review this program carefully. Questions?
Can you increase the motor speed while still reliably finding the line?
How does the threshold factor impact performance and reliability?
Can you improve the user interface? Consider blinking the LED while waiting for the button to be pushed.
What are your ideas to improve this program?
Review the generated Micropython code (View ... Python).
Does it make sense? Any questions?
Do this activity with the other students at your table.
Use a large sheet of white paper and 1/2" black tape to make a continuous track for the XRP to follow.
Use wide radius curved corners to make it easier to follow.
Consider a circle, oval, or other closed curvy shape
Based on your "Find the Line" program, write an on/off control program that follows the line around the track.
Wait for the user button to be pushed before starting the motors
Test your program and make improvements so that the XRP is follwing the line.
If you are having trouble, ask someone who has a working program to explain what they've done.
If you are stuck and need help writing this program, you can download this simple example:
Click on [line_follow_simple.blocks]
Then click the download button (looks like this) --->
to save the file to your notebook.
Select a folder to save the file. Remember where you saved it!
In the XRP Code Editor, File ... Upload to XRP
Speed
Reliability
Ability to handle more complex track turns
Ability to find the line if it is lost
Your ideas?
Be sure to turn OFF the motor power switch when you are done driving!
(And especially during classroom breaks and after the end of class.
Otherwise, the battery will drain and you won't be able to drive.. 😞