Commit acbcc7f0 authored by Claes Sjofors's avatar Claes Sjofors

PID controller, derivative filtering modified

parent 2d5b528b
...@@ -197,6 +197,9 @@ void CompModePID_Fo_exec( plc_sThread *tp, ...@@ -197,6 +197,9 @@ void CompModePID_Fo_exec( plc_sThread *tp,
/*_* /*_*
CompPID_Fo CompPID_Fo
Revision: 2011-01-18 / Werner
Error in filtered derivate part corrected.
@aref comppid_fo CompPID_Fo @aref comppid_fo CompPID_Fo
*/ */
void CompPID_Fo_init( pwr_sClass_CompPID_Fo *o) void CompPID_Fo_init( pwr_sClass_CompPID_Fo *o)
...@@ -227,6 +230,7 @@ void CompPID_Fo_exec( plc_sThread *tp, ...@@ -227,6 +230,7 @@ void CompPID_Fo_exec( plc_sThread *tp,
float derold; float derold;
float ut; float ut;
float dut; float dut;
float kd;
pwr_sClass_CompPID *co = (pwr_sClass_CompPID *) o->PlcConnectP; pwr_sClass_CompPID *co = (pwr_sClass_CompPID *) o->PlcConnectP;
if ( !co) if ( !co)
...@@ -259,13 +263,13 @@ void CompPID_Fo_exec( plc_sThread *tp, ...@@ -259,13 +263,13 @@ void CompPID_Fo_exec( plc_sThread *tp,
ddiff = ((co->PidAlg & DAVV) != 0) ? ddiff = ((co->PidAlg & DAVV) != 0) ?
(co->ControlDiff - eold) / *o->ScanTime: (co->ControlDiff - eold) / *o->ScanTime:
(co->ProcVal - xold) / *o->ScanTime; (co->ProcVal - xold) / *o->ScanTime;
if ((co->DerGain < 1.0) || if ((co->DerGain <= 0.0) || (co->DerTime <= 0))
(co->DerGain * *o->ScanTime >= co->DerTime)) co->FiltDer = ddiff; /* No Filter */
co->FiltDer = ddiff * co->DerTime; /* No Filter */ else {
else kd = 1.0 / (1.0 + co->DerGain * *o->ScanTime / co->DerTime);
co->FiltDer += (ddiff - derold) * co->FiltDer += (ddiff - derold) * (1.0 - kd);
co->DerGain * *o->ScanTime; /* Filter */ }
if ( co->Force ) { if ( co->Force ) {
/* Force */ /* Force */
dut = co->OutVal; dut = co->OutVal;
...@@ -288,7 +292,7 @@ void CompPID_Fo_exec( plc_sThread *tp, ...@@ -288,7 +292,7 @@ void CompPID_Fo_exec( plc_sThread *tp,
/* Not pure I-controller */ /* Not pure I-controller */
/* Derivative-part */ /* Derivative-part */
if ((co->PidAlg & DALG) != 0) if ((co->PidAlg & DALG) != 0)
dut += (co->FiltDer-derold); dut += (co->FiltDer-derold) * co->DerTime;
/* P-part */ /* P-part */
dut += ((co->PidAlg & PAVV) != 0) ? dut += ((co->PidAlg & PAVV) != 0) ?
co->ControlDiff - eold : co->ControlDiff - eold :
...@@ -326,7 +330,7 @@ void CompPID_Fo_exec( plc_sThread *tp, ...@@ -326,7 +330,7 @@ void CompPID_Fo_exec( plc_sThread *tp,
ut = co->ControlDiff; ut = co->ControlDiff;
/* Derivative-part */ /* Derivative-part */
if ((co->PidAlg & DALG) != 0) if ((co->PidAlg & DALG) != 0)
ut += co->FiltDer; ut += co->FiltDer * co->DerTime;
/* Gain */ /* Gain */
ut *= co->Gain; ut *= co->Gain;
if (co->Inverse != 0) ut = - ut; if (co->Inverse != 0) ut = - ut;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment