Three Sensor

In this scenario the robot is able to not only follow the line but detect other objects wether on or intersecting with the black line.  The placement of the third sensor determines how to Robot can take advantage of this.

For example of the third sensor is placed right between the Left and Right sensor, and does in effect is positioned over the black line, the robot can be made even more accuratel follow the line, and at higher speed.

If the light sensor is for example placed between the Left and Right sensor yet further back, it can be used to react to items on the black line, increase decision as to what to do when an intersecting black line is detected.

You could also use the third sensor to drive first to a black line, when detced by the third sensor, turn on the Left and Right sensor and then follow the detected line.  In essence this allows for a robot which looks for a black line, detects it and then starts following it.

Code Example

In this example the third sensor is used to initially detect the black line it needs to follow, and then uses the two-sensor model to follow the line, yet again with a break out option when it reaches an intersection.

Advanced three Sensor model — PID control model

Want to make your robot follow a line? At slower speeds, the process is pretty simple – if the sensors say it is going left, steer right and if going right, steer left. This process has its limitations though, mainly when the speed is increased .  This is when a PID controller starts to shine.

PID stands for Proportional, Integral, Derivative.  A PID controller is a mathematically-based routine that processes sensor data and uses it to control the direction (and/ or speed) of a robot to keep it on course. Why does PID work better than our simple model described above? Let’s talk about how robot acts (or behaves) as it follows a line to see why.

Robot Behavior when following a line

Let’s say our robot has 3 sensors, Left, Center and Right. When the Center sensor sees the line, the robot is programmed to go straight. When the Left sensor sees the line, the robot is programmed to turn right. When the Right sensor sees the line, the robot is programmed to turn left.  This will typically cause the robot the wobble back and forth over the line and if going too fast, it may lose control and stop following the line.

This method only takes one behavior into consideration – is the robot centered over the line.  To improve performance, we should also take into consideration 2 more behaviors – how rapidly is the robot moving from side to side and how long is it not centered over the line.  These 3 behaviors are called Proportional, Integral and Derivative in terms of a PID controller.

Implementing a PID based method in NXT-G all though possible, is stretching it a bit.  Better tools for this are LabView or RobotC or other more advance robot programming languages available for the NXT.