![STEMCenter USA Pi-Bot v2.00 User Manual Download Page 93](http://html.mh-extra.com/html/stemcenter-usa/pi-bot-v2-00/pi-bot-v2-00_user-manual_1372067093.webp)
93
Line Following – Advanced Programming
More advanced programming can be created to allow your Pi-Bot to operate more precisely. Run the
program, AdvancedLineFollowing below. This is an example of a more sophisticated line following
algorithm.
While your Pi-Bot will not run any faster using this program, it is more reliable and can easily track
around sharp corners. The program continuously samples each of the three line sensors and stores the
latest N samples for each detector where N can be any integer value between 2 and 50. The samples are
stored in three arrays, one for each detector. After each set of samples are read, the program places the
samples on the top of the arrays and shifts the current samples down for each array. The samples at the
bottom of the arrays are discarded. After the arrays are shifted down and the latest samples are placed
on the top of the arrays, a weighted sum is generated from the arrays for each of the detectors.
Basically, instead of having an on/off value for each detector, there are values related to how long your
Pi-Bot is has been off the line. The longer it has been off the line, the larger the differential speed is
between the wheels to get your Pi-Bot back on track.
In the program, N is set to 8. The speed value for each motor is controlled by the ratio of the weighted
sum of the side detectors to the center detector. This algorithm is very sensitive to the motor voltage
supplied by the 3 AA batteries. As the battery voltages lower with use, or if you are using rechargeable
NiCads batteries, the performance changes. To minimize this effect, the program reads the motor
battery voltage using the analog input and adjusts the PWM voltage accordingly.
THEREFORE, YOU
MUST RUN A JUMPER FROM THE BREADBOARD, H-BRIDGE PIN 15 (MOTOR BATTERY POWER) TO A0
OF THE ANALOG INPUT ON THE STEM BOARD. WITHOUT THE JUMPER, THE PROGRAM WILL NOT
WORK CORRECTLY.
Also, this will not fix dead batteries. If your batteries cannot supply enough current
to run the motors, no programming will help! As you familiarize yourself with the program, change the
values to experiment. You can use this program as a starting point or just as a learning tool to develop
your own (and better) control program.
AdvancedLineFollowing Program
Summary of Contents for Pi-Bot v2.00
Page 67: ...67 Figure 6 15 ...
Page 78: ...78 UltraSonicSensorTestwithLED Program ...
Page 80: ...80 ObstacleAvoidance Program ...
Page 82: ...82 ObstacleAvoidancewithLED Program ...
Page 83: ...83 ObstacleAvoidancewithLED Program CONTINUED ...
Page 90: ...90 Download and run the following program LineFollowing Program ...
Page 91: ...91 LineFollowing Program CONTINUED ...
Page 94: ...94 AdvancedLineFollowing Program CONTINUED ...
Page 95: ...95 AdvancedLineFollowing Program CONTINUED ...
Page 96: ...96 AdvancedLineFollowing Program CONTINUED ...
Page 110: ...Appendix B Complete Pi Bot Wiring Schematic ...