Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,16 @@ Reference airspeed. Set this to airspeed at which PIDs were tuned. Usually shoul

---

### fw_throttle_rate_limiter

Limits throttle output rate of change. Setting defines minimum time in milliseconds for throttle to change by 1000us (min to max throttle range). Set to 0 to disable. Fixed wing only.

| Default | Min | Max |
| --- | --- | --- |
| 0 | 0 | 5000 |

---

### fw_tpa_time_constant

TPA smoothing and delay time constant to reflect non-instant speed/throttle response of the plane. See **PID Attenuation and scaling** Wiki for full details.
Expand Down
4 changes: 2 additions & 2 deletions src/main/fc/fc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ void taskMainPidLoop(timeUs_t currentTimeUs)
{

cycleTime = getTaskDeltaTime(TASK_SELF);
dT = (float)cycleTime * 0.000001f;
dT = US2S(cycleTime);

bool fwLaunchIsActive = STATE(AIRPLANE) && isNavLaunchEnabled() && armTime == 0;

Expand Down Expand Up @@ -992,7 +992,7 @@ void taskMainPidLoop(timeUs_t currentTimeUs)
// Calculate stabilisation
pidController(dT);

mixTable();
mixTable(dT);

if (isMixerUsingServos()) {
servoMixer(dT);
Expand Down
6 changes: 6 additions & 0 deletions src/main/fc/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,12 @@ groups:
field: nav.fw.launch_idle_throttle
min: 1000
max: 2000
- name: fw_throttle_rate_limiter
description: "Limits throttle output rate of change. Setting defines minimum time in milliseconds for throttle to change by 1000us (min to max throttle range). Set to 0 to disable. Fixed wing only."
default_value: 0
field: motor.throttle_rate_limiter
min: 0
max: 5000
- name: limit_cont_current
description: "Continous current limit (dA), set to 0 to disable"
condition: USE_POWER_LIMITS
Expand Down
21 changes: 20 additions & 1 deletion src/main/flight/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static EXTENDED_FASTRAM int throttleDeadbandHigh = 0;
static EXTENDED_FASTRAM int throttleRangeMin = 0;
static EXTENDED_FASTRAM int throttleRangeMax = 0;
static EXTENDED_FASTRAM int8_t motorYawMultiplier = 1;
static EXTENDED_FASTRAM float throttleRateLimit = 0.0f;

int motorZeroCommand = 0;

Expand Down Expand Up @@ -235,6 +236,10 @@ void mixerInit(void)
} else {
motorYawMultiplier = 1;
}

if (currentBatteryProfile->motor.throttle_rate_limiter > 0) {
throttleRateLimit = (PWM_RANGE_MAX - PWM_RANGE_MIN) / MS2S(currentBatteryProfile->motor.throttle_rate_limiter);
}
}

void mixerResetDisarmedMotors(void)
Expand Down Expand Up @@ -486,8 +491,10 @@ static int getReversibleMotorsThrottleDeadband(void)
return ifMotorstopFeatureEnabled() ? reversibleMotorsConfig()->neutral : directionValue;
}

void FAST_CODE mixTable(void)
void FAST_CODE mixTable(float dT)
{
static float lastMixerThrottleCommand = 1000.0f;

#ifdef USE_DSHOT
if (FLIGHT_MODE(TURTLE_MODE)) {
applyTurtleModeToMotors();
Expand All @@ -505,6 +512,7 @@ void FAST_CODE mixTable(void)
motor[i] = isDisarmed ? motor_disarmed[i] : motorValueWhenStopped;
}
mixerThrottleCommand = motor[0];
lastMixerThrottleCommand = mixerThrottleCommand;
return;
}

Expand Down Expand Up @@ -607,6 +615,17 @@ void FAST_CODE mixTable(void)
throttleMax = throttleRangeMax;
throttleRange = throttleMax - throttleMin;

// FW throttle rate limiter
if (STATE(AIRPLANE) && throttleRateLimit) {
const float deltaThrottle = mixerThrottleCommand - lastMixerThrottleCommand;
const float throttleRate = deltaThrottle / dT;

if (fabsf(throttleRate) > throttleRateLimit) {
lastMixerThrottleCommand = lastMixerThrottleCommand + SIGN(throttleRate) * throttleRateLimit * dT;
mixerThrottleCommand = lastMixerThrottleCommand;
}
}

#define THROTTLE_CLIPPING_FACTOR 0.33f
motorMixRange = (float)rpyMixRange / (float)throttleRange;
if (motorMixRange > 1.0f) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/flight/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void writeAllMotors(int16_t mc);
void mixerInit(void);
void mixerUpdateStateFlags(void);
void mixerResetDisarmedMotors(void);
void mixTable(void);
void mixTable(float dT);
void writeMotors(void);
void processServoAutotrim(const float dT);
void processServoAutotrimMode(void);
Expand Down
3 changes: 2 additions & 1 deletion src/main/sensors/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static pt1Filter_t amperageFilterState;
batteryState_e batteryState;
const batteryProfile_t *currentBatteryProfile;

PG_REGISTER_ARRAY_WITH_RESET_FN(batteryProfile_t, MAX_BATTERY_PROFILE_COUNT, batteryProfiles, PG_BATTERY_PROFILES, 3);
PG_REGISTER_ARRAY_WITH_RESET_FN(batteryProfile_t, MAX_BATTERY_PROFILE_COUNT, batteryProfiles, PG_BATTERY_PROFILES, 4);

void pgResetFn_batteryProfiles(batteryProfile_t *instance)
{
Expand Down Expand Up @@ -136,6 +136,7 @@ void pgResetFn_batteryProfiles(batteryProfile_t *instance)
.motor = {
.throttleIdle = SETTING_THROTTLE_IDLE_DEFAULT,
.throttleScale = SETTING_THROTTLE_SCALE_DEFAULT,
.throttle_rate_limiter = SETTING_FW_THROTTLE_RATE_LIMITER_DEFAULT, // 100 millis
#ifdef USE_DSHOT
.turtleModePowerFactor = SETTING_TURTLE_MODE_POWER_FACTOR_DEFAULT,
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/main/sensors/battery_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ typedef struct batteryProfile_s {
struct {
float throttleIdle; // Throttle IDLE value based on min_command, max_throttle, in percent
float throttleScale; // Scaling factor for throttle.
uint16_t throttle_rate_limiter; // Min time in millis for fixed wing throttle to go from min to max
#ifdef USE_DSHOT
uint8_t turtleModePowerFactor; // Power factor from 0 to 100% of flip over after crash
#endif
} motor;

uint16_t failsafe_throttle; // Throttle level used for landing - specify value between 1000..2000 (pwm pulse width for slightly below hover). center throttle = 1500.
uint16_t failsafe_throttle; // Throttle level used for landing - slightly below hover for MC, probably motor off for FW.

struct {

Expand Down
Loading