PX4 Firmware
PX4 Autopilot Software http://px4.io
Takeoff.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 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 /**
35  * @file Takeoff.hpp
36  *
37  * A class handling all takeoff states and a smooth ramp up of the motors.
38  */
39 
40 #pragma once
41 
43 #include <drivers/drv_hrt.h>
44 
45 using namespace time_literals;
46 
47 enum class TakeoffState {
48  disarmed = 0,
49  spoolup,
51  rampup,
52  flight
53 };
54 
55 class Takeoff
56 {
57 public:
58  Takeoff() = default;
59  ~Takeoff() = default;
60 
61  // initialize parameters
62  void setTakeoffRampTime(const float seconds) { _takeoff_ramp_time = seconds; }
63  void setSpoolupTime(const float seconds) { _spoolup_time_hysteresis.set_hysteresis_time_from(false, (hrt_abstime)(seconds * (float)1_s)); }
64 
65  /**
66  * Calculate a vertical velocity to initialize the takeoff ramp
67  * that when passed to the velocity controller results in a zero throttle setpoint.
68  * @param hover_thrust normalized thrsut value with which the vehicle hovers
69  * @param velocity_p_gain proportional gain of the velocity controller to calculate the thrust
70  */
71  void generateInitialRampValue(const float hover_thrust, const float velocity_p_gain);
72 
73  /**
74  * Update the state for the takeoff.
75  * @param setpoint a vehicle_local_position_setpoint_s structure
76  * @return true if setpoint has updated correctly
77  */
78  void updateTakeoffState(const bool armed, const bool landed, const bool want_takeoff,
79  const float takeoff_desired_vz, const bool skip_takeoff, const hrt_abstime &now_us);
80 
81  /**
82  * Update and return the velocity constraint ramp value during takeoff.
83  * By ramping up _takeoff_ramp_vz during the takeoff and using it to constain the maximum climb rate a smooth takeoff behavior is achieved.
84  * Returns zero on the ground and takeoff_desired_vz in flight.
85  * @param dt time in seconds since the last call/loop iteration
86  * @param takeoff_desired_vz end value for the velocity ramp
87  * @return true if setpoint has updated correctly
88  */
89  float updateRamp(const float dt, const float takeoff_desired_vz);
90 
91  TakeoffState getTakeoffState() { return _takeoff_state; }
92 
93 private:
95 
96  float _takeoff_ramp_time = 0.f;
97  float _takeoff_ramp_vz_init = 0.f;
98  float _takeoff_ramp_vz = 0.f;
99 
100  systemlib::Hysteresis _spoolup_time_hysteresis{false}; /**< becomes true MPC_SPOOLUP_TIME seconds after the vehicle was armed */
101 };
High-resolution timer with callouts and timekeeping.
void setTakeoffRampTime(const float seconds)
Definition: Takeoff.hpp:62
static struct actuator_armed_s armed
Definition: Commander.cpp:139
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
void setSpoolupTime(const float seconds)
Definition: Takeoff.hpp:63
Hysteresis of a boolean value.
TakeoffState
Definition: Takeoff.hpp:47
float dt
Definition: px4io.c:73
TakeoffState getTakeoffState()
Definition: Takeoff.hpp:91