Firmware
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  ****************************************************************************/
41 #pragma once
42 
43 #include <matrix/math.hpp>
44 #include <lib/ecl/geo/geo.h>
45 #include <px4_module_params.h>
46 #include <uORB/topics/landing_target_pose.h>
47 
48 #include "navigator_mode.h"
49 #include "mission_block.h"
50 
51 enum class PrecLandState {
52  Start, // Starting state
53  HorizontalApproach, // Positioning over landing target while maintaining altitude
54  DescendAboveTarget, // Stay over landing target while descending
55  FinalApproach, // Final landing approach, even without landing target
56  Search, // Search for landing target
57  Fallback, // Fallback landing method
58  Done // Done landing
59 };
60 
61 enum class PrecLandMode {
62  Opportunistic = 1, // only do precision landing if landing target visible at the beginning
63  Required = 2 // try to find landing target if not visible at the beginning
64 };
65 
66 class PrecLand : public MissionBlock, public ModuleParams
67 {
68 public:
70  ~PrecLand() override = default;
71 
72  void on_activation() override;
73  void on_active() override;
74 
75  void set_mode(PrecLandMode mode) { _mode = mode; };
76 
77  PrecLandMode get_mode() { return _mode; };
78 
79 private:
80 
81  void updateParams() override;
82 
83  // run the control loop for each state
84  void run_state_start();
85  void run_state_horizontal_approach();
86  void run_state_descend_above_target();
87  void run_state_final_approach();
88  void run_state_search();
89  void run_state_fallback();
90 
91  // attempt to switch to a different state. Returns true if state change was successful, false otherwise
92  bool switch_to_state_start();
93  bool switch_to_state_horizontal_approach();
94  bool switch_to_state_descend_above_target();
95  bool switch_to_state_final_approach();
96  bool switch_to_state_search();
97  bool switch_to_state_fallback();
98  bool switch_to_state_done();
99 
100  // check if a given state could be changed into. Return true if possible to transition to state, false otherwise
101  bool check_state_conditions(PrecLandState state);
102  void slewrate(float &sp_x, float &sp_y);
103 
104  landing_target_pose_s _target_pose{};
106  int _target_pose_sub{-1};
107  bool _target_pose_valid{false};
108  bool _target_pose_updated{false};
110  struct map_projection_reference_s _map_ref {};
112  uint64_t _state_start_time{0};
113  uint64_t _last_slewrate_time{0};
114  uint64_t _target_acquired_time{0};
115  uint64_t _point_reached_time{0};
117  int _search_cnt{0};
118  float _approach_alt{0.0f};
120  matrix::Vector2f _sp_pev;
121  matrix::Vector2f _sp_pev_prev;
122 
123  PrecLandState _state{PrecLandState::Start};
124 
125  PrecLandMode _mode{PrecLandMode::Opportunistic};
126 
127  DEFINE_PARAMETERS(
128  (ParamFloat<px4::params::PLD_BTOUT>) _param_pld_btout,
129  (ParamFloat<px4::params::PLD_HACC_RAD>) _param_pld_hacc_rad,
130  (ParamFloat<px4::params::PLD_FAPPR_ALT>) _param_pld_fappr_alt,
131  (ParamFloat<px4::params::PLD_SRCH_ALT>) _param_pld_srch_alt,
132  (ParamFloat<px4::params::PLD_SRCH_TOUT>) _param_pld_srch_tout,
133  (ParamInt<px4::params::PLD_MAX_SRCH>) _param_pld_max_srch
134  )
135 
136  // non-navigator parameters
137  param_t _handle_param_acceleration_hor{PARAM_INVALID};
138  param_t _handle_param_xy_vel_cruise{PARAM_INVALID};
139  float _param_acceleration_hor{0.0f};
140  float _param_xy_vel_cruise{0.0f};
141 
142 };
#define PARAM_INVALID
Handle returned when a parameter cannot be found.
Definition: param.h:103
Definition: px4_param.h:313
Helper class to use mission items.
Definition: mission_block.h:56
Definition: navigator_main.cpp:80
Definition: px4_param.h:318
C++ base class for modules/classes using configuration parameters.
Definition: px4_module_params.h:46
Definition: precland.h:66
Definition: navigator.h:83
uint32_t param_t
Parameter handle.
Definition: param.h:98