Merge pull request #2786 from martinbudden/bf_tricopter_iterm
Improved ITerm windup handling for tricopter
This commit is contained in:
commit
6f5727719f
|
@ -116,6 +116,9 @@ PG_REGISTER_ARRAY(motorMixer_t, MAX_SUPPORTED_MOTORS, customMotorMixer, PG_MOTOR
|
||||||
#define EXTERNAL_CONVERSION_MAX_VALUE 2000
|
#define EXTERNAL_CONVERSION_MAX_VALUE 2000
|
||||||
#define EXTERNAL_CONVERSION_3D_MID_VALUE 1500
|
#define EXTERNAL_CONVERSION_3D_MID_VALUE 1500
|
||||||
|
|
||||||
|
#define TRICOPTER_ERROR_RATE_YAW_SATURATED 75 // rate at which tricopter yaw axis becomes saturated, determined experimentally by TriFlight
|
||||||
|
|
||||||
|
|
||||||
static uint8_t motorCount;
|
static uint8_t motorCount;
|
||||||
static float motorMixRange;
|
static float motorMixRange;
|
||||||
|
|
||||||
|
@ -328,6 +331,16 @@ float getMotorMixRange()
|
||||||
return motorMixRange;
|
return motorMixRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mixerIsOutputSaturated(int axis, float errorRate)
|
||||||
|
{
|
||||||
|
if (axis == FD_YAW && (currentMixerMode == MIXER_TRI || currentMixerMode == MIXER_CUSTOM_TRI)) {
|
||||||
|
return errorRate > TRICOPTER_ERROR_RATE_YAW_SATURATED;
|
||||||
|
} else {
|
||||||
|
return motorMixRange >= 1.0f;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool isMotorProtocolDshot(void) {
|
bool isMotorProtocolDshot(void) {
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
switch(motorConfig()->dev.motorPwmProtocol) {
|
switch(motorConfig()->dev.motorPwmProtocol) {
|
||||||
|
|
|
@ -124,6 +124,7 @@ struct rxConfig_s;
|
||||||
|
|
||||||
uint8_t getMotorCount();
|
uint8_t getMotorCount();
|
||||||
float getMotorMixRange();
|
float getMotorMixRange();
|
||||||
|
bool mixerIsOutputSaturated(int axis, float errorRate);
|
||||||
|
|
||||||
void mixerLoadMix(int index, motorMixer_t *customMixers);
|
void mixerLoadMix(int index, motorMixer_t *customMixers);
|
||||||
void mixerInit(mixerMode_e mixerMode);
|
void mixerInit(mixerMode_e mixerMode);
|
||||||
|
|
|
@ -335,9 +335,12 @@ void pidController(const pidProfile_t *pidProfile, const rollAndPitchTrims_t *an
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----calculate I component
|
// -----calculate I component
|
||||||
if (motorMixRange < 1.0f) {
|
const float ITerm = axisPID_I[axis];
|
||||||
// Only increase ITerm if motor output is not saturated
|
const float ITermNew = ITerm + Ki[axis] * errorRate * dT * dynKi * itermAccelerator;
|
||||||
axisPID_I[axis] += Ki[axis] * errorRate * dT * dynKi * itermAccelerator;
|
const bool outputSaturated = mixerIsOutputSaturated(axis, errorRate);
|
||||||
|
if (outputSaturated == false || ABS(ITermNew) < ABS(ITerm)) {
|
||||||
|
// Only increase ITerm if output is not saturated
|
||||||
|
axisPID_I[axis] = ITermNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----calculate D component
|
// -----calculate D component
|
||||||
|
|
Loading…
Reference in New Issue