mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 14:55:21 +03:00
Fix: RPM Limit - reset I-term at arm (#13214)
* RPM Limiter - reset I-term at arm * Update src/main/flight/mixer.c Co-authored-by: Jan Post <Rm2k-Freak@web.de> --------- Co-authored-by: Jan Post <Rm2k-Freak@web.de>
This commit is contained in:
parent
4f5bb1abc0
commit
6ac08cdd58
4 changed files with 10 additions and 5 deletions
|
@ -550,6 +550,9 @@ void tryArm(void)
|
||||||
|
|
||||||
#ifdef USE_OSD
|
#ifdef USE_OSD
|
||||||
osdSuppressStats(false);
|
osdSuppressStats(false);
|
||||||
|
#endif
|
||||||
|
#ifdef USE_RPM_LIMIT
|
||||||
|
mixerResetRpmLimiter();
|
||||||
#endif
|
#endif
|
||||||
ENABLE_ARMING_FLAG(ARMED);
|
ENABLE_ARMING_FLAG(ARMED);
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,6 @@ static void applyFlipOverAfterCrashModeToMotors(void)
|
||||||
static void applyRpmLimiter(mixerRuntime_t *mixer)
|
static void applyRpmLimiter(mixerRuntime_t *mixer)
|
||||||
{
|
{
|
||||||
static float prevError = 0.0f;
|
static float prevError = 0.0f;
|
||||||
static float i = 0.0f;
|
|
||||||
const float unsmoothedAverageRpm = getDshotRpmAverage();
|
const float unsmoothedAverageRpm = getDshotRpmAverage();
|
||||||
const float averageRpm = pt1FilterApply(&mixer->rpmLimiterAverageRpmFilter, unsmoothedAverageRpm);
|
const float averageRpm = pt1FilterApply(&mixer->rpmLimiterAverageRpmFilter, unsmoothedAverageRpm);
|
||||||
const float error = averageRpm - mixer->rpmLimiterRpmLimit;
|
const float error = averageRpm - mixer->rpmLimiterRpmLimit;
|
||||||
|
@ -356,9 +355,9 @@ static void applyRpmLimiter(mixerRuntime_t *mixer)
|
||||||
// PID
|
// PID
|
||||||
const float p = error * mixer->rpmLimiterPGain;
|
const float p = error * mixer->rpmLimiterPGain;
|
||||||
const float d = (error - prevError) * mixer->rpmLimiterDGain; // rpmLimiterDGain already adjusted for looprate (see mixer_init.c)
|
const float d = (error - prevError) * mixer->rpmLimiterDGain; // rpmLimiterDGain already adjusted for looprate (see mixer_init.c)
|
||||||
i += error * mixer->rpmLimiterIGain; // rpmLimiterIGain already adjusted for looprate (see mixer_init.c)
|
mixer->rpmLimiterI += error * mixer->rpmLimiterIGain; // rpmLimiterIGain already adjusted for looprate (see mixer_init.c)
|
||||||
i = MAX(0.0f, i);
|
mixer->rpmLimiterI = MAX(0.0f, mixer->rpmLimiterI);
|
||||||
float pidOutput = p + i + d;
|
float pidOutput = p + mixer->rpmLimiterI + d;
|
||||||
|
|
||||||
// Throttle limit learning
|
// Throttle limit learning
|
||||||
if (error > 0.0f && rcCommand[THROTTLE] < rxConfig()->maxcheck) {
|
if (error > 0.0f && rcCommand[THROTTLE] < rxConfig()->maxcheck) {
|
||||||
|
@ -382,7 +381,7 @@ static void applyRpmLimiter(mixerRuntime_t *mixer)
|
||||||
DEBUG_SET(DEBUG_RPM_LIMIT, 3, lrintf(throttle * 100.0f));
|
DEBUG_SET(DEBUG_RPM_LIMIT, 3, lrintf(throttle * 100.0f));
|
||||||
DEBUG_SET(DEBUG_RPM_LIMIT, 4, lrintf(error));
|
DEBUG_SET(DEBUG_RPM_LIMIT, 4, lrintf(error));
|
||||||
DEBUG_SET(DEBUG_RPM_LIMIT, 5, lrintf(p * 100.0f));
|
DEBUG_SET(DEBUG_RPM_LIMIT, 5, lrintf(p * 100.0f));
|
||||||
DEBUG_SET(DEBUG_RPM_LIMIT, 6, lrintf(i * 100.0f));
|
DEBUG_SET(DEBUG_RPM_LIMIT, 6, lrintf(mixer->rpmLimiterI * 100.0f));
|
||||||
DEBUG_SET(DEBUG_RPM_LIMIT, 7, lrintf(d * 100.0f));
|
DEBUG_SET(DEBUG_RPM_LIMIT, 7, lrintf(d * 100.0f));
|
||||||
}
|
}
|
||||||
#endif // USE_RPM_LIMIT
|
#endif // USE_RPM_LIMIT
|
||||||
|
|
|
@ -361,6 +361,7 @@ void mixerInitProfile(void)
|
||||||
mixerRuntime.rpmLimiterPGain = mixerConfig()->rpm_limit_p * 15e-6f;
|
mixerRuntime.rpmLimiterPGain = mixerConfig()->rpm_limit_p * 15e-6f;
|
||||||
mixerRuntime.rpmLimiterIGain = mixerConfig()->rpm_limit_i * 1e-3f * pidGetDT();
|
mixerRuntime.rpmLimiterIGain = mixerConfig()->rpm_limit_i * 1e-3f * pidGetDT();
|
||||||
mixerRuntime.rpmLimiterDGain = mixerConfig()->rpm_limit_d * 3e-7f * pidGetPidFrequency();
|
mixerRuntime.rpmLimiterDGain = mixerConfig()->rpm_limit_d * 3e-7f * pidGetPidFrequency();
|
||||||
|
mixerRuntime.rpmLimiterI = 0.0;
|
||||||
pt1FilterInit(&mixerRuntime.rpmLimiterAverageRpmFilter, pt1FilterGain(6.0f, pidGetDT()));
|
pt1FilterInit(&mixerRuntime.rpmLimiterAverageRpmFilter, pt1FilterGain(6.0f, pidGetDT()));
|
||||||
pt1FilterInit(&mixerRuntime.rpmLimiterThrottleScaleOffsetFilter, pt1FilterGain(2.0f, pidGetDT()));
|
pt1FilterInit(&mixerRuntime.rpmLimiterThrottleScaleOffsetFilter, pt1FilterGain(2.0f, pidGetDT()));
|
||||||
mixerResetRpmLimiter();
|
mixerResetRpmLimiter();
|
||||||
|
@ -373,6 +374,7 @@ void mixerInitProfile(void)
|
||||||
#ifdef USE_RPM_LIMIT
|
#ifdef USE_RPM_LIMIT
|
||||||
void mixerResetRpmLimiter(void)
|
void mixerResetRpmLimiter(void)
|
||||||
{
|
{
|
||||||
|
mixerRuntime.rpmLimiterI = 0.0;
|
||||||
mixerRuntime.rpmLimiterThrottleScale = constrainf(mixerRuntime.rpmLimiterRpmLimit / motorEstimateMaxRpm(), 0.0f, 1.0f);
|
mixerRuntime.rpmLimiterThrottleScale = constrainf(mixerRuntime.rpmLimiterRpmLimit / motorEstimateMaxRpm(), 0.0f, 1.0f);
|
||||||
mixerRuntime.rpmLimiterInitialThrottleScale = mixerRuntime.rpmLimiterThrottleScale;
|
mixerRuntime.rpmLimiterInitialThrottleScale = mixerRuntime.rpmLimiterThrottleScale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ typedef struct mixerRuntime_s {
|
||||||
float rpmLimiterPGain;
|
float rpmLimiterPGain;
|
||||||
float rpmLimiterIGain;
|
float rpmLimiterIGain;
|
||||||
float rpmLimiterDGain;
|
float rpmLimiterDGain;
|
||||||
|
float rpmLimiterI;
|
||||||
pt1Filter_t rpmLimiterAverageRpmFilter;
|
pt1Filter_t rpmLimiterAverageRpmFilter;
|
||||||
pt1Filter_t rpmLimiterThrottleScaleOffsetFilter;
|
pt1Filter_t rpmLimiterThrottleScaleOffsetFilter;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue