Firmware
mission.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2013-2018 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  ****************************************************************************/
45 #pragma once
46 
47 #include "mission_block.h"
49 #include "navigator_mode.h"
50 
51 #include <float.h>
52 
53 #include <dataman/dataman.h>
54 #include <drivers/drv_hrt.h>
55 #include <px4_module_params.h>
56 #include <uORB/topics/home_position.h>
57 #include <uORB/topics/mission.h>
58 #include <uORB/topics/mission_result.h>
59 #include <uORB/topics/position_setpoint_triplet.h>
60 #include <uORB/topics/vehicle_global_position.h>
61 #include <uORB/topics/vehicle_status.h>
62 #include <uORB/topics/vehicle_roi.h>
63 #include <uORB/uORB.h>
64 
65 class Navigator;
66 
67 class Mission : public MissionBlock, public ModuleParams
68 {
69 public:
71  ~Mission() override = default;
72 
73  void on_inactive() override;
74  void on_inactivation() override;
75  void on_activation() override;
76  void on_active() override;
77 
78  enum mission_altitude_mode {
79  MISSION_ALTMODE_ZOH = 0,
80  MISSION_ALTMODE_FOH = 1
81  };
82 
83  bool set_current_mission_index(uint16_t index);
84 
85  bool land_start();
86  bool landing();
87 
88  uint16_t get_land_start_index() const { return _land_start_index; }
89  bool get_land_start_available() const { return _land_start_available; }
90  bool get_mission_finished() const { return _mission_type == MISSION_TYPE_NONE; }
91  bool get_mission_changed() const { return _mission_changed ; }
92  bool get_mission_waypoints_changed() const { return _mission_waypoints_changed ; }
93 
94  void set_closest_item_as_current();
95 
101  void set_execution_mode(const uint8_t mode);
102 private:
103 
107  void update_mission();
108 
112  void advance_mission();
113 
117  void set_mission_items();
118 
122  bool do_need_vertical_takeoff();
123 
127  bool do_need_move_to_land();
128 
132  bool do_need_move_to_takeoff();
133 
137  void copy_position_if_valid(struct mission_item_s *mission_item, struct position_setpoint_s *setpoint);
138 
142  void set_align_mission_item(struct mission_item_s *mission_item, struct mission_item_s *mission_item_next);
143 
147  float calculate_takeoff_altitude(struct mission_item_s *mission_item);
148 
152  void heading_sp_update();
153 
157  void altitude_sp_foh_update();
158 
162  void cruising_speed_sp_update();
163 
167  void do_abort_landing();
168 
175  bool prepare_mission_items(mission_item_s *mission_item,
176  mission_item_s *next_position_mission_item, bool *has_next_position_item);
177 
184  bool read_mission_item(int offset, struct mission_item_s *mission_item);
185 
189  void save_mission_state();
190 
194  void report_do_jump_mission_changed(int index, int do_jumps_remaining);
195 
199  void set_mission_item_reached();
200 
204  void set_current_mission_item();
205 
209  void check_mission_valid(bool force);
210 
214  void reset_mission(struct mission_s &mission);
215 
219  bool need_to_reset_mission(bool active);
220 
224  void generate_waypoint_from_heading(struct position_setpoint_s *setpoint, float yaw);
225 
229  bool find_mission_land_start();
230 
234  int32_t index_closest_mission_item() const;
235 
236  bool position_setpoint_equal(const position_setpoint_s *p1, const position_setpoint_s *p2) const;
237 
238  DEFINE_PARAMETERS(
239  (ParamFloat<px4::params::MIS_DIST_1WP>) _param_mis_dist_1wp,
240  (ParamFloat<px4::params::MIS_DIST_WPS>) _param_mis_dist_wps,
241  (ParamInt<px4::params::MIS_ALTMODE>) _param_mis_altmode,
242  (ParamInt<px4::params::MIS_MNT_YAW_CTL>) _param_mis_mnt_yaw_ctl
243  )
244 
245  struct mission_s _mission {};
246 
247  int32_t _current_mission_index{-1};
248 
249  // track location of planned mission landing
250  bool _land_start_available{false};
251  uint16_t _land_start_index{UINT16_MAX};
253  bool _need_takeoff{true};
255  enum {
256  MISSION_TYPE_NONE,
257  MISSION_TYPE_MISSION
258  } _mission_type{MISSION_TYPE_NONE};
259 
260  bool _inited{false};
261  bool _home_inited{false};
262  bool _need_mission_reset{false};
263  bool _mission_waypoints_changed{false};
264  bool _mission_changed{false};
266  float _min_current_sp_distance_xy{FLT_MAX};
268  float _distance_current_previous{0.0f};
271  enum work_item_type {
272  WORK_ITEM_TYPE_DEFAULT,
273  WORK_ITEM_TYPE_TAKEOFF,
274  WORK_ITEM_TYPE_MOVE_TO_LAND,
275  WORK_ITEM_TYPE_ALIGN,
276  WORK_ITEM_TYPE_CMD_BEFORE_MOVE,
277  WORK_ITEM_TYPE_TRANSITON_AFTER_TAKEOFF,
278  WORK_ITEM_TYPE_MOVE_TO_LAND_AFTER_TRANSITION,
279  WORK_ITEM_TYPE_PRECISION_LAND
280  } _work_item_type{WORK_ITEM_TYPE_DEFAULT};
282  uint8_t _mission_execution_mode{mission_result_s::MISSION_EXECUTION_MODE_NORMAL};
283  bool _execution_mode_changed{false};
284 };
Global position setpoint in WGS84 coordinates.
Definition: navigation.h:145
void on_inactive() override
This function is called while the mode is inactive.
Definition: mission.cpp:69
Definition: px4_param.h:313
void on_active() override
This function is called while the mode is active.
Definition: mission.cpp:178
Helper class to use mission items.
Definition: mission_block.h:56
Definition: navigator_main.cpp:80
High-resolution timer with callouts and timekeeping.
Provides checks if mission is feasible given the navigation capabilities.
API for the uORB lightweight object broker.
Definition: px4_param.h:318
C++ base class for modules/classes using configuration parameters.
Definition: px4_module_params.h:46
DATAMANAGER driver.
void on_activation() override
This function is called one time when mode becomes active, pos_sp_triplet must be initialized here...
Definition: mission.cpp:152
void on_inactivation() override
This function is called one time when mode becomes inactive.
Definition: mission.cpp:140
Definition: navigator.h:83
Definition: mission.h:67
void set_execution_mode(const uint8_t mode)
Set a new mission mode and handle the switching between the different modes.
Definition: mission.cpp:316