Firmware
vtol_type.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2015 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
43 #ifndef VTOL_TYPE_H
44 #define VTOL_TYPE_H
45 
46 #include <lib/mathlib/mathlib.h>
47 #include <drivers/drv_hrt.h>
48 #include <drivers/drv_pwm_output.h>
49 
50 struct Params {
51  int32_t idle_pwm_mc; // pwm value for idle in mc mode
52  int32_t vtol_motor_count; // number of motors
53  int32_t vtol_type;
54  bool elevons_mc_lock; // lock elevons in multicopter mode
55  float fw_min_alt; // minimum relative altitude for FW mode (QuadChute)
56  float fw_alt_err; // maximum negative altitude error for FW mode (Adaptive QuadChute)
57  float fw_qc_max_pitch; // maximum pitch angle FW mode (QuadChute)
58  float fw_qc_max_roll; // maximum roll angle FW mode (QuadChute)
59  float front_trans_time_openloop;
60  float front_trans_time_min;
61  float front_trans_duration;
62  float back_trans_duration;
63  float transition_airspeed;
64  float front_trans_throttle;
65  float back_trans_throttle;
66  float airspeed_blend;
67  bool airspeed_disabled;
68  float front_trans_timeout;
69  float mpc_xy_cruise;
70  int32_t fw_motors_off;
71  int32_t diff_thrust;
72  float diff_thrust_scale;
73  int32_t v19_vt_rolldir;
74 };
75 
76 // Has to match 1:1 msg/vtol_vehicle_status.msg
77 enum mode {
78  TRANSITION_TO_FW = 1,
79  TRANSITION_TO_MC = 2,
80  ROTARY_WING = 3,
81  FIXED_WING = 4
82 };
83 
84 enum vtol_type {
85  TAILSITTER = 0,
86  TILTROTOR,
87  STANDARD
88 };
89 
90 // these are states that can be applied to a selection of multirotor motors.
91 // e.g. if we need to shut off some motors after transitioning to fixed wing mode
92 // we can individually disable them while others might still need to be enabled to produce thrust.
93 // we can select the target motors via VT_FW_MOT_OFFID
94 enum motor_state {
95  ENABLED = 0, // motor max pwm will be set to the standard max pwm value
96  DISABLED, // motor max pwm will be set to a value that shuts the motor off
97  IDLE, // motor max pwm will be set to VT_IDLE_PWM_MC
98  VALUE // motor max pwm will be set to a specific value provided, see set_motor_state()
99 };
100 
105  TYPE_MINIMUM = 0,
106  TYPE_MAXIMUM
107 };
108 
109 class VtolAttitudeControl;
110 
111 class VtolType
112 {
113 public:
114 
115  VtolType(VtolAttitudeControl *att_controller);
116  VtolType(const VtolType &) = delete;
117  VtolType &operator=(const VtolType &) = delete;
118 
119  virtual ~VtolType() = default;
120 
124  bool init();
125 
129  virtual void update_vtol_state() = 0;
130 
134  virtual void update_transition_state() = 0;
135 
139  virtual void update_mc_state();
140 
144  virtual void update_fw_state();
145 
149  virtual void fill_actuator_outputs() = 0;
150 
155  virtual void waiting_on_tecs() {}
156 
160  void check_quadchute_condition();
161 
165  bool can_transition_on_ground();
166 
167 
168 
169  mode get_mode() {return _vtol_mode;}
170 
171  virtual void parameters_update() = 0;
172 
173 protected:
174  VtolAttitudeControl *_attc;
175  mode _vtol_mode;
176 
177  struct vehicle_attitude_s *_v_att; //vehicle attitude
178  struct vehicle_attitude_setpoint_s *_v_att_sp; //vehicle attitude setpoint
179  struct vehicle_attitude_setpoint_s *_mc_virtual_att_sp; // virtual mc attitude setpoint
180  struct vehicle_attitude_setpoint_s *_fw_virtual_att_sp; // virtual fw attitude setpoint
181  struct vehicle_control_mode_s *_v_control_mode; //vehicle control mode
182  struct vtol_vehicle_status_s *_vtol_vehicle_status;
183  struct actuator_controls_s *_actuators_out_0; //actuator controls going to the mc mixer
184  struct actuator_controls_s *_actuators_out_1; //actuator controls going to the fw mixer (used for elevons)
185  struct actuator_controls_s *_actuators_mc_in; //actuator controls from mc_att_control
186  struct actuator_controls_s *_actuators_fw_in; //actuator controls from fw_att_control
187  struct vehicle_local_position_s *_local_pos;
188  struct vehicle_local_position_setpoint_s *_local_pos_sp;
189  struct airspeed_s *_airspeed; // airspeed
190  struct tecs_status_s *_tecs_status;
191  struct vehicle_land_detected_s *_land_detected;
192 
193  struct Params *_params;
194 
195  bool flag_idle_mc = false; //false = "idle is set for fixed wing mode"; true = "idle is set for multicopter mode"
196 
197  bool _pusher_active = false;
198  float _mc_roll_weight = 1.0f; // weight for multicopter attitude controller roll output
199  float _mc_pitch_weight = 1.0f; // weight for multicopter attitude controller pitch output
200  float _mc_yaw_weight = 1.0f; // weight for multicopter attitude controller yaw output
201  float _mc_throttle_weight = 1.0f; // weight for multicopter throttle command. Used to avoid
202 
203  // motors spinning up or cutting too fast when doing transitions.
204  float _thrust_transition = 0.0f; // thrust value applied during a front transition (tailsitter & tiltrotor only)
205 
206  float _ra_hrate = 0.0f; // rolling average on height rate for quadchute condition
207  float _ra_hrate_sp = 0.0f; // rolling average on height rate setpoint for quadchute condition
208 
209  bool _flag_was_in_trans_mode = false; // true if mode has just switched to transition
210 
211  hrt_abstime _trans_finished_ts = 0;
212 
213  bool _tecs_running = false;
214  hrt_abstime _tecs_running_ts = 0;
215 
216  motor_state _motor_state = motor_state::DISABLED;
217 
218 
219 
226  bool set_idle_mc();
227 
234  bool set_idle_fw();
235 
236 
247  motor_state set_motor_state(const motor_state current_state, const motor_state next_state, const int value = 0);
248 
249 private:
250 
251 
255  struct pwm_output_values _min_mc_pwm_values {};
256  struct pwm_output_values _max_mc_pwm_values {};
257  struct pwm_output_values _disarmed_pwm_values {};
258 
267  bool apply_pwm_limits(struct pwm_output_values &pwm_values, pwm_limit_type type);
268 
276  bool is_motor_off_channel(const int channel);
277 
278 };
279 
280 #endif
virtual void waiting_on_tecs()
Special handling opportunity for the time right after transition to FW before TECS is running...
Definition: vtol_type.h:155
High-resolution timer with callouts and timekeeping.
Definition: vtol_type.h:50
Definition: vtol_type.h:111
Definition: drv_pwm_output.h:67
pwm_limit_type
Used to specify if min or max pwm values should be altered.
Definition: vtol_type.h:104
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
Common header for mathlib exports.
Definition: vtol_att_control_main.h:89
int32_t fw_motors_off
bitmask of all motors that should be off in fixed wing mode
Definition: vtol_type.h:70