line follower robot

12
LINE FOLLOWING ROBOT USING PID CONTROL Regd NO: 2011-EE-196 2011-EE-202 2011-EE-203 2011-EE-205 2011-EE-211 2011-EE-219 Project: Control Systems LAB 1

Upload: aqibriaz

Post on 07-Feb-2016

52 views

Category:

Documents


0 download

DESCRIPTION

DETAILS OF LINE FOLLOWING ROBOT

TRANSCRIPT

Page 1: Line Follower Robot

LINE FOLLOWING ROBOT USING PID CONTROL

Regd NO:

2011-EE-196

2011-EE-202

2011-EE-203

2011-EE-205

2011-EE-211

2011-EE-219

Project:

Control Systems LAB

1

Page 2: Line Follower Robot

(A).INTRODUCTION TO PROJECT

DEFINITION OF A ROBOT:

• A Robot has been defined by the Robot Institute of America as:A robot is a reprogrammable, multifunction, manipulator designed for moving materials, tools, parts etc. throughvarious programmed motions to perform a variety of tasks.• A Robot has been defined by Webster dictionary as:A robot is an automatic device that performs functions normally ascribed to humans or a machine in the form ofa human.

APPLICATIONS OF ROBOT:

• Robot can replace humans job because robots can perform faster than humans. Robots need not to drink, to bepaid or rest as compared to humans.• Robot can be applied in military to reducing the number of casualties which occur during military actions hasbeen already been prioritized.• Robotic site of security sentries are able to work for long hours at consistency high level of vigilance and precision.

LINE FOLLOWING ROBOT:

A line follower robot is a robot that is capable of navigating while following a line on some terrain with the useof sensors that tell the robot where it is. Just as we manipulate and interact with objects through gestures, theserobots have to be taught some way to manipulate and understand its surroundings to be able understand andcomprehensively take decisions. The decision variables are provided by these sensors also referred to as the linesensors and the acquired decision variables are passed through a decision device (in our case the controller) Themicro-controller in turn commands the actuators to move the robot in the desired direction, giving the effect offollowing the line.

APPLICATIONS OF LINE FOLLOWERS:

• One most important application of line follower is in warehouses where the robots follow track to and from theshelves they stock and retrieve from.• Automated driverless cars running on roads with embedded magnets.• Tour guides in museum.• Industrial equipment carriers.

OBJECTIVES OF PROJECT:

The main objective of this project is to design a line follower robot with PID controller having a differential drivesteering mechanism.• To design and develop an autonomous robot that follows a black line drawn on the floor while smoothing thetracking motion by using PID control.• To study the concept of infrared sensors, DC geared motors interfacing and PID controller tuning using STM -micro-controller

BASIC OPERATIONS INVOLVED:

The basic operations of line follower are as follows:• Capture line position with optical sensors mounted at front end of the robot. For this a combination of IR

2

Page 3: Line Follower Robot

transmitter and receiver package has been used. Requirement for line sensing process are high resolution and highrobustness.• Steer robot requires steering mechanism for tracking. Two motors governing wheel motion based on differentialdrive scheme are used for achieving this task.• Application of PID algorithm to smooth the tracking motion. PID control is a closed loop system, which willprovide feedback and correct the error that occurs with fast response.

LINE FOLLOWING WITHOUT PID:

If the line followers are to be implemented without PID algorithm they will follow the black line but with a smalldeviations even on a straight line. Once there is any curve in their path all the sensors would be off the line, thiswill confuse the robots and they will not respond to any condition furthermore and they will continue moving intheir previous state. To avoid this problem, we have to sense the direction in which robot was moving when thesensors were off the line. This will help us pull back the robot on the track. This phenomenon is also illustrated infig. below.

COMPARISON OF LINE FOLLOWER WITH AND WITHOUT PID

(B).BLOCK DIAGRAM OF THE PROJECT:

Simple schematic of this project consists of three different stages as follows.• Sensor array for line detection.• Decision making circuit/controller to control direction of motion.• Motor driver circuit to steer the robot.

3

Page 4: Line Follower Robot

(C).HARDWARE COMPONENTS DESCRIPTION:

As stated above the description of the objectives of this project following components were employed in hardwareassembly of this robot.

•Line Sensors.•Comparators.•Decision Device.•Power source.•Motor Drivers.•Opto-Couplers.

(1).LINE SENSORS:

