Upcoming SlideShare
×

# Pid control for line follwoers

2,467 views

Published on

A tutorial to implement common PID control system on an Autonomous Linefollowing robot.

1 Comment
7 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No

Are you sure you want to  Yes  No
Views
Total views
2,467
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
0
1
Likes
7
Embeds 0
No embeds

No notes for slide

### Pid control for line follwoers

2. 2. Intro.. Line followers are autonomous robots thatfollow a line. They might follow a visualline painted or embedded in the floor orceiling or an electrical wire in the floor.Most of these robots operates on somespecific algorithms. This tutorial guides you through a commoncontrol system algorithm used in theindustry, PID control and how it can be
3. 3. So lets start !!
4. 4. The Basics.. All basic control systems rely onfeedback.. feedback of the systemoutput, to know what state the system is inat that instant and adapt the system bychanging its parameters so that the systemreaches the desired output.. We call that aSETPOINT.. (S.P) To attain the S.P we change certainelements in the system, these elements
5. 5.  So on coming to line followers our goal is tokeep the bot on the track at alltimes, ideally the centre of the bot on thecentre of the line at all times.. For the timebeing let this be our S.P... To achieve that weneed to change the way out bot moves, i.e wecontrol the motors.. our M.V..
6. 6. What is PID control then... The PID control scheme is named after itsthree correcting terms, whose sumconstitutes the manipulated variable (MV).The proportional, integral, and derivativeterms are summed to calculate the outputof the PID controller.
7. 7. Kp: Proportional gainKi: Integral gainKd: Derivative gaine(t)=SP-PV : Errort : Time or instantaneoustime (the present)Now this dosent make much sence does it !! 
8. 8. So what are these Kp,Ki n Kd.. In simple terms, the proportional term changesthe system proportional to the error, more theerror more the controller output.Eg: if the bot is at the right extreme sensor* onthe line(has to take a right turn), the leftmotor is given more power to get back into thecentre of the line. The integral term is the summation of previouserrors, so it looks into the past of the system*Assuming the bot has a odd sensor array.. 5 or 7 sensors or more..
9. 9. The Algorithm..1. Initialize the set point S.P2. Read sensor data P.V3. Calculate the error e(t)=SP-PV4. Calculate the output of the PIDcontroller u(t).5. Apply controller output to theactuators(motors).6. Go back to step 2.
10. 10. So lets define our variables… Our aim is to keep the bot on the centre ofthe line, for feedback we have sensors*; i.e.we need to keep the centre sensor on thecentre of the line.. that’s ok, but how can we convert 5/7 or2n+1 sensor inputs ot a single variabler(t).. that’s where simple mathematics and
11. 11. The conversion.. Lets assume we have 5 sensors.. Im assigning weights to eachsensor like in the figure above Centre has 0 weight, left mosthas -2 etc.. So when we take the input r(t) itwill bek(t)=(-2)*r2+(-1)*r1+(0)*c+(1)*l1+(2)*l2 . Generalizing..-2 -1 0 +1 +2r2 r1 c l1 l2
12. 12. Lets make this unique.. i’m assuming that sensors onthe line return 0 and off theline return 1. Now that we have k(t), we willdivide this by the number ofsensors that return 1.. Here wehave 4 sensors that return 1.. So the sum is 4.
13. 13. Lets build on this a little more…. Now that we have a single variable for theinput, as a number we can calculate whatthe set point S.P will be. So we have So our S.P is zero.. That makes the rest ofthe math easy to understand.
14. 14. Consider the bot on a 90’ right turn So in this case we have Si as [11 0 0 0]. Calculate r(t) So its negative 3/2..1 1 0 0 0
15. 15. Consider the bot on a 90’ left turn This will be easy now.. Its positive.. So for all left turns we getpositive inputs, right turnswe get negative inputs and ifits on the centre our input iszero. that’s basically calssifyingmathematically all our0 0 0 1 1
16. 16. Building… Initialize SP,e_int,e_diff We read Sensors Si; Compute r(t) Error e(t)= SP- r(t) Find e_int,e_diff Find u(t) Update e_diff Read sensors againSP=0;e_int,e_diff=0;A:Si=read();r=compute();e=SP-r;e_int +=e;e_diff=e-e_prev;u=Kp*e+Ki*e_int+Kd*e_diffe_prev=e;Goto A:Read() is the read sensor function, returning 1 if sensor is not on theline and 0 otherwise.Compute() finds the value of r(t) using the formula.
17. 17. Also.. The weight initialization Wk can also beother sequences, like 0,1,2,3,4..Accordingly you have to modify theerror control statement.. the set point for 0,1,2,3,4 weight systemwill be 2.. Values less than 2 correspondto left turn and greater than 2correspond to right turn..
18. 18. Putting it all together Now that we have the controller outputu(t), we need to assign it to the actuators, orthe motors in our case.. Using PWM signals we can vary the speed of themotors. Your signals to the motors correspondto the output u(t), but we have two motors.. So we convert this signal u(t) to 4 signals.. right1 and right2 connected to +ve and –ve of theright motor. left1 and left2 connected to +ve and –ve of the
19. 19. How we do it…if (u < 0){left1 = 100% + u%;left2 = 0% – u%;right1 = 100%;right2 = 0%;}else{right1 = 100% -u%;right2 = u%;left1 = 100%;left2 = 0%;}• Following the same analogy,we have negative output forleft turn and positive error forright turn.• u will vary from +k to –k,where k is a constant that canbe calculated.• Where 100% is 100 percentoutput (5V), u% is the controlleroutput in percentage(its twicethat actually).. Ie if controlleroutput ranges from -3 to +3, u%
20. 20. How to select Kp,Ki and Kd Selection of these parameters is called tuning.There are various mathematical methods likeZ-N method and C-N method, but that requiresthe mathematical model of the plant. So wemove to a practical approach. First we set Kp= a constant and set Ki and Kd tozero, which is turning off differential andintegral actions. The bot will be oscillating(sweeping left andright on the line) along the line. Increase Ki till the oscillations subside and bottravels smoothly(small oscillations will bethere, one or two sweeps).
21. 21. Practical experiences on using this scheme.. Though PID control is a very efficient controlsystem logic, using a 5 sensor array providesvery small data for enough variations andhence you might find the logic inadequate forsharp acute turns. The system however becomes an excellentconstructor helping the user map all the 2^Nconditions for an N sensor robot usingequations rather than having to use Booleanalgebra to map all the conditions.