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)

Saturday, February 21, 2009

Nm3 Conversions

One of the frequent conversion problems encountered in our industry is to convert from or to Nm3. We all know that the volume of gases change according to pressure. So, the conventional unit of m3/hr cannot be used to measure volumetric gas flow rates. Nm3 simply provides a standard of gas flow measurement. Nm3 is the equivalent flow at a standard temperature and pressure.
Temperature standard can be either at 0 °C, 15 °C or 25 °C. Pressure standard is mostly taken at 1 atm.
Suppose, to convert 1 Ton of Nitrogen into Nm3, we can safely use the ideal gas law for all practical estimates:

The volume, V is the volume in Nm3 as it is the volume under defined conditions of 1 atm and 0 °C.

Again, to convert 1 litre of Liquid Nitrogen into Nm3, we can use the same method:

Friday, February 20, 2009

Time taken to drain a cylindrical tank

Probelm: Consider a cylindrical tank with a cross-sectional area of ‘A’, liquid filled to a height ‘h’. It has a drain line of cross-sectional are ‘a’. The tank is being drained under gravity, how much time will it take to drain the tank (ignoring effects due to friction and viscosity)?


Solution: The key to solve the problem is to equate the drain flow rate to the level drop in the tank. But the trick is that the drain flow rate depends on the level.
Drain flow rate = cross-sectional area x velocity
=

Velocity is obtained by equating potential energy to kinetic energy as it is freely falling under gravity,


Rate of volume drop in the tank = cross-sectional area x rate of infinitesimal level drop in the tank

=
Equating both, we have

Solving which, we get:

which is the time taken to drain the tank completely.