The line sensors consist of an IR transmitter receiver pair for differentiating between the line and the background.The transmitter sends out IR rays and the receiver notes the amount, or in other words the intensity, of IR raysreceived and based on this it calculates if it is over the line or the surrounding. If the line is of white in color thenit will reflect more light as compared to any other color. This difference in reflected light helps us determine if thesensor is on the line or on the surroundings.

The IR sensor pair used in this project is RPR-359F which is selected for the following two reasons.

•To reduce the effect of ambient light on photo Detector.•To obtain High Accuracy

The sensors looks as:

4

Page 5: Line Follower Robot

ARRANGEMENT OF SENSORS ON ROBOT:

An array of 8 sensors arranged in a straight row pattern is bolted under the front of the robot. It locates the po-sition of line below the robot. We can use any number of sensors. If we have low number then our robot movementis not smooth and it may face problems during sharp turns. If higher number of sensors were, used robot movementwill become smooth and reliable for sharp turns rather it requires complex programming for micro-controller andrequires more hardware, which is its disadvantage. The output of the sensors is an analog signal which depends onthe amount of light reflected back, this analog signal is given to the comparator to produce digital signals (0s and1s) which are then fed to the micro controller.

Arrangement of sensor array is shown in figure below.

WORKING OF SENSORS:

The resistance of the sensor decreases when IR light falls on it. A good sensor will have nearly zero resistance inpresence of light and a very large resistance in absence of light. We have used this property of the sensor to forma potential divider.

From the above circuit diagram potential at point 2 is Rsensor / (Rsensor + R1). Again, a good sensor circuit

5

Page 6: Line Follower Robot

should give maximum change in potential at point 2 for no light and bright light conditions.

ALGORITHM OF LINE DETECTION:

Let us assume that when a sensor is on the line it reads 0 and when it is off the line it reads 1.

1. Referring to the figure of sensor array shown above:

L= leftmost sensor which reads 0.R= rightmost sensor which reads 0.If no sensor on Left (or Right) is 0 then L (or R) equals 0.For exampleIf sensors values are such that

Then in this case L=3; R=0.2. If all sensors read 1 go to step 3,Else;If L>R Move LeftIf L<R Move RightIf L=R Move ForwardGo to step 4

3. Move Clock-wise if line was last seen onMove Counter Clock-wise if line was last seen on LeftRepeat step 3 till line is found.

4. Go to step 1.

(2).COMPARATORS:

Comparator is a device, which compares two input voltages and gives output high or low. In circuit diagram belowit can be seen that it has two inputs Inverting (negative) and Non-Inverting (positive) Input (+), VCC, Ground,Output. From the name it is very clear that the operation of this circuit is to compare the two values at its inputterminals.

If V+ > V- then Output = VCC (Digital High Output is 1).If V+ < V- then Output = 0 (Digital Low Output is 0).

One input is from receiver, other is generated by potentiometer. The second voltage is reference voltage forthat sensor. We will fix the reference voltage at the non-inverting terminal of the comparator and compare thevalue whatever sensor receiver is generating as per position of robot on the line. The output thus produced will beused for PID control of robot.

DECISION DEVICE:

Decision device is a unit where the decision variables passed by the line sensors are analyzed, processed and thenthe appropriate actions/response are initiated. For our robot we have used the STM32L100RC microcontroller

6

Page 7: Line Follower Robot

board and C Programming Language for coding it.It is the brain of the robot and thus it can be said that therobot, to a certain degree, has artificial intelligence. Since the steering mechanism of the robot is a differentialdrive scheme which means we have to vary the speed of one motor relative to other to produce turning. This speedcontrol is being done using Pulse Width.Modulation (PWM) technique. A PWM is a basically a square wave of two state levels i.e., 1 and 0. We can setthe intervals of high and low level for PWM by changing the values in auto reload register, counter register andpre scalar register of this controller.

SPEED CONTROL USING PWM:

The logic high and logic low intervals correspond to duty cycle of PWM. For instance, if for a 16-Bit counter, wehave 70 percent duty cycle wave, then this means that from the interval of 65536 sec, 65536 * 0.7 sec will establisha high logic level, while the remaining interval will retain the logic low state. Logic high level corresponds to +5Vand low to 0V means Ground level. This means that if we have to decrease the speed of one motor relative to theother we will decrease the value of duty cycle of PWM signal applied to that motor which will be low for largertime than high state and motor will be off for more time as compared to on thereby decreasing its over all speed.

