PX4 Firmware
PX4 Autopilot Software http://px4.io
precland.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Copyright (c) 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 precland.h
35  *
36  * Helper class to do precision landing with a landing target
37  *
38  * @author Nicolas de Palezieux (Sunflower Labs) <ndepal@gmail.com>
39  */
40 
41 #pragma once
42 
43 #include <matrix/math.hpp>
44 #include <lib/ecl/geo/geo.h>
45 #include <px4_platform_common/module_params.h>
46 #include <uORB/Subscription.hpp>
48 
49 #include "navigator_mode.h"
50 #include "mission_block.h"
51 
52 enum class PrecLandState {
53  Start, // Starting state
54  HorizontalApproach, // Positioning over landing target while maintaining altitude
55  DescendAboveTarget, // Stay over landing target while descending
56  FinalApproach, // Final landing approach, even without landing target
57  Search, // Search for landing target
58  Fallback, // Fallback landing method
59  Done // Done landing
60 };
61 
62 enum class PrecLandMode {
63  Opportunistic = 1, // only do precision landing if landing target visible at the beginning
64  Required = 2 // try to find landing target if not visible at the beginning
65 };
66 
67 class PrecLand : public MissionBlock, public ModuleParams
68 {
69 public:
71  ~PrecLand() override = default;
72 
73  void on_activation() override;
74  void on_active() override;
75 
77 
78  PrecLandMode get_mode() { return _mode; };
79 
80 private:
81 
82  void updateParams() override;
83 
84  // run the control loop for each state
85  void run_state_start();
86  void run_state_horizontal_approach();
87  void run_state_descend_above_target();
88  void run_state_final_approach();
89  void run_state_search();
90  void run_state_fallback();
91 
92  // attempt to switch to a different state. Returns true if state change was successful, false otherwise
93  bool switch_to_state_start();
94  bool switch_to_state_horizontal_approach();
95  bool switch_to_state_descend_above_target();
96  bool switch_to_state_final_approach();
97  bool switch_to_state_search();
98  bool switch_to_state_fallback();
99  bool switch_to_state_done();
100 
101  // check if a given state could be changed into. Return true if possible to transition to state, false otherwise
102  bool check_state_conditions(PrecLandState state);
103  void slewrate(float &sp_x, float &sp_y);
104 
105  landing_target_pose_s _target_pose{}; /**< precision landing target position */
106 
107  uORB::Subscription _target_pose_sub{ORB_ID(landing_target_pose)};
108  bool _target_pose_valid{false}; /**< whether we have received a landing target position message */
109  bool _target_pose_updated{false}; /**< wether the landing target position message is updated */
110 
111  struct map_projection_reference_s _map_ref {}; /**< reference for local/global projections */
112 
113  uint64_t _state_start_time{0}; /**< time when we entered current state */
114  uint64_t _last_slewrate_time{0}; /**< time when we last limited setpoint changes */
115  uint64_t _target_acquired_time{0}; /**< time when we first saw the landing target during search */
116  uint64_t _point_reached_time{0}; /**< time when we reached a setpoint */
117 
118  int _search_cnt{0}; /**< counter of how many times we had to search for the landing target */
119  float _approach_alt{0.0f}; /**< altitude at which to stay during horizontal approach */
120 
123 
125 
127 
129  (ParamFloat<px4::params::PLD_BTOUT>) _param_pld_btout,
130  (ParamFloat<px4::params::PLD_HACC_RAD>) _param_pld_hacc_rad,
131  (ParamFloat<px4::params::PLD_FAPPR_ALT>) _param_pld_fappr_alt,
132  (ParamFloat<px4::params::PLD_SRCH_ALT>) _param_pld_srch_alt,
133  (ParamFloat<px4::params::PLD_SRCH_TOUT>) _param_pld_srch_tout,
134  (ParamInt<px4::params::PLD_MAX_SRCH>) _param_pld_max_srch
135  )
136 
137  // non-navigator parameters
138  param_t _handle_param_acceleration_hor{PARAM_INVALID};
139  param_t _handle_param_xy_vel_cruise{PARAM_INVALID};
140  float _param_acceleration_hor{0.0f};
141  float _param_xy_vel_cruise{0.0f};
142 
143 };
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
Definition: param.h:103
static enum @74 state
Definition of geo / math functions to perform geodesic calculations.
reference for local/global projections
Definition: precland.h:111
static Mode _mode
Definition: motor_ramp.cpp:81
Helper class to use mission items.
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
PrecLandMode
Definition: precland.h:62
matrix::Vector2f _sp_pev
Definition: precland.h:121
matrix::Vector2f _sp_pev_prev
Definition: precland.h:122
PrecLandState
Definition: precland.h:52
DEFINE_PARAMETERS((ParamFloat< px4::params::PLD_BTOUT >) _param_pld_btout,(ParamFloat< px4::params::PLD_HACC_RAD >) _param_pld_hacc_rad,(ParamFloat< px4::params::PLD_FAPPR_ALT >) _param_pld_fappr_alt,(ParamFloat< px4::params::PLD_SRCH_ALT >) _param_pld_srch_alt,(ParamFloat< px4::params::PLD_SRCH_TOUT >) _param_pld_srch_tout,(ParamInt< px4::params::PLD_MAX_SRCH >) _param_pld_max_srch) param_t _handle_param_acceleration_hor
Definition: precland.h:128
PrecLandMode get_mode()
Definition: precland.h:78
mode
Definition: vtol_type.h:76
void set_mode(PrecLandMode mode)
Definition: precland.h:76
uint32_t param_t
Parameter handle.
Definition: param.h:98