12/29/2015

Line Following Robot

Line following robots have been around for years, so many people have had chances to attack this sort of problem. Line following robots can be very basic or very sophisticated depending on the hardware used, efficiency wanted, and programming capabilities. In the history of line following robots the differential steering system is the most widely used way of keeping the robot on course. Infrared (IR) sensors are used more frequently in line following robots then any other sensor.

Hardware

The four main Hardware items needed to build and control a line following robot are Sensors, Micro-controllers, Drivers, and Motors.

Sensors

As mentioned before IR sensors are the most popular sensor used in the line following robot field. IR sensors have two IR LED, one is the Emitter and the other is the Receiver. An electrical property of these LED is that they produce a voltage difference across its leads when it is subjected to light. This voltage can barely be detected. An Op-Amp is normally used to increase this voltage to a reasonably detectable range. By amplifying the voltage, the changes in voltage will be easier to detect.

There are many other sensors that can be used to detect lines. Photo-cells and Photo-resistors are two other common sensors used.

The image below is a commercially available single line following IR sensor. It needs only 5 volts to run. The output signal ranges from 0V to 5V. This range is based off of it seeing white or black. This also means there is an Op-Amp already installed. The sensing distance is 0.04 in to 0.5 in. This short range is common for IR sensors.

 The image shown below is also a commercially available line following IR sensor. As you can see there are five IR sensors set up in an array. This board reads from all five sensors and outputs a 0-127 signal, 0 meaning all sensors are seeing white and 127 means all are seeing black. It has the same input voltage and range as the single line following IR sensor. An array of sensors is the most efficient way of sensing and staying on a line. PID Controller

Common Sensors

IR

IR— Infra-red sensors are normally used in range or proximity sensing. Time-of-Flight from the emitter to the receiver is used to calculate the distance to an object.

Sonar

Sonar sensors are used in the same manner as the IR sensors. The sonar sensor sends out a sound wave and measures the time it takes to return to the sensor. Sonar sensors are also used widely in range finding.

Laser

Lasers have the best range and percision of all the sensors used in robotics. They are very expensive and can be fairly large compared to IR and Sonar sensors. The same basic concept is used in laser sensors as IR and Sonar sensors.

Micro-Controller

The type of micro-controller used in your application may vary depending on what other objectives you may need to accomplish. The simplest micro-controller that will be needed to just follow a line will need to have an Analog to Digital (ATD) port (or something equivalent "Comparator") and a couple basic I/O pins. The ATD port is to read from the sensor and the two I/O pins are to control the drivers which in part control the motors. The more ATD ports on the micro-controller used will greatly improve the efficiency of the robot if coded properly.

Drivers

There are many types of drivers offered but all of them have the same concept. An H-Bridge configuration is the most common.
The diagram above shows how simple the concept of an H-Bridge really is. To rotate the motor in one direction the controller would need to close switches S1 and S4. To rotate in the opposite direction, the controller would need to close switches S3 and S2.

The driver shown below is a Texas Instruments(TI) L293 quadruple high-current half-H driver. The L293 is designed to provide bidirectional drive currents of up to 1 A at voltages from 4.5 V to 36 V. The L293 is designed to drive inductive loads such as relays, solenoids, dc and bipolar stepping motors, as well as other high-current/high-voltage loads in positive-supply applications.

Most IC drivers like the TI L293 have Enable pins, which will turn on that half of the IC or the IC in general. Pin 1 is the Enable pin for the first two half-H bridges. From the diagram Pin 9 turns on the other two half-H bridges. Pin 8 is the motor supply voltage input pin. This voltage is normally higher then the voltage used by other components on the robot. Pins 2 & 7 are the input pins to turn on or off the motors. Pins 3 & 6 are the outputs to the motor. Everything from here on is mirrored across the IC. This driver offers multiple configurations for motor set-ups. The figure below shows two different configurations. By connecting the two half-H bridges through a motor the controller can rotate the motor in both directions(right side). If Pin 2 is high and Pin 7 is low the motor will rotate in one direction and vise versa for the opposite direction. The drivers can also be configured to run one motor in only one direction using only one of the half-H bridges as seen on the left side of the figure below.

Motors

The motors and gearing used will be based off of the objective the robot is trying to complete.
A concern when choosing motors and gear reduction for a line following robot would be keeping the speed of the motors slow enough the robot is not over shooting the edge of the line. If the robot does over shoot the edge of the line the robot could become lost. Depending on programming the robot may never find the line or could find the line but will be going in the wrong direction and not know.

Programming

Zig-Zag Method

