Skip to content

Commit

Permalink
Make dyn idle startup increase configurable (betaflight#12432)
Browse files Browse the repository at this point in the history
* Make dyn idle startup increase configurable

Replace fixed 5 percent max increase from dynamic idle
when airmode is active with a configurable value.

-Default value is still 5.0 percent (50 in cli)
-Add dyn_idle_start_increase cli setting
-Add dyn_idle_start_increase BB header field

* Increse PG reset to ver 6 for pidProfile

* Indentation

---------

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
  • Loading branch information
2 people authored and davidbitton committed Feb 5, 2024
1 parent 94a607e commit 1c740d9
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/blackbox/blackbox.c
Expand Up @@ -1494,6 +1494,7 @@ static bool blackboxWriteSysinfo(void)
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DYN_IDLE_I_GAIN, "%d", currentPidProfile->dyn_idle_i_gain);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DYN_IDLE_D_GAIN, "%d", currentPidProfile->dyn_idle_d_gain);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DYN_IDLE_MAX_INCREASE, "%d", currentPidProfile->dyn_idle_max_increase);
BLACKBOX_PRINT_HEADER_LINE(PARAM_NAME_DYN_IDLE_START_INCREASE, "%d", currentPidProfile->dyn_idle_start_increase);
#endif

#ifdef USE_SIMPLIFIED_TUNING
Expand Down
1 change: 1 addition & 0 deletions src/main/cli/settings.c
Expand Up @@ -1194,6 +1194,7 @@ const clivalue_t valueTable[] = {
{ PARAM_NAME_DYN_IDLE_I_GAIN, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 1, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, dyn_idle_i_gain) },
{ PARAM_NAME_DYN_IDLE_D_GAIN, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 250 }, PG_PID_PROFILE, offsetof(pidProfile_t, dyn_idle_d_gain) },
{ PARAM_NAME_DYN_IDLE_MAX_INCREASE, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 10, 255 }, PG_PID_PROFILE, offsetof(pidProfile_t, dyn_idle_max_increase) },
{ PARAM_NAME_DYN_IDLE_START_INCREASE, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 10, 255 }, PG_PID_PROFILE, offsetof(pidProfile_t, dyn_idle_start_increase) },
#endif
{ "level_race_mode", VAR_UINT8 | PROFILE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_PID_PROFILE, offsetof(pidProfile_t, level_race_mode) },

Expand Down
1 change: 1 addition & 0 deletions src/main/fc/parameter_names.h
Expand Up @@ -100,6 +100,7 @@
#define PARAM_NAME_DYN_IDLE_I_GAIN "dyn_idle_i_gain"
#define PARAM_NAME_DYN_IDLE_D_GAIN "dyn_idle_d_gain"
#define PARAM_NAME_DYN_IDLE_MAX_INCREASE "dyn_idle_max_increase"
#define PARAM_NAME_DYN_IDLE_START_INCREASE "dyn_idle_start_increase"
#define PARAM_NAME_SIMPLIFIED_PIDS_MODE "simplified_pids_mode"
#define PARAM_NAME_SIMPLIFIED_MASTER_MULTIPLIER "simplified_master_multiplier"
#define PARAM_NAME_SIMPLIFIED_I_GAIN "simplified_i_gain"
Expand Down
3 changes: 2 additions & 1 deletion src/main/flight/mixer.c
Expand Up @@ -221,7 +221,8 @@ static void calculateThrottleAndCurrentMotorEndpoints(timeUs_t currentTimeUs)

#ifdef USE_DYN_IDLE
if (mixerRuntime.dynIdleMinRps > 0.0f) {
const float maxIncrease = isAirmodeActivated() ? mixerRuntime.dynIdleMaxIncrease : 0.05f;
const float maxIncrease = isAirmodeActivated()
? mixerRuntime.dynIdleMaxIncrease : mixerRuntime.dynIdleStartIncrease;
float minRps = getMinMotorFrequency();
DEBUG_SET(DEBUG_DYN_IDLE, 3, lrintf(minRps * 10.0f));
float rpsError = mixerRuntime.dynIdleMinRps - minRps;
Expand Down
1 change: 1 addition & 0 deletions src/main/flight/mixer_init.c
Expand Up @@ -318,6 +318,7 @@ void mixerInitProfile(void)
mixerRuntime.dynIdleIGain = currentPidProfile->dyn_idle_i_gain * 0.01f * pidGetDT();
mixerRuntime.dynIdleDGain = currentPidProfile->dyn_idle_d_gain * 0.0000003f * pidGetPidFrequency();
mixerRuntime.dynIdleMaxIncrease = currentPidProfile->dyn_idle_max_increase * 0.001f;
mixerRuntime.dynIdleStartIncrease = currentPidProfile->dyn_idle_start_increase * 0.001f;
mixerRuntime.minRpsDelayK = 800 * pidGetDT() / 20.0f; //approx 20ms D delay, arbitrarily suits many motors
if (!mixerRuntime.feature3dEnabled && mixerRuntime.dynIdleMinRps) {
mixerRuntime.motorOutputLow = DSHOT_MIN_THROTTLE; // Override value set by initEscEndpoints to allow zero motor drive
Expand Down
1 change: 1 addition & 0 deletions src/main/flight/mixer_init.h
Expand Up @@ -39,6 +39,7 @@ typedef struct mixerRuntime_s {
float deadbandMotor3dLow;
#ifdef USE_DYN_IDLE
float dynIdleMaxIncrease;
float dynIdleStartIncrease;
float idleThrottleOffset;
float dynIdleMinRps;
float dynIdlePGain;
Expand Down
3 changes: 2 additions & 1 deletion src/main/flight/pid.c
Expand Up @@ -119,7 +119,7 @@ PG_RESET_TEMPLATE(pidConfig_t, pidConfig,

#define LAUNCH_CONTROL_YAW_ITERM_LIMIT 50 // yaw iterm windup limit when launch mode is "FULL" (all axes)

PG_REGISTER_ARRAY_WITH_RESET_FN(pidProfile_t, PID_PROFILE_COUNT, pidProfiles, PG_PID_PROFILE, 5);
PG_REGISTER_ARRAY_WITH_RESET_FN(pidProfile_t, PID_PROFILE_COUNT, pidProfiles, PG_PID_PROFILE, 6);

void resetPidProfile(pidProfile_t *pidProfile)
{
Expand Down Expand Up @@ -199,6 +199,7 @@ void resetPidProfile(pidProfile_t *pidProfile)
.dyn_idle_i_gain = 50,
.dyn_idle_d_gain = 50,
.dyn_idle_max_increase = 150,
.dyn_idle_start_increase = 50,
.feedforward_averaging = FEEDFORWARD_AVERAGING_OFF,
.feedforward_max_rate_limit = 90,
.feedforward_smooth_factor = 25,
Expand Down
1 change: 1 addition & 0 deletions src/main/flight/pid.h
Expand Up @@ -204,6 +204,7 @@ typedef struct pidProfile_s {
uint8_t dyn_idle_i_gain; // I gain during active control of rpm
uint8_t dyn_idle_d_gain; // D gain for corrections around rapid changes in rpm
uint8_t dyn_idle_max_increase; // limit on maximum possible increase in motor idle drive during active control
uint8_t dyn_idle_start_increase; // limit on maximum possible increase in motor idle drive with airmode not activated

uint8_t feedforward_transition; // Feedforward attenuation around centre sticks
uint8_t feedforward_averaging; // Number of packets to average when averaging is on
Expand Down

0 comments on commit 1c740d9

Please sign in to comment.