Simple Line Follower Part III — Programming and Debugging the Robot

Here’s the completed simple line following robot:

Simple Line Following Robot SLFv1We choose a Pololu Mini Maestro 24-channel processor for this project.  Here’s the working source code:

mylabel:
100
begin
dup
while
led_off
1 minus

dup

23 get_position
200 greater_than
if
1
else
22 get_position
200 greater_than
if
33
else
100
endif
endif

less_than
if
8000 0 servo
else
4000 0 servo
endif
dup

20 get_position
200 greater_than
if
1
else
21 get_position
200 greater_than
if
33
else
100
endif
endif

less_than
if
8000 3 servo
else
4000 3 servo
led_on
endif

repeat
drop
goto mylabel

There’s a small learning curve when programming the mini maestro, but if you have experience with machine language it’s not too bad.  The scripting language uses a STACK and you have to place numbers on the stack before you can use them.  You also have to remember to not overload the stack, it can only hold so many numbers.  The first value I place on the stack is 100 and I use this value as a timer for pulse width modulating (PWM) the motors.  The program continuously counts from 1 to 100 and then starts over again.  Based on the sensor input each of the two motors turn at different speeds using PWM, depending on how far or close the robot is to the center of the line.

Here’s a youtube video of the working simple line following robot:

 

Leave a Reply

Your email address will not be published. Required fields are marked *