Commit 2d5b528b authored by Claes Sjofors's avatar Claes Sjofors

PID controller, derivative filtering modified, and function object Filter...

PID controller, derivative filtering modified, and function object Filter filter algorithm  modified
parent 26621636
...@@ -352,11 +352,14 @@ void filter_exec( ...@@ -352,11 +352,14 @@ void filter_exec(
plc_sThread *tp, plc_sThread *tp,
pwr_sClass_filter *object) pwr_sClass_filter *object)
{ {
float kd;
object->In = *object->InP; object->In = *object->InP;
if (object->FiltCon > *object->ScanTime) if (object->FiltCon > 0.0) {
kd = 1.0 / (1.0 + *object->ScanTime / object->FiltCon);
object->ActVal = *object->FeedBP + object->ActVal = *object->FeedBP +
(object->In - *object->FeedBP) * *object->ScanTime / object->FiltCon; (object->In - *object->FeedBP) * (1.0 - kd);
else } else
object->ActVal = object->In; object->ActVal = object->In;
} }
......
...@@ -338,6 +338,9 @@ void mode_exec( ...@@ -338,6 +338,9 @@ void mode_exec(
Possible to turn off integration and to force Possible to turn off integration and to force
output to desired value. output to desired value.
Revision: 2011-01-18 / Werner
Error in filtered derivate part corrected.
@aref pid Pid @aref pid Pid
*/ */
...@@ -360,6 +363,7 @@ void pid_exec( ...@@ -360,6 +363,7 @@ void pid_exec(
float derold; float derold;
float ut; float ut;
float dut; float dut;
float kd;
/* Save old values */ /* Save old values */
xold=object->ProcVal; xold=object->ProcVal;
...@@ -381,12 +385,12 @@ object->ControlDiff = object->ProcVal - object->SetVal; ...@@ -381,12 +385,12 @@ object->ControlDiff = object->ProcVal - object->SetVal;
ddiff = ((object->PidAlg & DAVV) != 0) ? ddiff = ((object->PidAlg & DAVV) != 0) ?
(object->ControlDiff - eold) / *object->ScanTime: (object->ControlDiff - eold) / *object->ScanTime:
(object->ProcVal - xold) / *object->ScanTime; (object->ProcVal - xold) / *object->ScanTime;
if ((object->DerGain < 1.0) || if ((object->DerGain <= 0.0) || (object->DerTime <= 0))
(object->DerGain * *object->ScanTime >= object->DerTime)) object->FiltDer = ddiff; /* No Filter */
object->FiltDer = ddiff * object->DerTime; /* No Filter */ else {
else kd = 1.0 / (1.0 + object->DerGain * *object->ScanTime / object->DerTime);
object->FiltDer += (ddiff - derold) * object->FiltDer += (ddiff - derold) * (1.0 - kd);
object->DerGain * *object->ScanTime; /* Filter */ }
if ( object->Force ) if ( object->Force )
/* Force */ /* Force */
...@@ -414,7 +418,7 @@ else ...@@ -414,7 +418,7 @@ else
{ {
/* Derivative-part */ /* Derivative-part */
if ((object->PidAlg & DALG) != 0) if ((object->PidAlg & DALG) != 0)
dut += (object->FiltDer-derold); dut += (object->FiltDer-derold) * object->DerTime;
/* P-part */ /* P-part */
dut += ((object->PidAlg & PAVV) != 0) ? dut += ((object->PidAlg & PAVV) != 0) ?
object->ControlDiff - eold : object->ControlDiff - eold :
...@@ -457,7 +461,7 @@ else ...@@ -457,7 +461,7 @@ else
ut = object->ControlDiff; ut = object->ControlDiff;
/* Derivative-part */ /* Derivative-part */
if ((object->PidAlg & DALG) != 0) if ((object->PidAlg & DALG) != 0)
ut += object->FiltDer; ut += object->FiltDer * object->DerTime;
/* Gain */ /* Gain */
ut *= object->Gain; ut *= object->Gain;
if (object->Inverse != 0) ut = - ut; if (object->Inverse != 0) ut = - ut;
......
...@@ -34,8 +34,7 @@ SObject pwrb:Class ...@@ -34,8 +34,7 @@ SObject pwrb:Class
! X = FeedB, if FeedB is connected, ! X = FeedB, if FeedB is connected,
! ActValt - 1, otherwise ! ActValt - 1, otherwise
! !
! a = ScanTime / FiltCon and 0 < a < 1.0. ! a = 1 - 1 / (1 + ScanTime / FiltCon)
! If a >= 1.0 no filtering is done.
! !
! An external signal may also be used as feedback; e.g. ! An external signal may also be used as feedback; e.g.
! @image orm_en1-77.gif ! @image orm_en1-77.gif
......
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