Skip to content

Commit

Permalink
Add gov_spoolup_min_throttle
Browse files Browse the repository at this point in the history
The default 5% minimum throttle during spoolup doesn't work well for
nitro models. This commits adds a new configurable option to adjust the
minimum throttle used during spoolup.
  • Loading branch information
awigen committed Nov 2, 2024
1 parent 2eb9030 commit 33737f7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/cli/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ const clivalue_t valueTable[] = {
{ "gov_rpm_filter", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 250 }, PG_GOVERNOR_CONFIG, offsetof(governorConfig_t, gov_rpm_filter) },
{ "gov_tta_filter", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 250 }, PG_GOVERNOR_CONFIG, offsetof(governorConfig_t, gov_tta_filter) },
{ "gov_ff_filter", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 250 }, PG_GOVERNOR_CONFIG, offsetof(governorConfig_t, gov_ff_filter) },
{ "gov_spoolup_min_throttle", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_GOVERNOR_CONFIG, offsetof(governorConfig_t, gov_spoolup_min_throttle) },

// PG_CONTROLRATE_PROFILES
#ifdef USE_PROFILE_NAMES
Expand Down
7 changes: 4 additions & 3 deletions src/main/flight/governor.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#define GOV_THROTTLE_OFF_LIMIT 0.05f

// Throttle limits for spoolup
#define GOV_MIN_SPOOLUP_THROTTLE 0.05f
#define GOV_MAX_SPOOLUP_THROTTLE 0.95f

// Headspeed quality levels
Expand Down Expand Up @@ -108,6 +107,7 @@ typedef struct {

// Throttle handover level
float maxIdleThrottle;
float minSpoolupThrottle;

// Current headspeed
float actualHeadSpeed;
Expand Down Expand Up @@ -849,11 +849,11 @@ static float govSpoolUpControl(void)
output = gov.pidSum;

// Apply gov.C if output not saturated
if (!((output > GOV_MAX_SPOOLUP_THROTTLE && gov.C > 0) || (output < GOV_MIN_SPOOLUP_THROTTLE && gov.C < 0)))
if (!((output > GOV_MAX_SPOOLUP_THROTTLE && gov.C > 0) || (output < gov.minSpoolupThrottle && gov.C < 0)))
gov.I += gov.C;

// Limit output
output = constrainf(output, GOV_MIN_SPOOLUP_THROTTLE, GOV_MAX_SPOOLUP_THROTTLE);
output = constrainf(output, gov.minSpoolupThrottle, GOV_MAX_SPOOLUP_THROTTLE);

return output;
}
Expand Down Expand Up @@ -1150,6 +1150,7 @@ void governorInit(const pidProfile_t *pidProfile)
gov.lostHeadspeedTimeout = governorConfig()->gov_lost_headspeed_timeout * 100;

gov.maxIdleThrottle = constrain(governorConfig()->gov_handover_throttle, 10, 50) / 100.0f;
gov.minSpoolupThrottle = constrain(governorConfig()->gov_spoolup_min_throttle, 0, 100) / 100.0f;

const float diff_cutoff = governorConfig()->gov_rpm_filter ?
constrainf(governorConfig()->gov_rpm_filter, 1, 50) : 20;
Expand Down
2 changes: 2 additions & 0 deletions src/main/msp/msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,7 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst)
sbufWriteU8(dst, governorConfig()->gov_rpm_filter);
sbufWriteU8(dst, governorConfig()->gov_tta_filter);
sbufWriteU8(dst, governorConfig()->gov_ff_filter);
sbufWriteU8(dst, governorConfig()->gov_spoolup_min_throttle);
break;

default:
Expand Down Expand Up @@ -3337,6 +3338,7 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
governorConfigMutable()->gov_rpm_filter = sbufReadU8(src);
governorConfigMutable()->gov_tta_filter = sbufReadU8(src);
governorConfigMutable()->gov_ff_filter = sbufReadU8(src);
governorConfigMutable()->gov_spoolup_min_throttle = sbufReadU8(src);
break;

default:
Expand Down
1 change: 1 addition & 0 deletions src/main/pg/governor.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ PG_RESET_TEMPLATE(governorConfig_t, governorConfig,
.gov_rpm_filter = 10,
.gov_tta_filter = 0,
.gov_ff_filter = 10,
.gov_spoolup_min_throttle = 5,
);

1 change: 1 addition & 0 deletions src/main/pg/governor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct governorConfig_s {
uint8_t gov_rpm_filter;
uint8_t gov_tta_filter;
uint8_t gov_ff_filter;
uint8_t gov_spoolup_min_throttle;
} governorConfig_t;

PG_DECLARE(governorConfig_t, governorConfig);
Expand Down

0 comments on commit 33737f7

Please sign in to comment.