2018-11-09 18:38:43 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
reverse thrust support functions
|
|
|
|
*/
|
|
|
|
#include "Plane.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
see if reverse thrust should be allowed in the current flight state
|
|
|
|
*/
|
|
|
|
bool Plane::allow_reverse_thrust(void) const
|
|
|
|
{
|
|
|
|
// check if we should allow reverse thrust
|
|
|
|
bool allow = false;
|
|
|
|
|
|
|
|
if (g.use_reverse_thrust == USE_REVERSE_THRUST_NEVER || !have_reverse_thrust()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
switch (control_mode->mode_number()) {
|
|
|
|
case Mode::Number::AUTO:
|
2018-11-09 18:38:43 -04:00
|
|
|
{
|
|
|
|
uint16_t nav_cmd = mission.get_current_nav_cmd().id;
|
|
|
|
|
|
|
|
// never allow reverse thrust during takeoff
|
|
|
|
if (nav_cmd == MAV_CMD_NAV_TAKEOFF) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// always allow regardless of mission item
|
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_AUTO_ALWAYS);
|
|
|
|
|
|
|
|
// landing
|
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_AUTO_LAND_APPROACH) &&
|
|
|
|
(nav_cmd == MAV_CMD_NAV_LAND);
|
|
|
|
|
|
|
|
// LOITER_TO_ALT
|
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_AUTO_LOITER_TO_ALT) &&
|
|
|
|
(nav_cmd == MAV_CMD_NAV_LOITER_TO_ALT);
|
|
|
|
|
|
|
|
// any Loiter (including LOITER_TO_ALT)
|
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_AUTO_LOITER_ALL) &&
|
|
|
|
(nav_cmd == MAV_CMD_NAV_LOITER_TIME ||
|
|
|
|
nav_cmd == MAV_CMD_NAV_LOITER_TO_ALT ||
|
|
|
|
nav_cmd == MAV_CMD_NAV_LOITER_TURNS ||
|
|
|
|
nav_cmd == MAV_CMD_NAV_LOITER_UNLIM);
|
|
|
|
|
|
|
|
// waypoints
|
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_AUTO_WAYPOINT) &&
|
|
|
|
(nav_cmd == MAV_CMD_NAV_WAYPOINT ||
|
|
|
|
nav_cmd == MAV_CMD_NAV_SPLINE_WAYPOINT);
|
2020-09-14 23:27:08 -03:00
|
|
|
|
|
|
|
// we are on a landing pattern
|
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_AUTO_LANDING_PATTERN) &&
|
|
|
|
mission.get_in_landing_sequence_flag();
|
2018-11-09 18:38:43 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::LOITER:
|
2018-11-09 18:38:43 -04:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_LOITER);
|
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::RTL:
|
2018-11-09 18:38:43 -04:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_RTL);
|
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::CIRCLE:
|
2018-11-09 18:38:43 -04:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_CIRCLE);
|
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::CRUISE:
|
2018-11-09 18:38:43 -04:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_CRUISE);
|
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::FLY_BY_WIRE_B:
|
2018-11-09 18:38:43 -04:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_FBWB);
|
|
|
|
break;
|
2019-01-15 13:46:13 -04:00
|
|
|
case Mode::Number::AVOID_ADSB:
|
|
|
|
case Mode::Number::GUIDED:
|
2018-11-09 18:38:43 -04:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_GUIDED);
|
|
|
|
break;
|
2019-05-06 01:39:14 -03:00
|
|
|
case Mode::Number::TAKEOFF:
|
|
|
|
allow = false;
|
|
|
|
break;
|
2022-03-04 05:43:50 -04:00
|
|
|
case Mode::Number::FLY_BY_WIRE_A:
|
2021-05-25 14:49:38 -03:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_FBWA);
|
|
|
|
break;
|
2022-03-04 05:43:50 -04:00
|
|
|
case Mode::Number::ACRO:
|
2021-05-25 14:49:38 -03:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_ACRO);
|
|
|
|
break;
|
2022-03-04 05:43:50 -04:00
|
|
|
case Mode::Number::STABILIZE:
|
2021-05-25 14:49:38 -03:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_STABILIZE);
|
|
|
|
break;
|
2022-03-04 05:43:50 -04:00
|
|
|
case Mode::Number::THERMAL:
|
2021-05-25 14:49:38 -03:00
|
|
|
allow |= (g.use_reverse_thrust & USE_REVERSE_THRUST_THERMAL);
|
|
|
|
break;
|
2018-11-09 18:38:43 -04:00
|
|
|
default:
|
2021-05-25 14:49:38 -03:00
|
|
|
// all other control_modes allow independent of mask(MANUAL)
|
2018-11-09 18:38:43 -04:00
|
|
|
allow = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:39:14 -03:00
|
|
|
// cope with bitwise ops above
|
|
|
|
return allow != false;
|
2018-11-09 18:38:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
return true if we are configured to support reverse thrust
|
|
|
|
*/
|
|
|
|
bool Plane::have_reverse_thrust(void) const
|
|
|
|
{
|
|
|
|
return aparm.throttle_min < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
return control in from the radio throttle channel.
|
|
|
|
*/
|
2021-09-18 15:03:54 -03:00
|
|
|
float Plane::get_throttle_input(bool no_deadzone) const
|
2018-11-09 18:38:43 -04:00
|
|
|
{
|
2021-09-18 15:03:54 -03:00
|
|
|
float ret;
|
2018-11-09 18:38:43 -04:00
|
|
|
if (no_deadzone) {
|
2018-11-09 19:00:20 -04:00
|
|
|
ret = channel_throttle->get_control_in_zero_dz();
|
|
|
|
} else {
|
|
|
|
ret = channel_throttle->get_control_in();
|
2018-11-09 18:38:43 -04:00
|
|
|
}
|
2018-11-09 19:00:20 -04:00
|
|
|
if (reversed_throttle) {
|
|
|
|
// RC option for reverse throttle has been set
|
|
|
|
ret = -ret;
|
|
|
|
}
|
|
|
|
return ret;
|
2018-11-09 18:38:43 -04:00
|
|
|
}
|
2021-08-30 15:57:10 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
return control in from the radio throttle channel with curve giving mid-stick equal to TRIM_THROTTLE.
|
|
|
|
*/
|
2021-09-18 15:03:54 -03:00
|
|
|
float Plane::get_adjusted_throttle_input(bool no_deadzone) const
|
2021-08-30 15:57:10 -03:00
|
|
|
{
|
2022-02-25 02:01:06 -04:00
|
|
|
if ((plane.channel_throttle->get_type() != RC_Channel::ControlType::RANGE) ||
|
|
|
|
(g2.flight_options & FlightOptions::CENTER_THROTTLE_TRIM) == 0) {
|
2021-08-30 15:57:10 -03:00
|
|
|
return get_throttle_input(no_deadzone);
|
|
|
|
}
|
2021-09-18 15:03:54 -03:00
|
|
|
float ret = channel_throttle->get_range() * throttle_curve(aparm.throttle_cruise * 0.01, 0, 0.5 + 0.5*channel_throttle->norm_input());
|
2021-08-30 15:57:10 -03:00
|
|
|
if (reversed_throttle) {
|
|
|
|
// RC option for reverse throttle has been set
|
|
|
|
return -ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|