FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
February 01, 1997

Embedded C++

(Page 3 of 5)

February 1997/A Reusable PID Control Class/Listing 2

Listing 2: The CalculateGain function


double PidControl::CalculateGain( double position )
{
    double error = Setpoint - position;
    ErrorSum += error;
    ProportionalGain = KProportional * error;
    IntegralGain = KIntegral * ErrorSum;
    if( fabs( IntegralGain ) > IntegralLimit ) {
       if( IntegralGain > 0 )
           IntegralGain = IntegralLimit;
       else
           IntegralGain = -IntegralLimit;
       ErrorSum -= error;
       }
    if( ++DifferentialCycleCount >= DifferentialCycle ) {
       DifferentialGain =  KDifferential * ( error - LastError );
       DifferentialCycleCount = 0;
       }
    LastError = error;
    Gain = ProportionalGain + IntegralGain + DifferentialGain;
    return Gain;
}
//End of File
Previous Page | 1 | 2 | 3 | 4 | 5 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK