Ads 468x60px

Subscribe:

Labels

Thursday 2 February 2012

[TUTORIAL] Simple Implementation of PID

A PID controller based behaviour of line follower. [source]
Many industrial have to make sure that their robots or other mechanism devices is work properly. Usually to manage their devices, they have to make system control. There is many system control design out there,  this time i'll explained briefly and give simple implementation of PID control.

Proportional-integral-derivative control or shortened PID is a generic control loop feedback mechanism controller. It calculates an error values as the difference between a measured process variable and a desired set point. To minimize the error, controller adjusting the process control inputs.

The algorithm is involves three parameters; the proportional, the integral, the derivative values. Proportional is depends on present error. Integral is accumulation of error. Derivative is a prediction of future error. But, in some circumtances may require only one or two: just using P, PI, PD. We can't use only I or D, at least there is P in calculations.


Process diagram

First thing to tuning PID controller, we have to set the "zero point". This is important, because we want set range of error. The error can get  from "zero point" or called SP (Set Point) minus value that always change called PV (Process Value).

After get the error, calculate the proportional (P) gain from multiplying error and constant P(Kp). Tuning the proportional gain give you output that change the error. Bigger value of Kcan make large change in the output for given change to error. If the output of proportional gain is too high, the system can be unstable. In contrast if the output of proportional gain is too low, the system is not responsive or less sensitive.


Third step is determine whether use Integral term or Derivative term or using both of them. Integral term is the sum of instantaneous error over time and gives accumulated offset that should have been corrected previously. Then accumulated error is multiplied by constant I (Ki) and added to the controller output. Tuning the Integral gain is recommended Ki value is under 1 but not 0. The integral term is accelerate the movement of process towards the set point. However, since integral term responds to accumulated errors from the past, it can cause the present value to overshoot the setpoint value.


Derivative term is the derivative of the process error  is calculated by determining the slope of the error over time and multiplying this rate of change by the derivative constant KdThe derivative term slows the rate of change of the controller output. Derivative control is used to reduce the magnitude of the overshoot produced by the integral component and improve the combined controller-process stability. However, the derivative term slows the transient response of the controller. Also, differentiation of a signal amplifies noise and thus this term in the controller is highly sensitive to noise in the error term, and can cause a process to become unstable if the noise and the derivative gain are sufficiently large.




Line following robot is simplest yet fun to implement PID controller. To implement it to line following robot, first we have to make a set point, let's say the line following robot use 4 light dependecy sensors. So the set point is center of the robot, it means the set point is two sensors at center (two sensors more accurate than one). 
Illustration : sensor is red and line is black.
The sensor is 2cm apart each sensor and width of line is 3cm. Then, give value to each possible position of sensors. Full range of position can be like this (1 is represent to sensor is detect a line and 0 is represent to sensor is not detect a line) :


0001 : 3
0011 : 2
0010 : 1
0110 : 0 
0100 : -1
1100 : -2
1000 : -3


Give a "flag" value to right and left sensor for possiblity any sensor not detecting a line. Then give a position value to each flag, like this (flag 1 is for left sensor and flag 0 is for right sensor) :


0000 : 
flag 1 ----> 4
flag 0 ----> -4




After value of position is given, then we use that for PID formula.
First, we use Proportional term in PID formula. Error is value of position that given at each sensor. Then multiply it with constant P(Kp) - give any number for it, it will be adjust for better run of line follower. After that, make a logic statement for the run of robot. Speed of robot is set and it will be reduced by PID output value, this is how robot is navigate through the line. Adjust the Kp until the robot is follow the line correctly. After the run of robot is follow the line correctly, use I or D to stabilize the robot, but usually for more visible  result use D first. Formula of D is current error (present position value) minus previous error and multiply it with Kd. After that, sum the P and D for PID output value. Adjust Kuntil the robot is more be in center the line. After get more stabilize run of the robot from P and D formula, use I for more stabilize run of the robot and more be in center the line. Formula of I is current error plus previous Integral value, after that sum it with P and D. Adjust Kd until run of the robot is stable and follow the line with variation of shape. Try and try run of the robot until its best performance. 


You can download my code made by CodevisionAVR C Compiler here
I will upload video of my robot soon!






Source :
Definition of PID controller in wikipedia


No comments:

Post a Comment