Plane: Allow center throttle to be trim airspeed in cruise

This commit is contained in:
Michael du Breuil 2018-09-01 17:01:32 -07:00 committed by Andrew Tridgell
parent 20c56f3e06
commit f150cae75a
3 changed files with 29 additions and 6 deletions

View File

@ -1173,7 +1173,7 @@ const AP_Param::GroupInfo ParametersG2::var_info[] = {
// @Param: FLIGHT_OPTIONS
// @DisplayName: Flight mode options
// @Description: Flight mode specific options
// @Bitmask: 0:Rudder mixing in direct flight modes only (Manual, Stabilize, Acro)
// @Bitmask: 0:Rudder mixing in direct flight modes only (Manual, Stabilize, Acro),1:Use centered throttle in Cruise or FBWB to indicate trim airspeed
// @User: Advanced
AP_GROUPINFO("FLIGHT_OPTIONS", 13, ParametersG2, flight_options, 0),

View File

@ -199,5 +199,6 @@ enum {
};
enum FlightOptions {
DIRECT_RUDDER_ONLY = (1 << 0),
DIRECT_RUDDER_ONLY = (1 << 0),
CRUISE_TRIM_THROTTLE = (1 << 1),
};

View File

@ -109,10 +109,32 @@ void Plane::calc_airspeed_errors()
// FBW_B/cruise airspeed target
if (!failsafe.rc_failsafe && (control_mode == FLY_BY_WIRE_B || control_mode == CRUISE)) {
target_airspeed_cm = ((int32_t)(aparm.airspeed_max -
aparm.airspeed_min) *
channel_throttle->get_control_in()) +
((int32_t)aparm.airspeed_min * 100);
if (g2.flight_options & FlightOptions::CRUISE_TRIM_THROTTLE) {
float control_min = 0.0f;
float control_mid = 0.0f;
const float control_max = channel_throttle->get_range();
const float control_in = channel_throttle->get_control_in();
switch (channel_throttle->get_type()) {
case RC_Channel::RC_CHANNEL_TYPE_ANGLE:
control_min = -control_max;
break;
case RC_Channel::RC_CHANNEL_TYPE_RANGE:
control_mid = channel_throttle->get_control_mid();
break;
}
if (control_in <= control_mid) {
target_airspeed_cm = linear_interpolate(aparm.airspeed_min * 100, aparm.airspeed_cruise_cm,
control_in,
control_min, control_mid);
} else {
target_airspeed_cm = linear_interpolate(aparm.airspeed_cruise_cm, aparm.airspeed_max * 100,
control_in,
control_mid, control_max);
}
} else {
target_airspeed_cm = ((int32_t)(aparm.airspeed_max - aparm.airspeed_min) *
channel_throttle->get_control_in()) + ((int32_t)aparm.airspeed_min * 100);
}
} else if (flight_stage == AP_Vehicle::FixedWing::FLIGHT_LAND) {
// Landing airspeed target