Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : 7 : This program is distributed in the hope that it will be useful, 8 : but WITHOUT ANY WARRANTY; without even the implied warranty of 9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 : GNU General Public License for more details. 11 : 12 : You should have received a copy of the GNU General Public License 13 : along with this program. If not, see <http://www.gnu.org/licenses/>. 14 : */ 15 : #pragma once 16 : 17 : #include <AP_Param/AP_Param.h> 18 : #include "transition.h" 19 : #include <AP_Motors/AP_MotorsTailsitter.h> 20 : #include <AP_Logger/LogStructure.h> 21 : 22 : class QuadPlane; 23 : class AP_MotorsMulticopter; 24 : class Tailsitter_Transition; 25 : class Tailsitter 26 : { 27 : friend class QuadPlane; 28 : friend class Plane; 29 : public: 30 : 31 : Tailsitter(QuadPlane& _quadplane, AP_MotorsMulticopter*& _motors); 32 : 33 61718796 : bool enabled() const { return (enable > 0) && setup_complete;} 34 : 35 : void setup(); 36 : 37 : // return true when flying a control surface only tailsitter 38 : bool is_control_surface_tailsitter(void) const; 39 : 40 : // return true when flying a tailsitter in VTOL 41 : bool active(void); 42 : 43 : // create outputs for tailsitters 44 : void output(void); 45 : 46 : // handle different tailsitter input types 47 : void check_input(void); 48 : 49 : // check if we have completed transition to fixed wing 50 : bool transition_fw_complete(void); 51 : 52 : // return true if we are a tailsitter in FW flight 53 : bool is_in_fw_flight(void) const; 54 : 55 : // check if we have completed transition to vtol 56 : bool transition_vtol_complete(void) const; 57 : 58 : // return true if transition to VTOL flight 59 : bool in_vtol_transition(uint32_t now = 0) const; 60 : 61 : // account for control surface speed scaling in VTOL modes 62 : void speed_scaling(void); 63 : 64 : // return the transition_angle_vtol value 65 : int8_t get_transition_angle_vtol() const; 66 : 67 : // return true if pitch control should be relaxed 68 : bool relax_pitch(); 69 : 70 : // Write tailsitter specific log 71 : void write_log(); 72 : 73 : // tailsitter speed scaler 74 : float last_spd_scaler = 1.0f; // used to slew rate limiting with TAILSITTER_GSCL_ATT_THR option 75 : 76 : static const struct AP_Param::GroupInfo var_info[]; 77 : 78 : // bit 0 enables plane mode and bit 1 enables body-frame roll mode 79 : enum input { 80 : TAILSITTER_INPUT_PLANE = (1U<<0), 81 : TAILSITTER_INPUT_BF_ROLL = (1U<<1) 82 : }; 83 : 84 : enum gscl_mask { 85 : TAILSITTER_GSCL_THROTTLE = (1U<<0), 86 : TAILSITTER_GSCL_ATT_THR = (1U<<1), 87 : TAILSITTER_GSCL_DISK_THEORY = (1U<<2), 88 : TAILSITTER_GSCL_ALTITUDE = (1U<<3), 89 : }; 90 : 91 : AP_Int8 enable; 92 : AP_Int8 transition_angle_fw; 93 : AP_Float transition_rate_fw; 94 : AP_Int8 transition_angle_vtol; 95 : AP_Float transition_rate_vtol; 96 : AP_Float transition_throttle_vtol; 97 : AP_Int8 input_type; 98 : AP_Float vectored_forward_gain; 99 : AP_Float vectored_hover_gain; 100 : AP_Float vectored_hover_power; 101 : AP_Float throttle_scale_max; 102 : AP_Float gain_scaling_min; 103 : AP_Float max_roll_angle; 104 : AP_Int16 motor_mask; 105 : AP_Float scaling_speed_min; 106 : AP_Float scaling_speed_max; 107 : AP_Int16 gain_scaling_mask; 108 : AP_Float disk_loading; 109 : AP_Float VTOL_roll_scale; 110 : AP_Float VTOL_pitch_scale; 111 : AP_Float VTOL_yaw_scale; 112 : AP_Float disk_loading_min_outflow; 113 : 114 : AP_MotorsTailsitter* tailsitter_motors; 115 : 116 : private: 117 : 118 : // Tailsitter specific log message 119 : struct PACKED log_tailsitter { 120 : LOG_PACKET_HEADER; 121 : uint64_t time_us; 122 : float throttle_scaler; 123 : float speed_scaler; 124 : float min_throttle; 125 : }; 126 : 127 : // Data to be logged 128 : struct { 129 : float throttle_scaler; 130 : float speed_scaler; 131 : float min_throttle; 132 : } log_data; 133 : 134 : 135 : bool setup_complete; 136 : 137 : // true when flying a tilt-vectored tailsitter 138 : bool _is_vectored; 139 : 140 : // true is outputs are configured 141 : bool _have_elevator; 142 : bool _have_aileron; 143 : bool _have_rudder; 144 : bool _have_elevon; 145 : bool _have_v_tail; 146 : 147 : // references for convenience 148 : QuadPlane& quadplane; 149 : AP_MotorsMulticopter*& motors; 150 : 151 : // transition logic 152 : Tailsitter_Transition* transition; 153 : 154 : }; 155 : 156 : 157 : // Transition for tailsitters 158 : class Tailsitter_Transition : public Transition 159 : { 160 : friend class Tailsitter; 161 : public: 162 : 163 6 : Tailsitter_Transition(QuadPlane& _quadplane, AP_MotorsMulticopter*& _motors, Tailsitter& _tailsitter):Transition(_quadplane, _motors), tailsitter(_tailsitter) {}; 164 : 165 : void update() override; 166 : 167 : void VTOL_update() override; 168 : 169 : void force_transition_complete() override; 170 : 171 2970 : bool complete() const override { return transition_state == State::DONE; } 172 : 173 : // setup for the transition back to fixed wing 174 : void restart() override; 175 : 176 6169 : uint8_t get_log_transition_state() const override { return static_cast<uint8_t>(transition_state); } 177 : 178 452515 : bool active_frwd() const override { return transition_state == State::ANGLE_WAIT_FW; } 179 : 180 : bool show_vtol_view() const override; 181 : 182 : void set_FW_roll_pitch(int32_t& nav_pitch_cd, int32_t& nav_roll_cd) override; 183 : 184 : bool allow_stick_mixing() const override; 185 : 186 : MAV_VTOL_STATE get_mav_vtol_state() const override; 187 : 188 : bool set_VTOL_roll_pitch_limit(int32_t& nav_roll_cd, int32_t& nav_pitch_cd) override; 189 : 190 : bool allow_weathervane() override; 191 : 192 : private: 193 : 194 : enum class State { 195 : ANGLE_WAIT_FW = 0, 196 : ANGLE_WAIT_VTOL = 1, 197 : DONE = 2, 198 : } transition_state; 199 : 200 : // for transition to VTOL flight 201 : uint32_t vtol_transition_start_ms; 202 : float vtol_transition_initial_pitch; 203 : 204 : // for rate limit of VTOL flight 205 : uint32_t vtol_limit_start_ms; 206 : float vtol_limit_initial_pitch; 207 : 208 : // for rate limit of FW flight 209 : uint32_t fw_limit_start_ms; 210 : float fw_limit_initial_pitch; 211 : 212 : // for transition to FW flight 213 : uint32_t fw_transition_start_ms; 214 : float fw_transition_initial_pitch; 215 : 216 : // time when we were last in a vtol control mode 217 : uint32_t last_vtol_mode_ms; 218 : 219 : Tailsitter& tailsitter; 220 : 221 : };