PID ALGORITHM

PID Algorithm 

What is PID? Old day technology use On Off switching to control the system. The on-off controller is the easiest possible way of control. Many technical systems use it, not limited to controlling a motor.  Refrigerator, heater, water pump usually use this system. But more complicated system its not going to work as we aspect by using this technique. The idea behind feedback control is very simple. We have a target speed, specified by the user or the computer program, and we have the current actual speed, measured by the sensor (hall, encoder, pot, etc). Measurements and actions according to the measurements can be taken very frequently(t).

The easiest way of control is not always the end of the story. A more sophisticated of controller and industry standard is the PID controller. It base on proportional, an integral, and a derivative control part. The controller parts are introduced in the following sections individually and in combined operation.


Proportional is the simplest term. The error is multiplied by the proportional gain,The amount of correction applied to the system is directly proportional
to the error.
'kP term....
              P1 = Kp * DIFF

P math in C code (embedded)

1    e_fungsi = v_target - v_drive; // error function //
2    z_motor = Kp*e_fungsi ; //motor output 



Integral term is calculate the "historic" error in the system in fixed period of time. How long the motor need to move from point A to B? How to set the timer overflow in microcontroller is not as easy as in P and D term. If we set the timer overflow too fast from what they need to compensate the error and the system will not going to stable. The integral gain must be thoroughly tested before implementation to any PID systems. Its not as simple as I term =  gain * sum.
output = (kp * error_value) + (ki * integral) + (kd * derivative); 

The idea for the I controller is to reduce the steady-state error of the P controller. With an additional
integral term, this steady-state error can be reduced to zero.

I math in C code (embedded)

3 e_fungsi = v_target - v_drive;
4 z_motor = r_old + Kp*(e_fungsi - e_old) + Ki*(e_func+e_old)/2;



Derivative term is based on the rate at which the system is changing. Sometime it can be extremely aggressive when it is acting on the error of the system. In my case I make it adjustable to reduce the aggressiveness of this term. Similar to the I controller, the D controller (derivative controller) is rarely used by itself, but mostly in combination with the P or PI controller. The idea for adding a derivative term is to speed up the P controller’s response to a change
of input
'kD term......             

errdelta = DIFF - errprev
d1 = kd * errdelta
drive = d1 + p1

No comments:

Post a Comment