mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Merge pull request #6402 from ianrmurphy/3.4.0-rate-limit
CLI configurable limits for rates
This commit is contained in:
commit
ad16f2db0f
6 changed files with 22 additions and 5 deletions
|
@ -1254,6 +1254,9 @@ static bool blackboxWriteSysinfo(void)
|
||||||
BLACKBOX_PRINT_HEADER_LINE("rates", "%d,%d,%d", currentControlRateProfile->rates[ROLL],
|
BLACKBOX_PRINT_HEADER_LINE("rates", "%d,%d,%d", currentControlRateProfile->rates[ROLL],
|
||||||
currentControlRateProfile->rates[PITCH],
|
currentControlRateProfile->rates[PITCH],
|
||||||
currentControlRateProfile->rates[YAW]);
|
currentControlRateProfile->rates[YAW]);
|
||||||
|
BLACKBOX_PRINT_HEADER_LINE("rate_limits", "%d,%d,%d", currentControlRateProfile->rate_limit[ROLL],
|
||||||
|
currentControlRateProfile->rate_limit[PITCH],
|
||||||
|
currentControlRateProfile->rate_limit[YAW]);
|
||||||
BLACKBOX_PRINT_HEADER_LINE("rollPID", "%d,%d,%d", currentPidProfile->pid[PID_ROLL].P,
|
BLACKBOX_PRINT_HEADER_LINE("rollPID", "%d,%d,%d", currentPidProfile->pid[PID_ROLL].P,
|
||||||
currentPidProfile->pid[PID_ROLL].I,
|
currentPidProfile->pid[PID_ROLL].I,
|
||||||
currentPidProfile->pid[PID_ROLL].D);
|
currentPidProfile->pid[PID_ROLL].D);
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include "fc/config.h"
|
#include "fc/config.h"
|
||||||
#include "fc/controlrate_profile.h"
|
#include "fc/controlrate_profile.h"
|
||||||
#include "fc/rc.h"
|
#include "fc/rc.h"
|
||||||
|
#include "fc/rc_controls.h"
|
||||||
|
|
||||||
controlRateConfig_t *currentControlRateProfile;
|
controlRateConfig_t *currentControlRateProfile;
|
||||||
|
|
||||||
|
@ -57,7 +58,10 @@ void pgResetFn_controlRateProfiles(controlRateConfig_t *controlRateConfig)
|
||||||
.rates[FD_PITCH] = 70,
|
.rates[FD_PITCH] = 70,
|
||||||
.rates[FD_YAW] = 70,
|
.rates[FD_YAW] = 70,
|
||||||
.throttle_limit_type = THROTTLE_LIMIT_TYPE_OFF,
|
.throttle_limit_type = THROTTLE_LIMIT_TYPE_OFF,
|
||||||
.throttle_limit_percent = 100
|
.throttle_limit_percent = 100,
|
||||||
|
.rate_limit[FD_ROLL] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX,
|
||||||
|
.rate_limit[FD_PITCH] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX,
|
||||||
|
.rate_limit[FD_YAW] = CONTROL_RATE_CONFIG_RATE_LIMIT_MAX
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ typedef struct controlRateConfig_s {
|
||||||
uint16_t tpa_breakpoint; // Breakpoint where TPA is activated
|
uint16_t tpa_breakpoint; // Breakpoint where TPA is activated
|
||||||
uint8_t throttle_limit_type; // Sets the throttle limiting type - off, scale or clip
|
uint8_t throttle_limit_type; // Sets the throttle limiting type - off, scale or clip
|
||||||
uint8_t throttle_limit_percent; // Sets the maximum pilot commanded throttle limit
|
uint8_t throttle_limit_percent; // Sets the maximum pilot commanded throttle limit
|
||||||
|
uint16_t rate_limit[3]; // Sets the maximum rate for the axes
|
||||||
} controlRateConfig_t;
|
} controlRateConfig_t;
|
||||||
|
|
||||||
PG_DECLARE_ARRAY(controlRateConfig_t, CONTROL_RATE_PROFILE_COUNT, controlRateProfiles);
|
PG_DECLARE_ARRAY(controlRateConfig_t, CONTROL_RATE_PROFILE_COUNT, controlRateProfiles);
|
||||||
|
|
|
@ -111,7 +111,9 @@ static int16_t rcLookupThrottle(int32_t tmp)
|
||||||
return lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100;
|
return lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SETPOINT_RATE_LIMIT 1998.0f
|
#define SETPOINT_RATE_LIMIT 1998
|
||||||
|
STATIC_ASSERT(CONTROL_RATE_CONFIG_RATE_LIMIT_MAX <= SETPOINT_RATE_LIMIT, CONTROL_RATE_CONFIG_RATE_LIMIT_MAX_too_large);
|
||||||
|
|
||||||
#define RC_RATE_INCREMENTAL 14.54f
|
#define RC_RATE_INCREMENTAL 14.54f
|
||||||
|
|
||||||
float applyBetaflightRates(const int axis, float rcCommandf, const float rcCommandfAbs)
|
float applyBetaflightRates(const int axis, float rcCommandf, const float rcCommandfAbs)
|
||||||
|
@ -169,7 +171,8 @@ static void calculateSetpointRate(int axis)
|
||||||
|
|
||||||
angleRate = applyRates(axis, rcCommandf, rcCommandfAbs);
|
angleRate = applyRates(axis, rcCommandf, rcCommandfAbs);
|
||||||
}
|
}
|
||||||
setpointRate[axis] = constrainf(angleRate, -SETPOINT_RATE_LIMIT, SETPOINT_RATE_LIMIT); // Rate limit protection (deg/sec)
|
// Rate limit from profile (deg/sec)
|
||||||
|
setpointRate[axis] = constrainf(angleRate, -1.0f * currentControlRateProfile->rate_limit[axis], 1.0f * currentControlRateProfile->rate_limit[axis]);
|
||||||
|
|
||||||
DEBUG_SET(DEBUG_ANGLERATE, axis, angleRate);
|
DEBUG_SET(DEBUG_ANGLERATE, axis, angleRate);
|
||||||
}
|
}
|
||||||
|
@ -189,8 +192,8 @@ static void scaleRcCommandToFpvCamAngle(void)
|
||||||
|
|
||||||
float roll = setpointRate[ROLL];
|
float roll = setpointRate[ROLL];
|
||||||
float yaw = setpointRate[YAW];
|
float yaw = setpointRate[YAW];
|
||||||
setpointRate[ROLL] = constrainf(roll * cosFactor - yaw * sinFactor, -SETPOINT_RATE_LIMIT, SETPOINT_RATE_LIMIT);
|
setpointRate[ROLL] = constrainf(roll * cosFactor - yaw * sinFactor, -SETPOINT_RATE_LIMIT * 1.0f, SETPOINT_RATE_LIMIT * 1.0f);
|
||||||
setpointRate[YAW] = constrainf(yaw * cosFactor + roll * sinFactor, -SETPOINT_RATE_LIMIT, SETPOINT_RATE_LIMIT);
|
setpointRate[YAW] = constrainf(yaw * cosFactor + roll * sinFactor, -SETPOINT_RATE_LIMIT * 1.0f, SETPOINT_RATE_LIMIT * 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define THROTTLE_BUFFER_MAX 20
|
#define THROTTLE_BUFFER_MAX 20
|
||||||
|
|
|
@ -100,6 +100,9 @@ typedef enum {
|
||||||
|
|
||||||
#define CONTROL_RATE_CONFIG_RC_RATES_MAX 255
|
#define CONTROL_RATE_CONFIG_RC_RATES_MAX 255
|
||||||
|
|
||||||
|
#define CONTROL_RATE_CONFIG_RATE_LIMIT_MIN 200
|
||||||
|
#define CONTROL_RATE_CONFIG_RATE_LIMIT_MAX 1998
|
||||||
|
|
||||||
// (Super) rates are constrained to [0, 100] for Betaflight rates, so values higher than 100 won't make a difference. Range extended for RaceFlight rates.
|
// (Super) rates are constrained to [0, 100] for Betaflight rates, so values higher than 100 won't make a difference. Range extended for RaceFlight rates.
|
||||||
#define CONTROL_RATE_CONFIG_RATE_MAX 255
|
#define CONTROL_RATE_CONFIG_RATE_MAX 255
|
||||||
|
|
||||||
|
|
|
@ -749,6 +749,9 @@ const clivalue_t valueTable[] = {
|
||||||
{ "tpa_breakpoint", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, tpa_breakpoint) },
|
{ "tpa_breakpoint", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { PWM_PULSE_MIN, PWM_PULSE_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, tpa_breakpoint) },
|
||||||
{ "throttle_limit_type", VAR_UINT8 | PROFILE_RATE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_THROTTLE_LIMIT_TYPE }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, throttle_limit_type) },
|
{ "throttle_limit_type", VAR_UINT8 | PROFILE_RATE_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_THROTTLE_LIMIT_TYPE }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, throttle_limit_type) },
|
||||||
{ "throttle_limit_percent", VAR_UINT8 | PROFILE_RATE_VALUE, .config.minmax = { 25, 100 }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, throttle_limit_percent) },
|
{ "throttle_limit_percent", VAR_UINT8 | PROFILE_RATE_VALUE, .config.minmax = { 25, 100 }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, throttle_limit_percent) },
|
||||||
|
{ "roll_rate_limit", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { CONTROL_RATE_CONFIG_RATE_LIMIT_MIN, CONTROL_RATE_CONFIG_RATE_LIMIT_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, rate_limit[FD_ROLL]) },
|
||||||
|
{ "pitch_rate_limit", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { CONTROL_RATE_CONFIG_RATE_LIMIT_MIN, CONTROL_RATE_CONFIG_RATE_LIMIT_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, rate_limit[FD_PITCH]) },
|
||||||
|
{ "yaw_rate_limit", VAR_UINT16 | PROFILE_RATE_VALUE, .config.minmax = { CONTROL_RATE_CONFIG_RATE_LIMIT_MIN, CONTROL_RATE_CONFIG_RATE_LIMIT_MAX }, PG_CONTROL_RATE_PROFILES, offsetof(controlRateConfig_t, rate_limit[FD_YAW]) },
|
||||||
|
|
||||||
// PG_SERIAL_CONFIG
|
// PG_SERIAL_CONFIG
|
||||||
{ "reboot_character", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 48, 126 }, PG_SERIAL_CONFIG, offsetof(serialConfig_t, reboot_character) },
|
{ "reboot_character", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 48, 126 }, PG_SERIAL_CONFIG, offsetof(serialConfig_t, reboot_character) },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue