Pid control for line follwoers

10,368 views

Published on

This is a tutorial on how to implement PID control system in an autonomous linefollower robot.
A robocet initative

Published in: Education, Business, Technology
1 Comment
21 Likes
Statistics
Notes
No Downloads
Views
Total views
10,368
On SlideShare
0
From Embeds
0
Number of Embeds
205
Actions
Shares
0
Downloads
0
Comments
1
Likes
21
Embeds 0
No embeds

No notes for slide

Pid control for line follwoers

  1. 1. By,Mahadev G+919496370662
  2. 2. Intro.. Line followers are autonomous robots that follow a line.They might follow a visual line painted or embedded inthe floor or ceiling or an electrical wire in the floor. Mostof these robots operates on some specific algorithms. This tutorial guides you through a common controlsystem algorithm used in the industry, PID control andhow it can be implemented in a line follower system.
  3. 3. So lets start !!
  4. 4. The Basics.. All basic control systems rely on feedback.. feedback ofthe system output, to know what state the system is in atthat instant and adapt the system by changing itsparameters so that the system reaches the desiredoutput.. We call that a SETPOINT.. (S.P) To attain the S.P we change certain elements in thesystem, these elements (variables) are calledManipulated Variables (M.V)
  5. 5.  So on coming to line followers our goal is to keep the boton the track at all times, ideally the centre of the bot onthe centre of the line at all times.. For the time being letthis be our S.P... To achieve that we need to change theway out bot moves, i.e we control the motors.. our M.V.. Fore more on Closed loop control basics visit [ http://hsconntrol.blogspot.in/2011/03/control-loop-basics.html ]
  6. 6. What is PID control then... The PID control scheme is named after its three correctingterms, whose sum constitutes the manipulated variable (MV).The proportional, integral, and derivative terms are summed tocalculate the output of the PID controller.
  7. 7. Kp: Proportional gainKi: Integral gainKd: Derivative gaine(t)=SP-PV : Errort : Time or instantaneous time(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 changes the systemproportional to the error, more the error more the controller output.Eg: if the bot is at the right extreme sensor* on the line(has to take aright turn), the left motor is given more power to get back into thecentre of the line. The integral term is the summation of previous errors, so it looks intothe past of the system and compensates accordingly.. The differential term does something like predicting what the futureerror will be, it is not an absolute measure of the future error though..*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 PID controller u(t).5. Apply controller output to the actuators(motors).6. Go back to step 2.
  10. 10. So lets define our variables… Our aim is to keep the bot on the centre of the line,for feedback we have sensors*; i.e. we need to keepthe centre sensor on the centre of the line.. That’s ok, but how can we convert 5/7 or 2n+1sensor inputs ot a single variable r(t).. That’s where simple mathematics and numbersystem comes into use..
  11. 11. The conversion.. Lets assume we have 5 sensors.. Im assigning weights to each sensorlike in the figure above Centre has 0 weight, left most has -2etc.. So when we take the input r(t) it will 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 the input, as anumber we can calculate what the set point S.P will be. So we have So our S.P is zero.. That makes the rest of the math easyto understand.
  14. 14. Consider the bot on a 90’ right turn So in this case we have Si as [1 1 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 get positiveinputs, right turns we get negative inputsand if its on the centre our input is zero. That’s basically calssifyingmathematically all our conditions.0 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 be other sequences,like 0,1,2,3,4.. Accordingly you have to modify the errorcontrol statement.. the set point for 0,1,2,3,4 weight system will be 2.. Valuesless than 2 correspond to left turn and greater than 2correspond to right turn..
  18. 18. Putting it all together Now that we have the controller output u(t), we need to assign it tothe actuators, or the motors in our case.. Using PWM signals we can vary the speed of the motors. Yoursignals to the motors correspond to the output u(t), but we have twomotors.. So we convert this signal u(t) to 4 signals.. right1 and right2 connected to +ve and –ve of the right motor. left1 and left2 connected to +ve and –ve of the left motor.
  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 havenegative output for left turn and positiveerror for right turn.• u will vary from +k to –k, where k is aconstant that can be calculated.• Where 100% is 100 percent output (5V),u% is the controller output in percentage(itstwice that actually).. Ie if controller outputranges from -3 to +3, u% is (u/3)*100..• Going through the math you find that if uis 100% negative, the bot will turn usingdifferential steering.
  20. 20. How to select Kp,Ki and Kd Selection of these parameters is called tuning. There are variousmathematical methods like Z-N method and C-N method, but thatrequires the mathematical model of the plant. So we move to a practicalapproach. First we set Kp= a constant and set Ki and Kd to zero, which isturning off differential and integral actions. The bot will be oscillating(sweeping left and right on the line) alongthe line. Increase Ki till the oscillations subside and bot travels smoothly(smalloscillations will be there, one or two sweeps). Put Kd as 10% of Ki or a very small value.
  21. 21. Practical experiences on using this scheme.. Though PID control is a very efficient control system logic, using a 5 sensorarray provides very small data for enough variations and hence you mightfind the logic inadequate for sharp acute turns. The system however becomes an excellent constructor helping the usermap all the 2^N conditions for an N sensor robot using equations rather thanhaving to use Boolean algebra to map all the conditions. Hence using this scheme means that there will not be any unmappedcondition so that your uC gets locked in a loop. Extremely effective and useful if using more number of sensors.

×