pidcontrol.h 1.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#ifndef PidControl_h
#define PidControl_h

//-----------------------------------------------------------------------------

/// Simple PID controller class
class PIDControl {
public:
    /// Default constructor
    PIDControl();

    /// Destructor
    virtual ~PIDControl();

    /// Set the Proportional, Integral and Derivative gains
    virtual PIDControl & setPIDGains( double pGain, double iGain, double dGain );

    /// Set the lower and upper limits for the integrator
    virtual PIDControl & setIntegratorLimits( double iMin, double iMax );
    
    void setPWMParams( float Period, float PulseWidth );
    
    /// Update loop
    virtual double update( double error, double position );

private:
    double m_dState;    ///< Last position input
    double m_iState;    ///< Integrator state
    double m_iMax;      ///< Maximum allowable integrator state
    double m_iMin;      ///< Minimum allowable integrator state

    double m_iGain;     ///< Integral gain
    double m_pGain;     ///< Proportional gain
    double m_dGain;     ///< Derivative gain
};

//-----------------------------------------------------------------------------

#endif //PidControl_h