From 0dd1943d7f3a218044568299bfcde4510c655e31 Mon Sep 17 00:00:00 2001 From: Ivan Efimov Date: Fri, 12 Aug 2022 18:10:45 -0500 Subject: [PATCH] Added extra_motor_output_limit_hundredths --- src/main/cli/settings.c | 1 + src/main/config/config.c | 4 ++++ src/main/flight/mixer_init.c | 4 +++- src/main/flight/pid.c | 1 + src/main/flight/pid.h | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/cli/settings.c b/src/main/cli/settings.c index c3b8bb4ce47..ad35ad5ab59 100644 --- a/src/main/cli/settings.c +++ b/src/main/cli/settings.c @@ -1163,6 +1163,7 @@ const clivalue_t valueTable[] = { #endif { PARAM_NAME_MOTOR_OUTPUT_LIMIT, VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { MOTOR_OUTPUT_LIMIT_PERCENT_MIN, MOTOR_OUTPUT_LIMIT_PERCENT_MAX }, PG_PID_PROFILE, offsetof(pidProfile_t, motor_output_limit) }, + { "extra_motor_output_limit_hundredths", VAR_UINT8 | PROFILE_VALUE, .config.minmaxUnsigned = { 0, 99 }, PG_PID_PROFILE, offsetof(pidProfile_t, extra_motor_output_limit_hundredths) }, { "auto_profile_cell_count", VAR_INT8 | PROFILE_VALUE, .config.minmax = { AUTO_PROFILE_CELL_COUNT_CHANGE, MAX_AUTO_DETECT_CELL_COUNT }, PG_PID_PROFILE, offsetof(pidProfile_t, auto_profile_cell_count) }, #ifdef USE_LAUNCH_CONTROL diff --git a/src/main/config/config.c b/src/main/config/config.c index 871046b3ca4..3d7b9cbbf04 100644 --- a/src/main/config/config.c +++ b/src/main/config/config.c @@ -293,6 +293,10 @@ static void validateAndFixConfig(void) pidProfilesMutable(i)->motor_output_limit = 100; } + if (pidProfilesMutable(i)->extra_motor_output_limit_hundredths >= 100) { + pidProfilesMutable(i)->extra_motor_output_limit_hundredths = 0; + } + if (pidProfilesMutable(i)->auto_profile_cell_count > MAX_AUTO_DETECT_CELL_COUNT || pidProfilesMutable(i)->auto_profile_cell_count < AUTO_PROFILE_CELL_COUNT_CHANGE) { pidProfilesMutable(i)->auto_profile_cell_count = AUTO_PROFILE_CELL_COUNT_STAY; } diff --git a/src/main/flight/mixer_init.c b/src/main/flight/mixer_init.c index 6a93f7bb322..2fd550d22c1 100644 --- a/src/main/flight/mixer_init.c +++ b/src/main/flight/mixer_init.c @@ -43,6 +43,7 @@ #include "sensors/battery.h" #include "mixer_init.h" +#include "common/maths.h" PG_REGISTER_WITH_RESET_TEMPLATE(mixerConfig_t, mixerConfig, PG_MIXER_CONFIG, 0); @@ -286,7 +287,8 @@ void initEscEndpoints(void) { float motorOutputLimit = 1.0f; if (currentPidProfile->motor_output_limit < 100) { - motorOutputLimit = currentPidProfile->motor_output_limit / 100.0f; + motorOutputLimit = currentPidProfile->motor_output_limit / 100.0f + currentPidProfile->extra_motor_output_limit_hundredths / 10000.0f; + motorOutputLimit = constrainf(motorOutputLimit, 0.0f, 1.0f); } motorInitEndpoints(motorConfig(), motorOutputLimit, &mixerRuntime.motorOutputLow, &mixerRuntime.motorOutputHigh, &mixerRuntime.disarmMotorOutput, &mixerRuntime.deadbandMotor3dHigh, &mixerRuntime.deadbandMotor3dLow); } diff --git a/src/main/flight/pid.c b/src/main/flight/pid.c index 6722dab7dfe..654bc836b7b 100644 --- a/src/main/flight/pid.c +++ b/src/main/flight/pid.c @@ -195,6 +195,7 @@ void resetPidProfile(pidProfile_t *pidProfile) .d_min_gain = 37, .d_min_advance = 20, .motor_output_limit = 100, + .extra_motor_output_limit_hundredths = 0, .auto_profile_cell_count = AUTO_PROFILE_CELL_COUNT_STAY, .transient_throttle_limit = 0, .profileName = { 0 }, diff --git a/src/main/flight/pid.h b/src/main/flight/pid.h index a38e698a3a0..0a6bed04329 100644 --- a/src/main/flight/pid.h +++ b/src/main/flight/pid.h @@ -194,6 +194,7 @@ typedef struct pidProfile_s { uint8_t d_min_gain; // Gain factor for amount of gyro / setpoint activity required to boost D uint8_t d_min_advance; // Percentage multiplier for setpoint input to boost algorithm uint8_t motor_output_limit; // Upper limit of the motor output (percent) + uint8_t extra_motor_output_limit_hundredths; int8_t auto_profile_cell_count; // Cell count for this profile to be used with if auto PID profile switching is used uint8_t transient_throttle_limit; // Maximum DC component of throttle change to mix into throttle to prevent airmode mirroring noise char profileName[MAX_PROFILE_NAME_LENGTH + 1]; // Descriptive name for profile