Skip to content

Commit 549e40a

Browse files
committed
Plane: add comment on speed scalar calculation
it needs to be a constant so that when the user changes TRIM_THROTTLE (eg. via DO_CHANGE_SPEED or via the parameter) that it doesn't change the tuning of their PID loops by changing the speed scaler. The aircraft could either start oscillating badly or could become very sluggish in control
1 parent 8d3c52c commit 549e40a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

ArduPlane/Attitude.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ float Plane::calc_speed_scaler(void)
4242
} else if (arming.is_armed_and_safety_off()) {
4343
// scale assumed surface movement using throttle output
4444
float throttle_out = MAX(SRV_Channels::get_output_scaled(SRV_Channel::k_throttle), 1);
45-
speed_scaler = sqrtf(THROTTLE_CRUISE / throttle_out);
45+
// we use a fixed value here as changing the trim throttle
46+
// value is often done at runtime - and changing that
47+
// shouldn't change the speed scaler here (it will change the
48+
// effective PID values)
49+
speed_scaler = sqrtf(AP_PLANE_TRIM_THROTTLE_DEFAULT / throttle_out);
4650
// This case is constrained tighter as we don't have real speed info
4751
speed_scaler = constrain_float(speed_scaler, 0.6f, 1.67f);
4852
} else {

ArduPlane/Parameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ const AP_Param::Info Plane::var_info[] = {
426426
// @Range: 0 100
427427
// @Increment: 1
428428
// @User: Standard
429-
ASCALAR(throttle_cruise, "TRIM_THROTTLE", THROTTLE_CRUISE),
429+
ASCALAR(throttle_cruise, "TRIM_THROTTLE", AP_PLANE_TRIM_THROTTLE_DEFAULT),
430430

431431
// @Param: THROTTLE_NUDGE
432432
// @DisplayName: Throttle nudge enable

ArduPlane/config.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@
138138
#ifndef THROTTLE_MIN
139139
# define THROTTLE_MIN 0 // percent
140140
#endif
141-
#ifndef THROTTLE_CRUISE
142-
# define THROTTLE_CRUISE 45
141+
#ifdef THROTTLE_CRUISE
142+
#error THROTTLE_CRUISE was renamed to AP_PLANE_TRIM_THROTTLE_DEFAULT
143+
#endif
144+
#ifndef AP_PLANE_TRIM_THROTTLE_DEFAULT
145+
# define AP_PLANE_TRIM_THROTTLE_DEFAULT 45
143146
#endif
144147
#ifndef THROTTLE_MAX
145148
# define THROTTLE_MAX 100

0 commit comments

Comments
 (0)