I have a PID controller algorithm from one of my textbooks, I could send it to you with lots of comments.
If it's not too much typing for you, it would be worth taking a look at.
Ok! Here is the PID controller algorithm that I would like to see implemented:
delta_u_n = Kp * [ (ep_n - ep_n-1) + ((Ts/Ti)*e_n)
+ (Td/Ts)*(edf_n - 2*edf_n-1 + edf_n-2) ]u_n = u_n-1 + delta_u_n
where:
delta_u : The incremental output
Kp : Proportional gain
ep : Proportional error with reference weighing
ep = beta * r - y
where:
beta : Weighing factor
r : Reference (setpoint)
y : Process value, measured
e : Error
e = r - y
Ts : Sampling interval
Ti : Integrator time
Td : Derivator time
edf : Derivate error with reference weighing and filtering
edf_n = edf_n-1 / ((Ts/Tf) + 1) + ed_n * (Ts/Tf) / ((Ts/Tf) + 1)
where:
Tf : Filter time
Tf = alpha * Td , where alpha usually is set to 0.1
ed : Unfiltered derivate error with reference weighing
ed = gamma * r - y
where:
gamma : Weighing factoru : absolute output
Index n means the n'th value.
Inputs: enabled , y_n , r_n , beta=1 , gamma=0 , alpha=0.1 , Kp , Ti , Td , Ts (is the sampling time available?) u_min , u_max
Output: u_n
if (enabled)
{
// Calculates proportional error:
ep_n = beta * r_n - y_n;
// Calculates error:
e_n = r_n - y_n;
// Calculates derivate error:
ed_n = gamma * r_n - y_n;
// Calculates filter time:
Tf = alpha * Td;
// Filters the derivate error:
edf_n = edf_n_1 / (Ts/Tf + 1)
+ (ed_n * (Ts/Tf) / (Ts/Tf + 1);
// Calculates the incremental output:
delta_u_n = Kp * ( (ep_n - ep_n_1)
+ ((Ts/Ti) * e_n)
+ ((Td/Ts) * (edf_n - 2*edf_n_1 + edf_n_2)) ); // Integrator anti-windup logic:
if ( delta_u_n > (u_max - u_n_1) )
delta_u_n = 0;
else if ( delta_u_n < (u_min - u_n_1) )
delta_u_n = 0;// Calculates absolute output: u_n = u_n_1 + delta_u_n;
// Updates indexed values;
u_n_1 = u_n;
ep_n_1 = ep_n;
edf_n_2 = edf_n_1;
edf_n_1 = edf_n;
}
else if (!enabled)
{
u_n = 0;
ep_n = 0;
edf_n = 0;
// Updates indexed values;
u_n_1 = u_n;
ep_n_1 = ep_n;
edf_n_2 = edf_n_1;
edf_n_1 = edf_n;
}Comments?
-- Roy Vegard Ovesen
_______________________________________________ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
