Firmware
FlightTaskAuto.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 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  ****************************************************************************/
33 
40 #pragma once
41 
42 #include "FlightTask.hpp"
43 #include <uORB/topics/position_setpoint_triplet.h>
44 #include <uORB/topics/position_setpoint.h>
45 #include <uORB/topics/home_position.h>
46 #include <uORB/topics/vehicle_status.h>
47 #include <lib/ecl/geo/geo.h>
48 #include <ObstacleAvoidance.hpp>
49 
55 enum class WaypointType : int {
56  position = position_setpoint_s::SETPOINT_TYPE_POSITION,
57  velocity = position_setpoint_s::SETPOINT_TYPE_VELOCITY,
58  loiter = position_setpoint_s::SETPOINT_TYPE_LOITER,
59  takeoff = position_setpoint_s::SETPOINT_TYPE_TAKEOFF,
60  land = position_setpoint_s::SETPOINT_TYPE_LAND,
61  idle = position_setpoint_s::SETPOINT_TYPE_IDLE,
62  offboard = position_setpoint_s::SETPOINT_TYPE_OFFBOARD, // only part of this structure due to legacy reason. It is not used within the Auto flighttasks
63  follow_target = position_setpoint_s::SETPOINT_TYPE_FOLLOW_TARGET,
64 };
65 
66 enum class State {
67  offtrack,
70  none
71 };
72 
73 class FlightTaskAuto : public FlightTask
74 {
75 public:
77 
78  virtual ~FlightTaskAuto() = default;
79  bool initializeSubscriptions(SubscriptionArray &subscription_array) override;
80  bool activate() override;
81  bool updateInitialize() override;
82  bool updateFinalize() override;
83 
87  void setYawHandler(WeatherVane *ext_yaw_handler) override {_ext_yaw_handler = ext_yaw_handler;}
88 
89 protected:
90  void _setDefaultConstraints() override;
91  matrix::Vector2f _getTargetVelocityXY();
92  void _updateInternalWaypoints();
93  bool _compute_heading_from_2D_vector(float &heading, matrix::Vector2f v);
95  matrix::Vector3f _prev_prev_wp{};
96  matrix::Vector3f _prev_wp{};
97  matrix::Vector3f _target{};
98  matrix::Vector3f _next_wp{};
99  float _mc_cruise_speed{0.0f};
100  WaypointType _type{WaypointType::idle};
101  uORB::Subscription<home_position_s> *_sub_home_position{nullptr};
102 
103  State _current_state{State::none};
104  float _target_acceptance_radius = 0.0f;
105  int _mission_gear = landing_gear_s::GEAR_KEEP;
106 
109  DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTask,
110  (ParamFloat<px4::params::MPC_XY_CRUISE>) _param_mpc_xy_cruise,
111  (ParamFloat<px4::params::MPC_CRUISE_90>) _param_mpc_cruise_90, // speed at corner when angle is 90 degrees move to line
113  _param_nav_mc_alt_rad, //vertical acceptance radius at which waypoints are updated
114  (ParamInt<px4::params::MPC_YAW_MODE>) _param_mpc_yaw_mode, // defines how heading is executed,
115  (ParamInt<px4::params::COM_OBS_AVOID>) _param_com_obs_avoid, // obstacle avoidance active
116  (ParamFloat<px4::params::MPC_YAWRAUTO_MAX>) _param_mpc_yawrauto_max
117  );
118 
119 private:
120  matrix::Vector2f _lock_position_xy{NAN, NAN};
121  bool _yaw_lock = false;
122  float _yaw_sp_prev = NAN;
123  uORB::Subscription<position_setpoint_triplet_s> *_sub_triplet_setpoint{nullptr};
124  uORB::Subscription<vehicle_status_s> *_sub_vehicle_status{nullptr};
125 
126  matrix::Vector3f
127  _triplet_target;
128  matrix::Vector3f
129  _triplet_prev_wp;
130  matrix::Vector3f
131  _triplet_next_wp;
132  matrix::Vector2f _closest_pt;
134  map_projection_reference_s _reference_position{};
135  float _reference_altitude = NAN;
136  hrt_abstime _time_stamp_reference = 0;
138  WeatherVane *_ext_yaw_handler =
139  nullptr;
142  void _limitYawRate();
143  bool _evaluateTriplets();
144  bool _isFinite(const position_setpoint_s &sp);
145  bool _evaluateGlobalReference();
146  State _getCurrentState();
147  void _set_heading_from_mode();
148 };
Vehicle is in normal tracking mode from triplet previous to triplet target.
Definition: px4_param.h:313
Definition: WeatherVane.hpp:48
Definition: FlightTask.hpp:58
WaypointType
This enum has to agree with position_setpoint_s type definition The only reason for not using the str...
Definition: FlightTaskAuto.hpp:55
Definition: FlightTaskAuto.hpp:73
State
Definition: FlightTaskAuto.hpp:66
void setYawHandler(WeatherVane *ext_yaw_handler) override
Sets an external yaw handler which can be used to implement a different yaw control strategy...
Definition: FlightTaskAuto.hpp:87
Definition: px4_param.h:318
Vehilce is behind previous waypoint.
Abstract base class for different advanced flight tasks like orbit, follow me, ...
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
Vehicle is more than cruise speed away from track.
ObstacleAvoidance _obstacle_avoidance
class adjusting setpoints according to external avoidance module&#39;s input
Definition: FlightTaskAuto.hpp:107
Vehicle is in front of target.
Definition: ObstacleAvoidance.hpp:58
Definition: SubscriptionArray.hpp:46
This class is used to inject the setpoints of an obstacle avoidance system into the FlightTasks...