mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
Merge pull request #5945 from supiiik/master
New calculation method for Dterm setpoint weight
This commit is contained in:
commit
71a1a9789a
6 changed files with 12 additions and 8 deletions
|
@ -237,7 +237,7 @@ static CMS_Menu cmsx_menuRateProfile = {
|
||||||
.entries = cmsx_menuRateProfileEntries
|
.entries = cmsx_menuRateProfileEntries
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t cmsx_dtermSetpointWeight;
|
static uint16_t cmsx_dtermSetpointWeight;
|
||||||
static uint8_t cmsx_setpointRelaxRatio;
|
static uint8_t cmsx_setpointRelaxRatio;
|
||||||
static uint8_t cmsx_angleStrength;
|
static uint8_t cmsx_angleStrength;
|
||||||
static uint8_t cmsx_horizonStrength;
|
static uint8_t cmsx_horizonStrength;
|
||||||
|
@ -285,7 +285,7 @@ static long cmsx_profileOtherOnExit(const OSD_Entry *self)
|
||||||
static OSD_Entry cmsx_menuProfileOtherEntries[] = {
|
static OSD_Entry cmsx_menuProfileOtherEntries[] = {
|
||||||
{ "-- OTHER PP --", OME_Label, NULL, pidProfileIndexString, 0 },
|
{ "-- OTHER PP --", OME_Label, NULL, pidProfileIndexString, 0 },
|
||||||
|
|
||||||
{ "D SETPT WT", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &cmsx_dtermSetpointWeight, 0, 255, 1, 10 }, 0 },
|
{ "D SETPT WT", OME_UINT16, NULL, &(OSD_UINT16_t) { &cmsx_dtermSetpointWeight, 0, 2000, 1 }, 0 },
|
||||||
{ "SETPT TRS", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &cmsx_setpointRelaxRatio, 0, 100, 1, 10 }, 0 },
|
{ "SETPT TRS", OME_FLOAT, NULL, &(OSD_FLOAT_t) { &cmsx_setpointRelaxRatio, 0, 100, 1, 10 }, 0 },
|
||||||
{ "ANGLE STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_angleStrength, 0, 200, 1 } , 0 },
|
{ "ANGLE STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_angleStrength, 0, 200, 1 } , 0 },
|
||||||
{ "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_horizonStrength, 0, 200, 1 } , 0 },
|
{ "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t) { &cmsx_horizonStrength, 0, 200, 1 } , 0 },
|
||||||
|
|
|
@ -401,7 +401,7 @@ static int applyStepAdjustment(controlRateConfig_t *controlRateConfig, uint8_t a
|
||||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RC_RATE_YAW, newValue);
|
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RC_RATE_YAW, newValue);
|
||||||
break;
|
break;
|
||||||
case ADJUSTMENT_D_SETPOINT:
|
case ADJUSTMENT_D_SETPOINT:
|
||||||
newValue = constrain((int)pidProfile->dtermSetpointWeight + delta, 0, 254); // FIXME magic numbers repeated in cli.c
|
newValue = constrain((int)pidProfile->dtermSetpointWeight + delta, 0, 2000); // FIXME magic numbers repeated in cli.c
|
||||||
pidProfile->dtermSetpointWeight = newValue;
|
pidProfile->dtermSetpointWeight = newValue;
|
||||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT, newValue);
|
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT, newValue);
|
||||||
break;
|
break;
|
||||||
|
@ -550,7 +550,7 @@ static int applyAbsoluteAdjustment(controlRateConfig_t *controlRateConfig, adjus
|
||||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RC_RATE_YAW, newValue);
|
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_RC_RATE_YAW, newValue);
|
||||||
break;
|
break;
|
||||||
case ADJUSTMENT_D_SETPOINT:
|
case ADJUSTMENT_D_SETPOINT:
|
||||||
newValue = constrain(value, 0, 254); // FIXME magic numbers repeated in cli.c
|
newValue = constrain(value, 0, 2000); // FIXME magic numbers repeated in cli.c
|
||||||
pidProfile->dtermSetpointWeight = newValue;
|
pidProfile->dtermSetpointWeight = newValue;
|
||||||
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT, newValue);
|
blackboxLogInflightAdjustmentEvent(ADJUSTMENT_D_SETPOINT, newValue);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -88,7 +88,7 @@ PG_RESET_TEMPLATE(pidConfig_t, pidConfig,
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PG_REGISTER_ARRAY_WITH_RESET_FN(pidProfile_t, MAX_PROFILE_COUNT, pidProfiles, PG_PID_PROFILE, 2);
|
PG_REGISTER_ARRAY_WITH_RESET_FN(pidProfile_t, MAX_PROFILE_COUNT, pidProfiles, PG_PID_PROFILE, 3);
|
||||||
|
|
||||||
void resetPidProfile(pidProfile_t *pidProfile)
|
void resetPidProfile(pidProfile_t *pidProfile)
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,7 +98,7 @@ typedef struct pidProfile_s {
|
||||||
uint16_t itermThrottleThreshold; // max allowed throttle delta before iterm accelerated in ms
|
uint16_t itermThrottleThreshold; // max allowed throttle delta before iterm accelerated in ms
|
||||||
uint16_t itermAcceleratorGain; // Iterm Accelerator Gain when itermThrottlethreshold is hit
|
uint16_t itermAcceleratorGain; // Iterm Accelerator Gain when itermThrottlethreshold is hit
|
||||||
uint8_t setpointRelaxRatio; // Setpoint weight relaxation effect
|
uint8_t setpointRelaxRatio; // Setpoint weight relaxation effect
|
||||||
uint8_t dtermSetpointWeight; // Setpoint weight for Dterm (0= measurement, 1= full error, 1 > aggressive derivative)
|
uint16_t dtermSetpointWeight; // Setpoint weight for Dterm (0= measurement, 1= full error, 1 > aggressive derivative)
|
||||||
uint16_t yawRateAccelLimit; // yaw accel limiter for deg/sec/ms
|
uint16_t yawRateAccelLimit; // yaw accel limiter for deg/sec/ms
|
||||||
uint16_t rateAccelLimit; // accel limiter roll/pitch deg/sec/ms
|
uint16_t rateAccelLimit; // accel limiter roll/pitch deg/sec/ms
|
||||||
uint16_t crash_dthreshold; // dterm crash value
|
uint16_t crash_dthreshold; // dterm crash value
|
||||||
|
|
|
@ -1224,7 +1224,7 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
|
||||||
sbufWriteU8(dst, 0); // reserved
|
sbufWriteU8(dst, 0); // reserved
|
||||||
sbufWriteU8(dst, currentPidProfile->vbatPidCompensation);
|
sbufWriteU8(dst, currentPidProfile->vbatPidCompensation);
|
||||||
sbufWriteU8(dst, currentPidProfile->setpointRelaxRatio);
|
sbufWriteU8(dst, currentPidProfile->setpointRelaxRatio);
|
||||||
sbufWriteU8(dst, currentPidProfile->dtermSetpointWeight);
|
sbufWriteU8(dst, MIN(currentPidProfile->dtermSetpointWeight, 255));
|
||||||
sbufWriteU8(dst, 0); // reserved
|
sbufWriteU8(dst, 0); // reserved
|
||||||
sbufWriteU8(dst, 0); // reserved
|
sbufWriteU8(dst, 0); // reserved
|
||||||
sbufWriteU8(dst, 0); // reserved
|
sbufWriteU8(dst, 0); // reserved
|
||||||
|
@ -1234,6 +1234,7 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
|
||||||
sbufWriteU8(dst, 0); // was pidProfile.levelSensitivity
|
sbufWriteU8(dst, 0); // was pidProfile.levelSensitivity
|
||||||
sbufWriteU16(dst, currentPidProfile->itermThrottleThreshold);
|
sbufWriteU16(dst, currentPidProfile->itermThrottleThreshold);
|
||||||
sbufWriteU16(dst, currentPidProfile->itermAcceleratorGain);
|
sbufWriteU16(dst, currentPidProfile->itermAcceleratorGain);
|
||||||
|
sbufWriteU16(dst, currentPidProfile->dtermSetpointWeight);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_SENSOR_CONFIG:
|
case MSP_SENSOR_CONFIG:
|
||||||
|
@ -1694,6 +1695,9 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
||||||
currentPidProfile->itermThrottleThreshold = sbufReadU16(src);
|
currentPidProfile->itermThrottleThreshold = sbufReadU16(src);
|
||||||
currentPidProfile->itermAcceleratorGain = sbufReadU16(src);
|
currentPidProfile->itermAcceleratorGain = sbufReadU16(src);
|
||||||
}
|
}
|
||||||
|
if (sbufBytesRemaining(src) >= 2) {
|
||||||
|
currentPidProfile->dtermSetpointWeight = sbufReadU16(src);
|
||||||
|
}
|
||||||
pidInitConfig(currentPidProfile);
|
pidInitConfig(currentPidProfile);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -738,7 +738,7 @@ const clivalue_t valueTable[] = {
|
||||||
{ "anti_gravity_threshold", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 20, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermThrottleThreshold) },
|
{ "anti_gravity_threshold", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 20, 1000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermThrottleThreshold) },
|
||||||
{ "anti_gravity_gain", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 1000, 30000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermAcceleratorGain) },
|
{ "anti_gravity_gain", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 1000, 30000 }, PG_PID_PROFILE, offsetof(pidProfile_t, itermAcceleratorGain) },
|
||||||
{ "setpoint_relax_ratio", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, setpointRelaxRatio) },
|
{ "setpoint_relax_ratio", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 100 }, PG_PID_PROFILE, offsetof(pidProfile_t, setpointRelaxRatio) },
|
||||||
{ "dterm_setpoint_weight", VAR_UINT8 | PROFILE_VALUE, .config.minmax = { 0, 254 }, PG_PID_PROFILE, offsetof(pidProfile_t, dtermSetpointWeight) },
|
{ "dterm_setpoint_weight", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 2000 }, PG_PID_PROFILE, offsetof(pidProfile_t, dtermSetpointWeight) },
|
||||||
{ "acc_limit_yaw", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, yawRateAccelLimit) },
|
{ "acc_limit_yaw", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, yawRateAccelLimit) },
|
||||||
{ "acc_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, rateAccelLimit) },
|
{ "acc_limit", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 500 }, PG_PID_PROFILE, offsetof(pidProfile_t, rateAccelLimit) },
|
||||||
{ "crash_dthreshold", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 2000 }, PG_PID_PROFILE, offsetof(pidProfile_t, crash_dthreshold) },
|
{ "crash_dthreshold", VAR_UINT16 | PROFILE_VALUE, .config.minmax = { 0, 2000 }, PG_PID_PROFILE, offsetof(pidProfile_t, crash_dthreshold) },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue