|
|
|
@ -24,7 +24,7 @@ public:
@@ -24,7 +24,7 @@ public:
|
|
|
|
|
_address(address), |
|
|
|
|
_integrator(0), |
|
|
|
|
_last_error(0), |
|
|
|
|
_last_error_derivative(0) |
|
|
|
|
_last_derivative(0) |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
/// Constructor
|
|
|
|
@ -38,7 +38,7 @@ public:
@@ -38,7 +38,7 @@ public:
|
|
|
|
|
_address(0), |
|
|
|
|
_integrator(0), |
|
|
|
|
_last_error(0), |
|
|
|
|
_last_error_derivative(0) |
|
|
|
|
_last_derivative(0) |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
/// Iterate the PID, return the new control value
|
|
|
|
@ -55,7 +55,11 @@ public:
@@ -55,7 +55,11 @@ public:
|
|
|
|
|
|
|
|
|
|
/// Reset the PID integrator
|
|
|
|
|
///
|
|
|
|
|
void reset_I() { _integrator = 0; _last_error = 0; } |
|
|
|
|
void reset_I() {
|
|
|
|
|
_integrator = 0;
|
|
|
|
|
_last_error = 0;
|
|
|
|
|
_last_derivative = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Load gain properties
|
|
|
|
|
///
|
|
|
|
@ -75,11 +79,11 @@ public:
@@ -75,11 +79,11 @@ public:
|
|
|
|
|
void kP(float v) { _kp = v; } |
|
|
|
|
void kI(float v) { _ki = v; } |
|
|
|
|
void kD(float v) { _kd = v; } |
|
|
|
|
void imax(float v) { _imax = v; } |
|
|
|
|
void imax(float v); |
|
|
|
|
//@}
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
uint16_t _address ///< EEPROM address for save/restore of P/I/D
|
|
|
|
|
uint16_t _address; ///< EEPROM address for save/restore of P/I/D
|
|
|
|
|
float *_gain_array; ///< pointer to the gains for this pid
|
|
|
|
|
|
|
|
|
|
float _kp; ///< proportional gain
|
|
|
|
@ -89,13 +93,14 @@ private:
@@ -89,13 +93,14 @@ private:
|
|
|
|
|
|
|
|
|
|
float _integrator; ///< integrator value
|
|
|
|
|
int32_t _last_error; ///< last error for derivative
|
|
|
|
|
float _last_derivative; ///< last derivative for low-pass filter
|
|
|
|
|
|
|
|
|
|
/// low pass filter cut frequency
|
|
|
|
|
/// for derivative calculation,
|
|
|
|
|
/// set to 20 Hz becasue anything over that
|
|
|
|
|
/// is probably noise, see
|
|
|
|
|
/// http://en.wikipedia.org/wiki/Low-pass_filter
|
|
|
|
|
static uint8_t _RC = 20;
|
|
|
|
|
static const uint8_t _RC = 20;
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|