New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PaPaYoU - Introducing LUA and OSD Updates to utilize the new Filter parameters #51
Changes from 6 commits
b9b0f7e
35aa27a
c0199ab
6db08c1
3d4e9c5
4be2466
37b4efc
085e8e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ void resetPidProfile(pidProfile_t *pidProfile) | |
.dterm_notch_hz = 260, | ||
.dterm_notch_cutoff = 160, | ||
.dterm_filter_type = FILTER_PT1, | ||
.dterm_filter_style = KD_FILTER_CLASSIC, | ||
.dterm_filter_style = CLASSIC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert to KD_FILTER_CLASSIC |
||
.itermWindupPointPercent = 50, | ||
.vbatPidCompensation = 0, | ||
.pidAtMinThrottle = PID_STABILISATION_ON, | ||
|
@@ -511,28 +511,28 @@ void pidController(const pidProfile_t *pidProfile, const rollAndPitchTrims_t *an | |
if (axis != FD_YAW) { | ||
// apply filters | ||
float gyroRateFiltered = dtermNotchFilterApplyFn(dtermFilterNotch[axis], gyroRate); | ||
if (pidProfile->dterm_filter_style == KD_FILTER_CLASSIC) | ||
if (pidProfile->dterm_filter_style == CLASSIC) | ||
{ | ||
gyroRateFiltered = dtermLpfApplyFn(dtermFilterLpf[axis], gyroRateFiltered); | ||
} | ||
|
||
const float rD = dynCd * MIN(getRcDeflectionAbs(axis) * relaxFactor, 1.0f) * currentPidSetpoint - gyroRateFiltered; // cr - y | ||
const float pureRD = dynCd * MIN(getRcDeflectionAbs(axis) * relaxFactor, 1.0f) * getSetpointRate(axis) - gyroRateFiltered; // cr - y | ||
|
||
float delta = 0.0f; | ||
float iDT = 1.0f/deltaT; //divide once | ||
|
||
switch (pidProfile->dterm_filter_style) { | ||
case KD_FILTER_CLASSIC: | ||
case CLASSIC: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert cases to KD_FILTER_XXXX variant |
||
delta = (rD - previousRateError[axis]) * iDT; | ||
previousRateError[axis] = rD; | ||
break; | ||
case KD_FILTER_SP: | ||
case SP: | ||
//filter Kd properly along with sp | ||
delta = dtermLpfApplyFn(dtermFilterLpf[axis], (rD - previousRateError[axis]) * iDT ); | ||
previousRateError[axis] = rD; | ||
break; | ||
case KD_FILTER_NOSP: | ||
case NOSP: | ||
//filter Kd properly, no sp | ||
delta = dtermLpfApplyFn(dtermFilterLpf[axis], (pureRD - previousRateError[axis]) * iDT ); | ||
previousRateError[axis] = pureRD; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1178,16 +1178,32 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst) | |
sbufWriteU16(dst, gyroConfig()->gyro_soft_notch_hz_2); | ||
sbufWriteU16(dst, gyroConfig()->gyro_soft_notch_cutoff_2); | ||
sbufWriteU8(dst, currentPidProfile->dterm_filter_type); | ||
sbufWriteU8(dst, currentPidProfile->dterm_filter_style); | ||
break; | ||
|
||
#ifdef USE_GYRO_FAST_KALMAN | ||
case MSP_ADVANCED_FILTER_CONFIG : | ||
sbufWriteU16(dst, gyroConfig()->gyro_soft_lpf_hz_2); | ||
case MSP_FAST_KALMAN : | ||
sbufWriteU16(dst, gyroConfig()->gyro_filter_q); | ||
sbufWriteU16(dst, gyroConfig()->gyro_filter_r); | ||
sbufWriteU16(dst, gyroConfig()->gyro_filter_p); | ||
sbufWriteU8(dst, gyroConfig()->gyro_stage2_filter_type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not need gyro_stage2_filter_type anymore? |
||
break; | ||
#endif | ||
|
||
#ifdef USE_GYRO_IMUF9001 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something whack going on with the TABS on this area - could we please get that harmonized to line up with the rest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
case MSP_IMUF_CONFIG : | ||
sbufWriteU16(dst, gyroConfig()->imuf_mode); | ||
sbufWriteU16(dst, gyroConfig()->imuf_pitch_q); | ||
sbufWriteU16(dst, gyroConfig()->imuf_pitch_r); | ||
sbufWriteU16(dst, gyroConfig()->imuf_roll_q); | ||
sbufWriteU16(dst, gyroConfig()->imuf_roll_r); | ||
sbufWriteU16(dst, gyroConfig()->imuf_yaw_q); | ||
sbufWriteU16(dst, gyroConfig()->imuf_yaw_r); | ||
sbufWriteU16(dst, gyroConfig()->imuf_pitch_lpf_cutoff_hz); | ||
sbufWriteU16(dst, gyroConfig()->imuf_roll_lpf_cutoff_hz); | ||
sbufWriteU16(dst, gyroConfig()->imuf_yaw_lpf_cutoff_hz); | ||
sbufWriteU16(dst, gyroConfig()->imuf_dyn_gain); | ||
break; | ||
#endif | ||
|
||
case MSP_PID_ADVANCED: | ||
sbufWriteU16(dst, 0); | ||
sbufWriteU16(dst, 0); | ||
|
@@ -1647,22 +1663,37 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src) | |
gyroConfigMutable()->gyro_soft_notch_hz_2 = sbufReadU16(src); | ||
gyroConfigMutable()->gyro_soft_notch_cutoff_2 = sbufReadU16(src); | ||
} | ||
if (sbufBytesRemaining(src) >= 1) { | ||
if (sbufBytesRemaining(src) >= 2) { | ||
currentPidProfile->dterm_filter_type = sbufReadU8(src); | ||
currentPidProfile->dterm_filter_style = sbufReadU8(src); | ||
} | ||
// reinitialize the gyro filters with the new values | ||
validateAndFixGyroConfig(); | ||
gyroInitFilters(); | ||
// reinitialize the PID filters with the new values | ||
pidInitFilters(currentPidProfile); | ||
break; | ||
|
||
#ifdef USE_GYRO_FAST_KALMAN | ||
case MSP_SET_ADVANCED_FILTER_CONFIG : | ||
gyroConfigMutable()->gyro_soft_lpf_hz_2 = sbufReadU16(src); | ||
case MSP_SET_FAST_KALMAN : | ||
gyroConfigMutable()->gyro_filter_q = sbufReadU16(src); | ||
gyroConfigMutable()->gyro_filter_r = sbufReadU16(src); | ||
gyroConfigMutable()->gyro_filter_p = sbufReadU16(src); | ||
gyroConfigMutable()->gyro_stage2_filter_type = sbufReadU8(src); | ||
break; | ||
#endif | ||
|
||
#ifdef USE_GYRO_IMUF9001 | ||
case MSP_SET_IMUF_CONFIG : | ||
gyroConfigMutable()->imuf_mode = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_pitch_q = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_pitch_r = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_roll_q = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_roll_r = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_yaw_q = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_yaw_r = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_pitch_lpf_cutoff_hz = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_roll_lpf_cutoff_hz = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_yaw_lpf_cutoff_hz = sbufReadU16(src); | ||
gyroConfigMutable()->imuf_dyn_gain = sbufReadU16(src); | ||
break; | ||
#endif | ||
case MSP_SET_PID_ADVANCED: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,7 +250,7 @@ static const char * const lookupTableLowpassType[] = { | |
}; | ||
|
||
static const char * const lookupTableKdStyle[] = { | ||
"KD_FILTER_CLASSIC", "KD_FILTER_SP", "KD_FILTER_NOSP" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert for clarity =D |
||
"CLASSIC", "SP", "NOSP" | ||
}; | ||
|
||
static const char * const lookupTableFailsafe[] = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,29 +48,29 @@ void targetConfiguration(void) { | |
|
||
#if defined(HELIO_RACE) | ||
//optimizng for strech-x | ||
pidProfile->pid[PID_PITCH].P = 30; | ||
pidProfile->pid[PID_PITCH].I = 60; | ||
pidProfile->pid[PID_PITCH].D = 17; | ||
pidProfile->pid[PID_ROLL].P = 28; | ||
pidProfile->pid[PID_ROLL].I = 70; | ||
pidProfile->pid[PID_PITCH].P = 30; | ||
pidProfile->pid[PID_PITCH].I = 60; | ||
pidProfile->pid[PID_PITCH].D = 17; | ||
pidProfile->pid[PID_ROLL].P = 28; | ||
pidProfile->pid[PID_ROLL].I = 70; | ||
pidProfile->pid[PID_ROLL].D = 20; | ||
#elif defined(HELIO_FREESTYLE) | ||
//optimizng for squished-x | ||
pidProfile->pid[PID_PITCH].P = 40; | ||
pidProfile->pid[PID_PITCH].I = 55; | ||
pidProfile->pid[PID_PITCH].D = 27; | ||
pidProfile->pid[PID_ROLL].P = 43; | ||
pidProfile->pid[PID_ROLL].I = 45; | ||
pidProfile->pid[PID_PITCH].P = 40; | ||
pidProfile->pid[PID_PITCH].I = 55; | ||
pidProfile->pid[PID_PITCH].D = 27; | ||
pidProfile->pid[PID_ROLL].P = 43; | ||
pidProfile->pid[PID_ROLL].I = 45; | ||
pidProfile->pid[PID_ROLL].D = 25; | ||
#elif defined(HELIO_BANGOOD_SPECIAL) | ||
//optimizng for IDKWTF set the normal defaults | ||
#else | ||
//optimizng for true-x and most standard tunes. | ||
pidProfile->pid[PID_PITCH].P = 45; | ||
pidProfile->pid[PID_PITCH].I = 50; | ||
pidProfile->pid[PID_PITCH].D = 30; | ||
pidProfile->pid[PID_ROLL].P = 45; | ||
pidProfile->pid[PID_ROLL].I = 50; | ||
pidProfile->pid[PID_PITCH].P = 45; | ||
pidProfile->pid[PID_PITCH].I = 50; | ||
pidProfile->pid[PID_PITCH].D = 30; | ||
pidProfile->pid[PID_ROLL].P = 45; | ||
pidProfile->pid[PID_ROLL].I = 50; | ||
pidProfile->pid[PID_ROLL].D = 30; | ||
#endif | ||
|
||
|
@@ -80,12 +80,11 @@ void targetConfiguration(void) { | |
pidProfile->itermAcceleratorGain = 5000; | ||
// should't need to set these since they don't get init in gyro.c with USE_GYRO_IMUF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If these are really no longer needed we should just remove them entirely instead of leaving comments IMO |
||
// pidProfile->yaw_lpf_hz = 0; | ||
// pidProfile->dterm_lpf_hz = 0; | ||
// pidProfile->dterm_lpf_hz = 0; | ||
// pidProfile->dterm_notch_hz = 0; | ||
// pidProfile->dterm_notch_cutoff = 0; | ||
pidProfile->dterm_filter_type = FILTER_BIQUAD; | ||
pidProfile->dterm_filter_style = KD_FILTER_NOSP; | ||
pidProfile->dterm_filter_style = NOSP; | ||
pidProfile->dterm_lpf_hz = 60; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hate to do this to ya PaPaYou but I think we should revert this change and keep them as KD_FILTER_XXXX - just so the code clarity is improved.
SP / CLASSIC / NOSP are fine for people familiar with the genesis of these features but for anyone else that comes in on this code it might be confusing. The KD_FILTER add some clarity by making it immeditaly obvious that its dealing with D term filters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sure no problem