Firmware
FlightTaskManualAltitude.hpp
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 "FlightTaskManual.hpp"
43 #include <uORB/topics/home_position.h>
44 
46 {
47 public:
48  FlightTaskManualAltitude() = default;
49  virtual ~FlightTaskManualAltitude() = default;
50  bool initializeSubscriptions(SubscriptionArray &subscription_array) override;
51  bool activate() override;
52  bool updateInitialize() override;
53  bool update() override;
54 
55 protected:
57  virtual void _updateSetpoints();
58  virtual void _scaleSticks();
63  void _rotateIntoHeadingFrame(matrix::Vector2f &vec);
64 
70  void _updateAltitudeLock();
71 
72  DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTaskManual,
73  (ParamFloat<px4::params::MPC_HOLD_MAX_Z>) _param_mpc_hold_max_z,
74  (ParamInt<px4::params::MPC_ALT_MODE>) _param_mpc_alt_mode,
75  (ParamFloat<px4::params::MPC_HOLD_MAX_XY>) _param_mpc_hold_max_xy,
76  (ParamFloat<px4::params::MPC_Z_P>) _param_mpc_z_p,
77  (ParamFloat<px4::params::MPC_MAN_Y_MAX>) _param_mpc_man_y_max,
78  (ParamFloat<px4::params::MPC_MAN_TILT_MAX>) _param_mpc_man_tilt_max,
79  (ParamFloat<px4::params::MPC_LAND_ALT1>) _param_mpc_land_alt1,
80  (ParamFloat<px4::params::MPC_LAND_ALT2>) _param_mpc_land_alt2,
82  _param_mpc_land_speed,
84  _param_mpc_tko_speed
85  )
86 private:
94  void _terrainFollowing(bool apply_brake, bool stopped);
95 
102  void _respectMinAltitude();
103 
104  void _respectMaxAltitude();
105 
110  void _respectGroundSlowdown();
111 
112  uORB::Subscription<home_position_s> *_sub_home_position{nullptr};
113 
114  uint8_t _reset_counter = 0;
115  float _max_speed_up = 10.0f;
116  float _min_speed_down = 1.0f;
117  bool _terrain_follow{false};
118  bool _terrain_hold{false};
126  float _dist_to_ground_lock = NAN;
127 };
void _updateHeadingSetpoints()
sets yaw or yaw speed
Definition: FlightTaskManualAltitude.cpp:300
Definition: px4_param.h:313
bool updateInitialize() override
Call before activate() or update() to initialize time and input data.
Definition: FlightTaskManualAltitude.cpp:57
void _respectGroundSlowdown()
Sets downwards velocity constraint based on the distance to ground.
Definition: FlightTaskManualAltitude.cpp:268
float _dist_to_ground_lock
Distance to ground during terrain following.
Definition: FlightTaskManualAltitude.hpp:126
void _updateAltitudeLock()
Check and sets for position lock.
Definition: FlightTaskManualAltitude.cpp:105
virtual void _scaleSticks()
scales sticks to velocity in z
Definition: FlightTaskManualAltitude.cpp:96
Definition: px4_param.h:318
uint8_t _reset_counter
counter for estimator resets in z-direction
Definition: FlightTaskManualAltitude.hpp:114
bool _terrain_follow
true when the vehicle is following the terrain height
Definition: FlightTaskManualAltitude.hpp:117
DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTaskManual,(ParamFloat< px4::params::MPC_HOLD_MAX_Z >) _param_mpc_hold_max_z,(ParamInt< px4::params::MPC_ALT_MODE >) _param_mpc_alt_mode,(ParamFloat< px4::params::MPC_HOLD_MAX_XY >) _param_mpc_hold_max_xy,(ParamFloat< px4::params::MPC_Z_P >) _param_mpc_z_p,(ParamFloat< px4::params::MPC_MAN_Y_MAX >) _param_mpc_man_y_max,(ParamFloat< px4::params::MPC_MAN_TILT_MAX >) _param_mpc_man_tilt_max,(ParamFloat< px4::params::MPC_LAND_ALT1 >) _param_mpc_land_alt1,(ParamFloat< px4::params::MPC_LAND_ALT2 >) _param_mpc_land_alt2,(ParamFloat< px4::params::MPC_LAND_SPEED >) _param_mpc_land_speed,(ParamFloat< px4::params::MPC_TKO_SPEED >) _param_mpc_tko_speed) private void _respectMinAltitude()
Terrain following.
Definition: FlightTaskManualAltitude.cpp:199
void _rotateIntoHeadingFrame(matrix::Vector2f &vec)
rotates vector into local frame
Definition: FlightTaskManualAltitude.cpp:292
Linear and exponential map from stick inputs to range -1 and 1.
bool _terrain_hold
true when vehicle is controlling height above a static ground position
Definition: FlightTaskManualAltitude.hpp:118
virtual void _updateSetpoints()
updates all setpoints
Definition: FlightTaskManualAltitude.cpp:324
Definition: FlightTaskManualAltitude.hpp:45
bool update() override
To be called regularly in the control loop cycle to execute the task.
Definition: FlightTaskManualAltitude.cpp:348
Definition: SubscriptionArray.hpp:46
Definition: FlightTaskManual.hpp:46
bool initializeSubscriptions(SubscriptionArray &subscription_array) override
Initialize the uORB subscriptions using an array.
Definition: FlightTaskManualAltitude.cpp:44
bool activate() override
Call once on the event where you switch to the task.
Definition: FlightTaskManualAltitude.cpp:64