PX4 Firmware
PX4 Autopilot Software http://px4.io
rtl.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Copyright (c) 2013-2017 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 rtl.h
35  *
36  * Helper class for RTL
37  *
38  * @author Julian Oes <julian@oes.ch>
39  * @author Anton Babushkin <anton.babushkin@me.com>
40  */
41 
42 #pragma once
43 
44 #include <px4_platform_common/module_params.h>
45 
46 #include "navigator_mode.h"
47 #include "mission_block.h"
48 
50 
51 class Navigator;
52 
53 class RTL : public MissionBlock, public ModuleParams
54 {
55 public:
56  enum RTLType {
57  RTL_HOME = 0,
61  };
62 
67  };
68 
70 
71  ~RTL() = default;
72 
73  void on_inactive() override;
74  void on_activation() override;
75  void on_active() override;
76 
77  void find_RTL_destination();
78 
79  void set_return_alt_min(bool min);
80 
81  int rtl_type() const;
82 
83  int rtl_destination();
84 
85 private:
86  /**
87  * Set the RTL item
88  */
89  void set_rtl_item();
90 
91  /**
92  * Move to next RTL item
93  */
94  void advance_rtl();
95 
96 
97  float calculate_return_alt_from_cone_half_angle(float cone_half_angle_deg);
98 
99  enum RTLState {
108  } _rtl_state{RTL_STATE_NONE};
109 
110  struct RTLPosition {
111  double lat;
112  double lon;
113  float alt;
114  float yaw;
115  uint8_t safe_point_index; ///< 0 = home position, 1 = mission landing, >1 = safe landing points (rally points)
117 
118  void set(const home_position_s &home_position)
119  {
120  lat = home_position.lat;
121  lon = home_position.lon;
122  alt = home_position.alt;
123  yaw = home_position.yaw;
124  safe_point_index = 0;
126  }
127  };
128 
129  RTLPosition _destination{}; ///< the RTL position to fly to (typically the home position or a safe point)
130 
131  float _rtl_alt{0.0f}; // AMSL altitude at which the vehicle should return to the home position
132  bool _rtl_alt_min{false};
133 
134  DEFINE_PARAMETERS(
135  (ParamFloat<px4::params::RTL_RETURN_ALT>) _param_rtl_return_alt,
136  (ParamFloat<px4::params::RTL_DESCEND_ALT>) _param_rtl_descend_alt,
137  (ParamFloat<px4::params::RTL_LAND_DELAY>) _param_rtl_land_delay,
138  (ParamFloat<px4::params::RTL_MIN_DIST>) _param_rtl_min_dist,
139  (ParamInt<px4::params::RTL_TYPE>) _param_rtl_type,
140  (ParamInt<px4::params::RTL_CONE_ANG>) _param_rtl_cone_half_angle_deg
141  )
142 };
void advance_rtl()
Move to next RTL item.
Definition: rtl.cpp:423
RTLType
Definition: rtl.h:56
uint8_t safe_point_index
0 = home position, 1 = mission landing, >1 = safe landing points (rally points)
Definition: rtl.h:115
~RTL()=default
RTLState
Definition: rtl.h:99
Helper class to use mission items.
void set_return_alt_min(bool min)
Definition: rtl.cpp:230
RTLDestinationType
Definition: rtl.h:63
void set_rtl_item()
Set the RTL item.
Definition: rtl.cpp:236
int rtl_destination()
void on_inactive() override
This function is called while the mode is inactive.
Definition: rtl.cpp:56
float yaw
Definition: rtl.h:114
RTLDestinationType type
Definition: rtl.h:116
float _rtl_alt
Definition: rtl.h:131
double lon
Definition: rtl.h:112
Definition: rtl.h:53
float alt
Definition: rtl.h:113
double lat
Definition: rtl.h:111
constexpr _Tp min(_Tp a, _Tp b)
Definition: Limits.hpp:54
RTLPosition _destination
the RTL position to fly to (typically the home position or a safe point)
Definition: rtl.h:129
bool _rtl_alt_min
Definition: rtl.h:132
void find_RTL_destination()
Definition: rtl.cpp:66
void on_active() override
This function is called while the mode is active.
Definition: rtl.cpp:221
enum RTL::RTLState RTL_STATE_NONE
void on_activation() override
This function is called one time when mode becomes active, pos_sp_triplet must be initialized here...
Definition: rtl.cpp:177
RTL(Navigator *navigator)
Definition: rtl.cpp:49
int rtl_type() const
Definition: rtl.cpp:171
float calculate_return_alt_from_cone_half_angle(float cone_half_angle_deg)
Definition: rtl.cpp:477