mirror of https://github.com/ArduPilot/ardupilot
AC_PID: Create Leaky Integrator Function.
This commit is contained in:
parent
ca23a7ba76
commit
abd2a60036
|
@ -33,6 +33,25 @@ int32_t AC_PID::get_i(int32_t error, float dt)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// This is an integrator which tends to decay to zero naturally
|
||||
// if the error is zero.
|
||||
|
||||
int32_t AC_PID::get_leaky_i(int32_t error, float dt, float leak_rate)
|
||||
{
|
||||
if((_ki != 0) && (dt != 0)){
|
||||
_integrator -= (float)_integrator * leak_rate;
|
||||
_integrator += ((float)error * _ki) * dt;
|
||||
if (_integrator < -_imax) {
|
||||
_integrator = -_imax;
|
||||
} else if (_integrator > _imax) {
|
||||
_integrator = _imax;
|
||||
}
|
||||
|
||||
return _integrator;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AC_PID::get_d(int32_t input, float dt)
|
||||
{
|
||||
if ((_kd != 0) && (dt != 0)) {
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
int32_t get_p(int32_t error);
|
||||
int32_t get_i(int32_t error, float dt);
|
||||
int32_t get_d(int32_t error, float dt);
|
||||
int32_t get_leaky_i(int32_t error, float dt, float leak_rate);
|
||||
|
||||
|
||||
/// Reset the PID integrator
|
||||
|
|
Loading…
Reference in New Issue