I've been given a plant transfer function to control trough a PID. The transfer function is:
$G_{\small{p}}(s) = \frac{1}{(1+s)(1+2s)}$
Doing a little work with matlab I got this PID controller transfer function:
$G_{\small{c}}(s) = 3 + \frac{1}{s} + \frac{2s}{1+\frac{s}{60}}$
So $K_{\small{p}} = 3, K_{\small{i}} = 1, K_{\small{d}} = 2$. Please note that I needed to put an high frequency pole into derivative term to keep it real. That pole has been put reasonably away from the bandwidth limit of the plant (cut-off frequency about $2 rad/s$).
Checking the step response on matlab everything seems to work really fine.
Now I need to discretize such controller function and provide anti-windup functionality, I'm not an expert but since I need an antiwindup I think I need to divide the integral action from the proportional and derivative action.
Using Tustin method and a sampling time of $10^{-3}s$ I got these:
uP[k] = 3*e[k]
uI[k] = 0.0005*(e[k] + e[k-1]) + uI[k-1]
uD[k] = 116.5*(e[k] - e[k-1]) + 0.9417 * uD[k-1]
of course the resulting command will be u[k] = uP[k] + uI[k] + uD[k]
The C code become:
double control(const double y, const double r)
{
static double e[2] = { 0, 0 }; // e[0] -> e_k-1, e[1] -> e_k
static double uD[2] = { 0, 0 }; // uD[0] -> uD_k-1, uD[1] -> uD_k
static double uI[2] = { 0, 0 }; // uI[0] -> uI_k-1, uI[1] -> uI_k
double uP, u;
e[1] = r - y;
uP = Kp * e[1];
uI[1] = Ki * (e[1] + e[0]) + uI[0];
uD[1] = Kd1 * (e[1] - e[0]) + Kd2 * uD[0];
u = uP + uI[1] + uD[1];
// Cut-Off
if(u>MAX_CMD){
u = MAX_CMD;
}
else if(u<MIN_CMD) {
u = MIN_CMD;
}
//
e[0] = e[1];
uD[0] = uD[1];
uI[0] = uI[1];
return u;
}
I think each step is correct but I don't feel very comfortable with such high derivative terms and low integral. Moreover I cannot figure out an effective antiwindup feature (I always used it on PI controllers never on PID). Something like that should work?
// Cut-Off
if(u>MAX_CMD){
u = MAX_CMD;
uI[1] = 0; // Antiwindup
}
else if(u<MIN_CMD) {
u = MIN_CMD;
uI[1] = 0; // Antiwindup
}
//
uI[1]=0
(effectivelyuI[0]
is also made zero immediately afterwards). Do you have a text book reference for this type of anti wind-up implementation? 2 "I don't feel very comfortable with such high derivative terms and low integral" Is that part of the question? It seems to be un related to the anti-wind-up part of the question. 3 why is a condition onu
checked for anti-wind-up rather thanuI
it self? $\endgroup$