Page 1 of 1

PID line follow with three sensors in NXC

Posted: 04 Oct 2012, 11:45
by bungeshea
Hello,

I'm currently working on a line-following robot which uses three sensors to follow a black line. The sensors are pretty much in line and right next to each other.

Right now, I'm doing a simple line follow: if on the line go forward, otherwise turn left or right to regain the line. This means that the robot is wiggling along the line most of the time.

I'm looking for a better way for this robot to follow the line using three sensors. The program I'm writing is in Not eXactly C code. I'm trying to get the robot to utilize the power of PID control, but I'm not sure how one would go about writing a three-sensor PID line-follower program in NXC. Any help would be greatly appreciated.

Re: PID line follow with three sensors in NXC

Posted: 04 Oct 2012, 13:22
by hassenplug
Using three light sensors, and simple boolean values (either it's on the line, or off the line) there are eight possible states.

For most of them, you should know what to do, simply by looking at the sensors.

However, without getting too fancy, you can greatly improve things by knowing the previous state the sensors were in.

For example, if the sensor on the left sees the line, you know you need to turn left.

If NO sensor see the line, but the sensor on the left just saw the line (previous state) you know you need to turn sharper left.

But... if the sensor on the left see the line, and the previous state was no sensor on the line, you know the robot is currently turning onto the line. In this case, you can stop turning, go straight and let momentum continue to turn the robot.

Using this type of logic will be a huge gain over basic line following techniques.

Steve