PX4 Firmware
PX4 Autopilot Software http://px4.io
RunwayTakeoff.cpp
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 /**
34  * @file RunwayTakeoff.cpp
35  * Runway takeoff handling for fixed-wing UAVs with steerable wheels.
36  *
37  * @author Roman Bapst <roman@px4.io>
38  * @author Andreas Antener <andreas@uaventure.com>
39  */
40 
41 #include <stdbool.h>
42 #include <stdint.h>
43 #include <math.h>
44 
45 #include "RunwayTakeoff.h"
46 #include <systemlib/mavlink_log.h>
47 #include <mathlib/mathlib.h>
48 
49 using matrix::Vector2f;
50 
51 namespace runwaytakeoff
52 {
53 
54 RunwayTakeoff::RunwayTakeoff(ModuleParams *parent) :
55  ModuleParams(parent),
56  _state(),
57  _initialized(false),
58  _initialized_time(0),
59  _init_yaw(0),
60  _climbout(false)
61 {
62 }
63 
64 void RunwayTakeoff::init(float yaw, double current_lat, double current_lon)
65 {
66  _init_yaw = yaw;
67  _initialized = true;
70  _climbout = true; // this is true until climbout is finished
71  _start_wp(0) = (float)current_lat;
72  _start_wp(1) = (float)current_lon;
73 }
74 
75 void RunwayTakeoff::update(float airspeed, float alt_agl,
76  double current_lat, double current_lon, orb_advert_t *mavlink_log_pub)
77 {
78 
79  switch (_state) {
81  if (hrt_elapsed_time(&_initialized_time) > _param_rwto_ramp_time.get() * 1e6f) {
83  }
84 
85  break;
86 
88  if (airspeed > _param_fw_airspd_min.get() * _param_rwto_airspd_scl.get()) {
90  mavlink_log_info(mavlink_log_pub, "#Takeoff airspeed reached");
91  }
92 
93  break;
94 
96  if (alt_agl > _param_rwto_nav_alt.get()) {
98 
99  /*
100  * If we started in heading hold mode, move the navigation start WP to the current location now.
101  * The navigator will take this as starting point to navigate towards the takeoff WP.
102  */
103  if (_param_rwto_hdg.get() == 0) {
104  _start_wp(0) = (float)current_lat;
105  _start_wp(1) = (float)current_lon;
106  }
107 
108  mavlink_log_info(mavlink_log_pub, "#Climbout");
109  }
110 
111  break;
112 
114  if (alt_agl > _param_fw_clmbout_diff.get()) {
115  _climbout = false;
117  mavlink_log_info(mavlink_log_pub, "#Navigating to waypoint");
118  }
119 
120  break;
121 
122  default:
123  break;
124  }
125 }
126 
127 /*
128  * Returns true as long as we're below navigation altitude
129  */
131 {
132  // keep controlling yaw directly until we start navigation
134 }
135 
136 /*
137  * Returns pitch setpoint to use.
138  *
139  * Limited (parameter) as long as the plane is on runway. Otherwise
140  * use the one from TECS
141  */
142 float RunwayTakeoff::getPitch(float tecsPitch)
143 {
145  return math::radians(_param_rwto_psp.get());
146  }
147 
148  return tecsPitch;
149 }
150 
151 /*
152  * Returns the roll setpoint to use.
153  */
154 float RunwayTakeoff::getRoll(float navigatorRoll)
155 {
156  // until we have enough ground clearance, set roll to 0
158  return 0.0f;
159  }
160 
161  // allow some roll during climbout
162  else if (_state < RunwayTakeoffState::FLY) {
163  return math::constrain(navigatorRoll,
164  math::radians(-_param_rwto_max_roll.get()),
165  math::radians(_param_rwto_max_roll.get()));
166  }
167 
168  return navigatorRoll;
169 }
170 
171 /*
172  * Returns the yaw setpoint to use.
173  *
174  * In heading hold mode (_heading_mode == 0), it returns initial yaw as long as it's on the
175  * runway. When it has enough ground clearance we start navigation towards WP.
176  */
177 float RunwayTakeoff::getYaw(float navigatorYaw)
178 {
179  if (_param_rwto_hdg.get() == 0 && _state < RunwayTakeoffState::CLIMBOUT) {
180  return _init_yaw;
181 
182  } else {
183  return navigatorYaw;
184  }
185 }
186 
187 /*
188  * Returns the throttle setpoint to use.
189  *
190  * Ramps up in the beginning, until it lifts off the runway it is set to
191  * parameter value, then it returns the TECS throttle.
192  */
193 float RunwayTakeoff::getThrottle(float tecsThrottle)
194 {
195  switch (_state) {
197  float throttle = (hrt_elapsed_time(&_initialized_time) / (float)_param_rwto_ramp_time.get() * 1e6f) *
198  _param_rwto_max_thr.get();
199  return throttle < _param_rwto_max_thr.get() ?
200  throttle :
201  _param_rwto_max_thr.get();
202  }
203 
205  return _param_rwto_max_thr.get();
206 
207  default:
208  return tecsThrottle;
209  }
210 }
211 
213 {
214  // reset integrators if we're still on runway
216 }
217 
218 /*
219  * Returns the minimum pitch for TECS to use.
220  *
221  * In climbout we either want what was set on the waypoint (sp_min) but at least
222  * the climbtout minimum pitch (parameter).
223  * Otherwise use the minimum that is enforced generally (parameter).
224  */
225 float RunwayTakeoff::getMinPitch(float sp_min, float climbout_min, float min)
226 {
228  return math::max(sp_min, climbout_min);
229  }
230 
231  else {
232  return min;
233  }
234 }
235 
236 /*
237  * Returns the maximum pitch for TECS to use.
238  *
239  * Limited by parameter (if set) until climbout is done.
240  */
242 {
243  // use max pitch from parameter if set (> 0.1)
244  if (_state < RunwayTakeoffState::FLY && _param_rwto_max_pitch.get() > 0.1f) {
245  return _param_rwto_max_pitch.get();
246  }
247 
248  else {
249  return max;
250  }
251 }
252 
253 /*
254  * Returns the "previous" (start) WP for navigation.
255  */
257 {
258  return _start_wp;
259 }
260 
262 {
263  _initialized = false;
265 }
266 
267 }
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
Definition: Limits.hpp:66
static orb_advert_t * mavlink_log_pub
ramping up throttle
Definition: RunwayTakeoff.h:58
float getYaw(float navigatorYaw)
taking off, get ground clearance, roll 0
Definition: RunwayTakeoff.h:60
RunwayTakeoffState _state
state variables
Definition: RunwayTakeoff.h:96
float getPitch(float tecsPitch)
Runway takeoff handling for fixed-wing UAVs with steerable wheels.
fly towards takeoff waypoint
Definition: RunwayTakeoff.h:62
constexpr T radians(T degrees)
Definition: Limits.hpp:85
Vector2< float > Vector2f
Definition: Vector2.hpp:69
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
Definition: drv_hrt.h:102
float getThrottle(float tecsThrottle)
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
constexpr _Tp min(_Tp a, _Tp b)
Definition: Limits.hpp:54
void init(float yaw, double current_lat, double current_lon)
RunwayTakeoff(ModuleParams *parent)
constexpr _Tp max(_Tp a, _Tp b)
Definition: Limits.hpp:60
clamped to runway, controlling yaw directly (wheel or rudder)
Definition: RunwayTakeoff.h:59
float getMinPitch(float sp_min, float climbout_min, float min)
float getRoll(float navigatorRoll)
matrix::Vector2f getStartWP()
void update(float airspeed, float alt_agl, double current_lat, double current_lon, orb_advert_t *mavlink_log_pub)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
climbout to safe height before navigation, roll limited
Definition: RunwayTakeoff.h:61