The Zig-Zag method is the simplest and easiest way of programming a line following robot. The concept is the robot moves across the line it is following until it meets an edge. Once it senses it has hit an edge it turns the current motor off and turns the opposite motor on. Once it senses the next edge it swaps the power to the first motor again. As you can see the robot Zig-Zags back and forth across the line.

One Sensor

The Zig-Zag method with one sensor is a very basic line following robot. Since there is only one sensor there will only be one reading. This reading will be either "I see Black" or "I see White". As mentioned before the Zig-Zag method crosses back and forth across the line being followed, this causes problems with wide lines. The robot will move across the line untill it senses the edge, by the time it gets to the edge it might not be facing the end point any more. Further thought into programming and powering both motors, one just more then the other will help with this problem.
 
Basic Zig-Zag Code

%Zig-Zag Code
%2/10/10
%PinA is connected to the enable Pin on the driver for the right side motor
%PinB is connected to the enable Pin on the driver for the left side motor
%ATD1 is the port connected to the IR sensor(reads 1 for Black and 0 for
% White)
%In this program the robot will be following a White line. If you are
%following a Black line the inputs for the IF loops will be swapped
%Start centered on the line
ATD1 = 0;
%
%Start off scanning for edge to the left
PinA = 1;
%Right_wheel means the right wheel is spinning,
Right_wheel = 1;
%
%The percentage of your PWM will be based off of the gearing of your motor
%and the width of the line. I am using a PWM% of 50% just to show the
%concept
%Continuous loop
while(1);
%
%Sensor reads Black(Not on the Line)
if (ATD1 == 1)
%Figures out which direction it is currently moving
if(Right_wheel == 1)
%Changing direction by changing which motor is running
Right_wheel = 0;
PinB = 1;
PinA = 0;
else
%Changing direction by changing which motor is running
Right_wheel = 1;
PinA = 1;
PinB = 0;
end
end
end

Two Sensors

The Zig-Zag method using two sensors becomes more efficient then using one sensor. There are two ways of setting the sensors on the robot. Depending on the width of the line and personal preference the robots sensors can be set up to straddle the line or can be set up to stay with-in the line's width. Both of these configurations makes the response of the robot faster at detecting the edge then the single sensor robot. The robot will Zig-Zag faster back and forth but will have a more true heading. Using two sensors makes the over shoot problem a little easier to handle. If over shoot happens it is possible one of the sensors is seeing the line and could straighten the robot out based off of the general Zig-Zag coding.

PID Control Method

Array of Sensors

In many applications an array of sensors is used. By using the array of sensors the robot can have a better understanding of where it is on the line and will be able to correct its trajectory a little more accurately. The figure below is a simple diagram of an array of sensors that could be used on a line following robot. It has four sensors on the right (R1-R4) and four on the left (L1-L4). As seen in the above explanations these can be 0's or 1's depending on the color of the line you are following.

The figure below shows what the controller would see if the robot was centered on the line. When your robot is seeing this you will want your robot to supply both motors with an equal amout of power.

The Diagram below shows the robot trailing slightly to the right of the line. In this case the controller will want to power the right wheel slightly more then the left wheel to correct the trajectory of the robot back to centered on the line. If you are using a PID type of controller the error signal would be proportional to the magnitude the robot was off of center. In this case the robot is not far from center so the error would small.

In the following figure you can see the robot is drifting further to the right. In this case the PID error signal would be greater then the above example. There for supplying a greater amount of power to the right wheel.

When using an array of sensors the most common controller used is a PID controller. Most configurations using arrays will wire the signals into one whole eight pin ATD PORT on a micro-controller. By using the whole port the controller can read an 8 bit number from the sensors. By calibrating the sensors centered on the line to be followed, the controller can take that reading as "I'm on course". The PID control in the programming will try to keep the robot at the "I'm on course" reading by smoothly and constantly adjusting the right and left wheel speed. To learn more about PID Controlling please see PID Controller

Bibliography

http://www.ikalogic.com/ir_prox_sensors.php [1]
http://www.trossenrobotics.com/p/single-line-following-sensor.aspx [2]
http://www.trossenrobotics.com/p/I2C-Line-Following-Sensor.aspx [3]
http://focus.ti.com/lit/ds/symlink/l293.pdf [4]
http://www.kronosrobotics.com/application.shtml [5]

1 comment:

Interfacing LCD With Arduino Microcontroller

In this tutorial we are going to  interface a  Liquid Crystal Display (LCD)  with Arduino Microcontroller .  Liquid Crystal Display are us...