Friday, 15 April 2011

Line Follower Algorithm - Which is the best?


Single Light Sensor - Bit logic method (1 Min 59 Sec)
Read full post here.


Single Light Sensor - PID method - Smooth (1 Min 29 Sec)
Read full post here.



Single Light Sensor - PID method - Over Correction (53 Sec)
Read full post here.



Dual Light Sensor - PID method - Smooth and Fast (33 Sec)
I have not posted about this Line follower that I had built. It moves really fast and because there is 2 light sensors, it is able to adjust and move along quickly. I am trying to optimize the dual sensor to go even faster. Will post the outcome when I am done.

Line Follower - PID Method - Over corrected!



This post is a followup to the previous PID Line Follower post, of which I was using the PID method. As you would have noticed in the previous post, the Line follower robot was moving very smoothly over the black line, however it was extremely slow!

Please note that the line follower robot is only using 1 light sensor, the left one. The robot has been built with 2 sensors for future test algorithm.

In this followup post, you'll notice that the robot moves along at faster rate, but the robot seems to be constantly oscillating, with a few occasion that it manage to reach equilibrium. This is because the robot seems to be over compensating. The reason that this could happen is because is because the robot's feedback loop is too slow to react, and is NOT able to compensate quick enough, causing it to go into an oscillation mode. I would have to re-code the robot using NXC or RobotC to overcome the speed issue.

Another possibility is because of the variables that I have used to adjust the robot for a faster speed, rather than a smooth moving robot. Maybe the setup variables is inaccurate, thus the robot is unable to hit its equilibrium. However in the video above, the robot did reach an equilibrium state (moving straight) occasionally.

I will post the source codes in the future post after I have done investigation on how to make the robot move faster yet smoother.

If anyone has manage to complete the above task, please post in the comments how you manage to make the robot move fast yet smooth with 1 light sensor.

Line Follower - PID Method - Smooth



I hope most of you have read the Bit Logic line follower algorithm. Next I will explore the PID method, which I have been reading alot lately on the Internet. I reckon, for most high school students understanding just the "theory" of PID will be enough to put you through college :p

Please note that the line follower robot is only using 1 light sensor, the left one. The robot has been built with 2 sensors for future test algorithm.

Anyway, if you would like a very detailed theory, calculations and formula for the PID method, please follow this link.



If you have watched the video, you would realised that the robot tries to correct itself to stay in the middle, between the black and white areas, as shown in the image above. After a few oscillation, it would be moving along the grey area (between the white and black).


The graph above shows the Motor power output vs the readings from the Light sensor. As you can see, the robot will always try to keep within the Grey area (dotted line B), which is the equilibrium. When the Left motor and Right motor, is travelling at the same speed, the robot is actually move straight.

When the Light sensor is above the White area (dotted line A), you'll notice that the Right motor will stop, while the Left motor is moving at full power, causing the robot to turn right, thus heading towards the Black line.

When the Light sensor is above the Black area (dotted line C), the Left motor will stop, while the Right motor is moving at full power, causing the robot to turn left, thus heading towards the White area.

As you can see, since the graph is linear, the robot should automatically correct itself till it is moving along on its equilibrium (dotted line B), as you can see in the video attached above.

Saturday, 9 April 2011

Line Follower - Bit Logic Method



I have been tasked to teach one of the most fundamental programming ideas, Line Follower.

Before we begin, we should understand what Line Follower algorithm there is, and what is the best and quickest method. So today we will explore the easiest one of them all, the 2 bit line follower algorithm.



View the image above, the Black Box represents an enlarged Black line, while the tiny Red line represents where the light sensor is on and what it will see. You will notice from the video above, you will notice that the NXT Mindstorms actually makes very tiny zig-zag along the black line. If you look closely, it is actually like the red line above.

The idea is simple, if the sensor is over White (Point 1), you turn right towards the Black area. When you are over the Black (Point 2), you turn left towards the White area. Effectively you are hugging the left edge of the Black line.


Using just the a simple Switch Block, and 2 Move Blocks, we are able to program the bit logic line follower, as explained in the previous paragraph.

Being the easiest line follower algorithm to understand and teach doesn't make it the fastest. It only manage to complete the track in about 2 minutes, which is extremely slow!