ADVANTAGES OF PWM INCLUDE:

• Motor consumes less power.• Increases efficiency, reliability and finer motor control.• Selectivity of various speeds by mere duty cycle adjustment.

Below are shown some figures of the varying duty cycle PWM wave forms.

ACTUATORS:

The actuators in this robot are geared DC motors with that have sufficient torque to carry the robot .They aredirectly connected to the wheels of the robot and cause the robot to move in the desired direction. We have twomotors controlling the two wheels. Motion is achieved using the concept of differential drive. Thus we can achievemotions of moving front, back and turning left and right. The two motors are used to drive the robot using theconcept of differential drive. In this the speed and direction of rotation of the individual wheels are used to both

7

Page 8: Line Follower Robot

move and turn the robot.

WHY DC MOTORS:

DC motors are most easy for controlling. One DC motor has two signals for its operation. Reversing the polarityof the power supply across it can change the direction required. Speed can be varied by varying the voltage acrossmotor.

• The DC motors dont have enough torque to drive a robot directly by connecting wheels in it. Gears aregenerally used to increase the torque of dc motor on the expense of its speed because torque of the motor is relatedinversely to its speed.

DIFFERENTIAL DRIVE SCHEME:

The first and the top most requirement of this project was to implement motion of this autonomous vehicle usingdifferential drive arrangement. As described in above sections that in this scheme the turning of the robot aboutthe turns of arena is controlled by the relative speeds of the two motors connected directly to wheels.

Few possible scenarios of the motion of vehicle are explained below.

FORWARD MOTION:

For forward rotation the motors must be rotated in same direction. For example if one motor is rotating in anti-clockwise manner other will also have to rotate in anti-clockwise direction too.

RIGHT TURN:

In order to turn it in right direction, the motor on left side must have to move in the forward direction while theright one has to be slowed down. It should be noted that for sharp right turn (90 degrees bend) right motor shouldrotate in direction opposite to the left one and vice versa.

LEFT TURN:

In order to turn it in left direction, the motor on right side must have to move in the forward direction while theleft one has to be slowed down.

MOVEMENT OF ROBOT WITH VARIATION IN MOTOR DIRECTION.

8

Page 9: Line Follower Robot

(5).POWER SOURCE:

The power source provides electrical power to the robot and all its components. Since the mandatory requirementof the project was that robot should be battery powered so we have used 4 dry cells as a battery source. Thespecifications of our power supply are as follows.

• Classification: Re-chargeable• Chemical Sys.: Nickel-Metal Hydride(Ni-Mh)• Nominal voltage 1.2V• Capacity 1300mAh• Weight 28 g• Jacket Plastic label

(6).MOTOR DRIVERS:

The motor driver is a small circuitry that controls the power supplied to the motor based on the input from amicrocontroller. Motor driver is a current enhancing device; it can also be act as Switching Device. Many ICsare available for driving the motors like L293d, l298, etc. These ICs are implemented by half and full H-bridgecircuits. Full H bridge ICs can make the motor rotate in forward as well as reverse direction. But we have usedNPN epitaxial Darlington pair IC TIP122 as a motor driver. These power BJTs have capability of deliver-ing a high current up to 5A to the motor. Circuit diagram of power BJTs driving the motor is shown in figure below.

RATINGS OF TIP-122:

• Collector current: 5A.• Base current: 120mA.• Vce(rated): 100V.• Vcb (rated): 100V.

(7).OPTO ISOLATORS:

Often when trying to drive a DC motor with a controller using transistors or H-Bridges, you will notice that thecontroller is doing strange and unpredictable things. When this happens, the culprit is likely to be electrical noisebeing injected into your circuit by the brushes and spinning magnets in the motor. Unfortunately, this noise is

9

Page 10: Line Follower Robot

very difficult to remove. One way of dealing with it is to try to filter out the noise by decoupling your motor drivercircuit and logic circuit with ferrite beads, inductors, capacitors, and resistors. A better method to isolate circuitsis to use opto-isolators. This allows you to completely separate your circuits, including the grounds. While thisscheme may add come complexity to your circuit, it is extremely effective.

An opto coupler or opto isolator is a cool little device that allows you to completely separate sections of anelectrical circuit. It transfers electrical signals between two isolated circuits by using light. Opto-isolators preventhigh voltages from affecting the system receiving the signal.

