From 46fae47a06acb222ca75229db1c54bc7395ea8cb Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Wed, 5 Oct 2022 01:21:23 +0100 Subject: [PATCH] Plane: Quadplane: SLT: enforce TECS pitch limits to beat race --- ArduPlane/quadplane.cpp | 45 ++++++++++++++++++++++++++++++----------- ArduPlane/transition.h | 2 ++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ArduPlane/quadplane.cpp b/ArduPlane/quadplane.cpp index 0805c74b69..58d4afd6f3 100644 --- a/ArduPlane/quadplane.cpp +++ b/ArduPlane/quadplane.cpp @@ -1529,18 +1529,7 @@ void SLT_Transition::update() transition_start_ms = 0; transition_low_airspeed_ms = 0; } - - if (transition_state < TRANSITION_TIMER) { - // set a single loop pitch limit in TECS - if (plane.ahrs.groundspeed() < 3) { - // until we have some ground speed limit to zero pitch - plane.TECS_controller.set_pitch_max_limit(0); - } else { - plane.TECS_controller.set_pitch_max_limit(quadplane.transition_pitch_max); - } - } else if (transition_state < TRANSITION_DONE) { - plane.TECS_controller.set_pitch_max_limit((quadplane.transition_pitch_max+1)*2); - } + if (transition_state < TRANSITION_DONE) { // during transition we ask TECS to use a synthetic // airspeed. Otherwise the pitch limits will throw off the @@ -4236,6 +4225,38 @@ MAV_VTOL_STATE SLT_Transition::get_mav_vtol_state() const return MAV_VTOL_STATE_UNDEFINED; } +// Set FW roll and pitch limits and keep TECS informed +void SLT_Transition::set_FW_roll_pitch(int32_t& nav_pitch_cd, int32_t& nav_roll_cd, bool& allow_stick_mixing) +{ + if (quadplane.in_vtol_mode() || quadplane.in_vtol_airbrake()) { + // not in FW flight + return; + } + + if (transition_state == TRANSITION_DONE) { + // transition complete, nothing to do + return; + } + + float max_pitch; + if (transition_state < TRANSITION_TIMER) { + if (plane.ahrs.groundspeed() < 3.0) { + // until we have some ground speed limit to zero pitch + max_pitch = 0.0; + } else { + max_pitch = quadplane.transition_pitch_max; + } + } else { + max_pitch = (quadplane.transition_pitch_max+1.0)*2.0; + } + + // set a single loop pitch limit in TECS + plane.TECS_controller.set_pitch_max_limit(max_pitch); + + // ensure pitch is constrained to limit + nav_pitch_cd = constrain_int32(nav_pitch_cd, -max_pitch*100.0, max_pitch*100.0); +} + /* see if we are in a VTOL takeoff */ diff --git a/ArduPlane/transition.h b/ArduPlane/transition.h index bcef57708b..9ddc1d5b5f 100644 --- a/ArduPlane/transition.h +++ b/ArduPlane/transition.h @@ -87,6 +87,8 @@ public: bool show_vtol_view() const override; + void set_FW_roll_pitch(int32_t& nav_pitch_cd, int32_t& nav_roll_cd, bool& allow_stick_mixing) override; + bool set_FW_roll_limit(int32_t& roll_limit_cd) override; bool allow_update_throttle_mix() const override;