PID: added get_pid_4500()

this is a version of get_pid() that returns an int16_t constrained to
-4500 to 4500. This will prevent overflow errors for large PID gains
in ArduPlane and Rover
This commit is contained in:
Andrew Tridgell 2013-04-01 22:08:36 +11:00
parent 624ebced38
commit 6123ea2dac
2 changed files with 9 additions and 0 deletions

View File

@ -88,6 +88,12 @@ float PID::get_pid(float error, float scaler)
return output;
}
int16_t PID::get_pid_4500(float error, float scaler)
{
float v = get_pid(error, scaler);
return constrain(v, -4500, 4500);
}
void
PID::reset_I()
{

View File

@ -42,6 +42,9 @@ public:
///
float get_pid(float error, float scaler = 1.0);
// get_pid() constrained to +/- 4500
int16_t get_pid_4500(float error, float scaler = 1.0);
/// Reset the PID integrator
///
void reset_I();