Friday, August 7, 2009

A Self Tuning PID Algorithm

Introduction
The PID (Proportional Integral Derivative) controller is a popular feedback controller used in industry. One known drawback of the controller is that the constants () of the control loop are representative of the process at the time of tuning. Later, when the processes and its parameters related to the control loop may be change. But these changes needn’t be incorporated by the constants, which may lead to instability. So, often a re-tuning of the control loop is required to make the system stable.
Proposal
This paper proposes to provide a solution to this problem by modifying the PID controller algorithm based on the assumption that the change in the controller constants varies linearly with the magnitude of the error.
The form of the PID controller is considered is:

The modified tuning constants as per the assumption are:

Where is the average of the absolute errors over a period of time. This modification in constants will be iterative, initiated after a set of data is obtained.
Algorithm (in C)
Following is a sample code (C program) is for a standard PID controller
float sp, pv, mv, intg = 0, der, err, prev_err = 0;float kp, ki, kd; /* controller constants */int t1 = 1000; /* in microseconds */
pid(sp, pv){
err = sp - pv; /*sp – setpoint, pv – process value */intg = intg + err*t1;der = (err - prev_err) / t1;mv = kp*err + ki*intg + kd*der;pre_err = err;delay(t1);
return mv; /*mv – measure value */
}

The modified algorithm changes the controller constants is as follows:
float sp, pv, mv, intg = 0, der, err, prev_err = 0, avg_err = 0;float kp, ki, kd, cum_err=0;int t1 = 1000, i=0;
pid(sp, pv){
err = sp - pv;intg = intg + err*t1;der = (err - prev_err) / t1;mv = kp*err + ki*intg + kd*der;pre_err = err;delay(t1);
i++;
cum_err = cum_err + abs(err); /*abs is absolute value*/
if(i = 500){ /* initiates after 500 iterations */
kp = kp – cum_err/(i*sp);ki = ki – cum_err/(i*sp);kd = kd – cum_err/(i*sp);
i = 0; cum_err = 0;
}
return mv;
}

Conclusions
This modification in the PID algorithm can make it a self-tuning control loop which will incorporate the process changes by modifying the constants. (It is yet to be simulated or tested in a real-time environment.)
References
PID Controller – Wikipedia, the free Encyclopedia (http://en.wikipedia.org/wiki/PID_controller)

3 comments:

Justin said...

cool story bro

can you post some plots

Unknown said...

why should it follow the error? it is based on the offset I believe

abramjaely said...

Pragmatic Play launches new casino for US players - JT Hub
Pragmatic Play's new gaming studio, which is set to 진주 출장샵 open in 시흥 출장샵 the US in late 2021, 안동 출장샵 is available 양주 출장샵 to Indian players in 대전광역 출장마사지 its US