A common type of opto-isolator consists of an LED and a phototransistor in the same opaque package. Othertypes of source-sensor combinations include LED-photodiode, LED-LASCR, and lamp-photo resistor pairs. Usu-ally opto-isolators transfer digital (on-off) signals, but some techniques allow them to be used with analog signals.

• We have used K817P IC as an opto-coupler. In the K817P part, each channel consists of a phototran-sistor optically coupled to a gallium arsenide infrared-emitting diode in a 4 pin (single) plastic dual inline package.The functional diagram of opto-coupler is shown below.

• The signal coming from the uC is connected to (pin 1) anode of IC while cathode is grounded and the signalfrom (pin 5) collector of photo transistor is then proceeded to the next section of the circuit which in our case ispower BJT. In this way, complete isolation is achieved between the controller and driver circuit.

(D).PID CONTROL, ALGORITHM AND TUNING

In the objectives of this project, we mentioned that the following of the line is smooth and much accurate if wehave a PID control. Before going into the algorithm for PID designing let us go through brief introduction of PIDcontrollers.

PID CONTROLLER:

Proportional-Integral-Derivative (PID) control is the most common control algorithm used in industry and hasbeen universally accepted. As the name suggests, a PID algorithm consists of three basic coefficients: proportional

10

Page 11: Line Follower Robot

(Kp), integral (Ki) and derivative (Kd). These gains are varied to achieve an optimal system response. The generalstructure of a PID controller is shown below.

From the above fig. the mathematical equation for PID controller is:

PID ALGORITHM:

Before I tell you how to implement a PID algorithm for a line following robot, let me tell you the terms associatedwith it.

Set Point:It is the position you want the line follower to always be (or try to be) that is, the center of therobot. It is set to zero.

Measured Value: It is the current position of the robot with respect to the line. It can either be positiveor negative depending whether it is on left or right of set point. It involves calculating the distance between thecurrent position of the robot and the target position

Error: It is the difference between the current position and the target. It can be negative, positive or zero.

Proportional: It tells us how far the robot is from the line like to the right, to the extreme right, to theleft or a little to the left. Proportional is the fundamental term used to calculate the other two.

Integral: It gives the accumulated error over time. It tells us if the robot has been on the line in the lastfew moments or not.

Derivative: It is the rate at which the robot oscillates to the left and right about the line. This componentprevents the overshooting of the robot from the line when correcting the error.

PID constant: There are 3 constants used in this algorithm. These are the Proportional Constant (Kp), In-tegral Constant (Ki) and the Derivative Constant (Kd). The values of these constants are set beforehand by theprogramme.

11

Page 12: Line Follower Robot

PID IMPLEMENTATION:

We initialized the various constants such as Kp, Ki and Kd. Also we have initialized last error, which is the previ-ous error value & other variables such as integral, derivative and proportional. We set the value of the MeasuredPosition Variable for each sensor condition. Then we calculated the error value as

Error = Measured Value - Target Position

A higher error value tells us that the robot is farther away from the line, than a lower error value. We thenset the integral value as sum of current integral value & the error. The derivative value was updated to the sum ofcurrent derivative value & the last error.

We then calculated TURN Value as the sum of the product of error value & the Kp constant, product of Kiconstant and integral and the product of Kd constant & the derivative. We then give the output to the left wheeland the right wheel as a PWM (Pulse Width Modulation) output, which directly controls the speed of the motor.

Left PWM = BASE SPEED + TURNRight PWM = BASE SPEED - TURN

This results in both the wheels moving at different speed, which depends on the sensor input and is computedabove. At the end of the program we set the last error value as current error value.This algorithm keeps repeating in a loop to give an effective PID algorithm. The above explained computationhappens many times in a second to give an efficient line following robot. PID can be further improved by increasingthe number of sensors, which would cause the robot to go faster at curves and follow it more efficiently.

A brief pseudo code of all the above defined steps is shown below.

• Initialize the set point (S.P.).• Read sensors data (M.P.).• Calculate error.• Calculate output of PID controller.• Apply controller output to motors.• Go back to step 2.

PID TUNING:

Selecting the values of controlling parameters Kp, Ki and Kd is known as PID tuning. There are various mathe-matical techniques of PID tuning but we have applied trial and error approach for this task.

1.First of all, we set the values of Ki and Kd zero and just vary kp so that robot somehow follows a line.

2.Once robot started following a line we increased the value of Kd until there was no wobbling and robot was stable.

3.Finally we set the value of Ki so there will be no jerky movements towards left and right.

CONCLUSION

12