2017-12-08 19:44:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
2018-04-25 10:23:40 +02:00
|
|
|
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
|
2017-12-08 19:44:27 +01:00
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
2017-12-24 16:02:50 +01:00
|
|
|
* @file FlightManualAltitude.cpp
|
2017-12-08 19:44:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "FlightTaskManualAltitude.hpp"
|
|
|
|
|
#include <float.h>
|
2018-06-25 10:00:08 +02:00
|
|
|
#include <mathlib/mathlib.h>
|
2020-01-27 17:17:43 +01:00
|
|
|
#include <ecl/geo/geo.h>
|
2017-12-08 19:44:27 +01:00
|
|
|
|
|
|
|
|
using namespace matrix;
|
|
|
|
|
|
2018-05-24 08:51:24 +02:00
|
|
|
bool FlightTaskManualAltitude::updateInitialize()
|
|
|
|
|
{
|
2018-11-05 10:40:46 +01:00
|
|
|
bool ret = FlightTaskManual::updateInitialize();
|
2019-09-30 18:16:36 -04:00
|
|
|
|
2018-11-05 10:40:46 +01:00
|
|
|
// in addition to manual require valid position and velocity in D-direction and valid yaw
|
|
|
|
|
return ret && PX4_ISFINITE(_position(2)) && PX4_ISFINITE(_velocity(2)) && PX4_ISFINITE(_yaw);
|
2018-05-24 08:51:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-15 17:57:40 +02:00
|
|
|
bool FlightTaskManualAltitude::activate(vehicle_local_position_setpoint_s last_setpoint)
|
2018-04-26 11:26:19 +02:00
|
|
|
{
|
2019-07-15 17:57:40 +02:00
|
|
|
bool ret = FlightTaskManual::activate(last_setpoint);
|
2018-11-09 08:25:50 +01:00
|
|
|
_yaw_setpoint = NAN;
|
2020-01-27 17:17:43 +01:00
|
|
|
_yawspeed_setpoint = 0.f;
|
|
|
|
|
_acceleration_setpoint = Vector3f(0.f, 0.f, NAN); // altitude is controlled from position/velocity
|
2018-05-02 11:47:56 +02:00
|
|
|
_position_setpoint(2) = _position(2);
|
2020-01-27 17:17:43 +01:00
|
|
|
_velocity_setpoint(2) = 0.f;
|
2018-04-26 11:26:19 +02:00
|
|
|
_setDefaultConstraints();
|
2018-06-25 07:48:19 +02:00
|
|
|
|
2020-01-15 02:24:41 +01:00
|
|
|
_updateConstraintsFromEstimator();
|
|
|
|
|
|
|
|
|
|
_max_speed_up = _constraints.speed_up;
|
2020-01-17 10:27:43 +01:00
|
|
|
_max_speed_down = _constraints.speed_down;
|
2020-01-15 02:24:41 +01:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlightTaskManualAltitude::_updateConstraintsFromEstimator()
|
|
|
|
|
{
|
2019-09-30 18:16:36 -04:00
|
|
|
if (PX4_ISFINITE(_sub_vehicle_local_position.get().hagl_min)) {
|
|
|
|
|
_constraints.min_distance_to_ground = _sub_vehicle_local_position.get().hagl_min;
|
2018-06-25 07:48:19 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_constraints.min_distance_to_ground = -INFINITY;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-30 18:16:36 -04:00
|
|
|
if (PX4_ISFINITE(_sub_vehicle_local_position.get().hagl_max)) {
|
|
|
|
|
_constraints.max_distance_to_ground = _sub_vehicle_local_position.get().hagl_max;
|
2018-06-25 10:00:08 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_constraints.max_distance_to_ground = INFINITY;
|
|
|
|
|
}
|
2018-04-26 11:26:19 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-29 10:04:47 +01:00
|
|
|
void FlightTaskManualAltitude::_scaleSticks()
|
2017-12-08 19:44:27 +01:00
|
|
|
{
|
2019-11-09 14:20:57 +01:00
|
|
|
// Use stick input with deadzone, exponential curve and first order lpf for yawspeed
|
|
|
|
|
const float yawspeed_target = _sticks_expo(3) * math::radians(_param_mpc_man_y_max.get());
|
|
|
|
|
_yawspeed_setpoint = _applyYawspeedFilter(yawspeed_target);
|
2017-12-29 10:04:47 +01:00
|
|
|
|
2019-11-09 14:20:57 +01:00
|
|
|
// Use sticks input with deadzone and exponential curve for vertical velocity
|
2018-04-26 11:26:19 +02:00
|
|
|
const float vel_max_z = (_sticks(2) > 0.0f) ? _constraints.speed_down : _constraints.speed_up;
|
2018-02-28 10:02:20 +01:00
|
|
|
_velocity_setpoint(2) = vel_max_z * _sticks_expo(2);
|
2017-12-09 13:36:03 +01:00
|
|
|
}
|
2017-12-08 19:44:27 +01:00
|
|
|
|
2019-11-09 14:20:57 +01:00
|
|
|
float FlightTaskManualAltitude::_applyYawspeedFilter(float yawspeed_target)
|
|
|
|
|
{
|
|
|
|
|
const float den = math::max(_param_mpc_man_y_tau.get() + _deltatime, 0.001f);
|
|
|
|
|
const float alpha = _deltatime / den;
|
2019-11-20 10:30:25 +01:00
|
|
|
_yawspeed_filter_state = (1.f - alpha) * _yawspeed_filter_state + alpha * yawspeed_target;
|
|
|
|
|
return _yawspeed_filter_state;
|
2019-11-09 14:20:57 +01:00
|
|
|
}
|
|
|
|
|
|
2018-01-05 10:43:13 +01:00
|
|
|
void FlightTaskManualAltitude::_updateAltitudeLock()
|
2017-12-09 13:36:03 +01:00
|
|
|
{
|
2018-04-25 10:23:40 +02:00
|
|
|
// Depending on stick inputs and velocity, position is locked.
|
|
|
|
|
// If not locked, altitude setpoint is set to NAN.
|
2017-12-22 09:36:46 +01:00
|
|
|
|
2018-07-12 12:00:59 +10:00
|
|
|
// Check if user wants to break
|
2018-09-12 10:25:40 +02:00
|
|
|
const bool apply_brake = fabsf(_sticks_expo(2)) <= FLT_EPSILON;
|
2017-12-22 09:36:46 +01:00
|
|
|
|
2018-07-12 12:00:59 +10:00
|
|
|
// Check if vehicle has stopped
|
2019-03-20 10:28:17 +01:00
|
|
|
const bool stopped = (_param_mpc_hold_max_z.get() < FLT_EPSILON || fabsf(_velocity(2)) < _param_mpc_hold_max_z.get());
|
2018-04-25 10:16:45 +02:00
|
|
|
|
2018-07-12 12:00:59 +10:00
|
|
|
// Manage transition between use of distance to ground and distance to local origin
|
|
|
|
|
// when terrain hold behaviour has been selected.
|
2019-03-20 10:28:17 +01:00
|
|
|
if (_param_mpc_alt_mode.get() == 2) {
|
2018-07-12 12:00:59 +10:00
|
|
|
// Use horizontal speed as a transition criteria
|
2018-10-01 11:39:43 +02:00
|
|
|
float spd_xy = Vector2f(_velocity).length();
|
2018-07-12 12:00:59 +10:00
|
|
|
|
|
|
|
|
// Use presence of horizontal stick inputs as a transition criteria
|
|
|
|
|
float stick_xy = Vector2f(&_sticks_expo(0)).length();
|
|
|
|
|
bool stick_input = stick_xy > 0.001f;
|
2018-07-04 14:35:53 +10:00
|
|
|
|
|
|
|
|
if (_terrain_hold) {
|
2019-03-20 10:28:17 +01:00
|
|
|
bool too_fast = spd_xy > _param_mpc_hold_max_xy.get();
|
2018-07-04 14:35:53 +10:00
|
|
|
|
|
|
|
|
if (stick_input || too_fast || !PX4_ISFINITE(_dist_to_bottom)) {
|
2018-07-12 12:00:59 +10:00
|
|
|
// Stop using distance to ground
|
2018-07-04 14:35:53 +10:00
|
|
|
_terrain_hold = false;
|
|
|
|
|
_terrain_follow = false;
|
|
|
|
|
|
2018-07-12 12:00:59 +10:00
|
|
|
// Adjust the setpoint to maintain the same height error to reduce control transients
|
2018-07-04 14:35:53 +10:00
|
|
|
if (PX4_ISFINITE(_dist_to_ground_lock) && PX4_ISFINITE(_dist_to_bottom)) {
|
2020-02-12 10:46:51 +01:00
|
|
|
_position_setpoint(2) = _position(2) - (_dist_to_ground_lock - _dist_to_bottom);
|
2018-07-04 14:35:53 +10:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_position_setpoint(2) = _position(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2019-03-20 10:28:17 +01:00
|
|
|
bool not_moving = spd_xy < 0.5f * _param_mpc_hold_max_xy.get();
|
2018-07-04 14:35:53 +10:00
|
|
|
|
|
|
|
|
if (!stick_input && not_moving && PX4_ISFINITE(_dist_to_bottom)) {
|
2018-07-12 12:00:59 +10:00
|
|
|
// Start using distance to ground
|
2018-07-04 14:35:53 +10:00
|
|
|
_terrain_hold = true;
|
|
|
|
|
_terrain_follow = true;
|
|
|
|
|
|
2018-07-12 12:00:59 +10:00
|
|
|
// Adjust the setpoint to maintain the same height error to reduce control transients
|
2018-07-04 14:35:53 +10:00
|
|
|
if (PX4_ISFINITE(_position_setpoint(2))) {
|
2020-02-12 10:46:51 +01:00
|
|
|
_dist_to_ground_lock = _dist_to_bottom - (_position_setpoint(2) - _position(2));
|
2018-07-04 14:35:53 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-20 10:28:17 +01:00
|
|
|
if ((_param_mpc_alt_mode.get() == 1 || _terrain_follow) && PX4_ISFINITE(_dist_to_bottom)) {
|
2018-04-25 10:16:45 +02:00
|
|
|
// terrain following
|
2018-06-25 10:00:08 +02:00
|
|
|
_terrainFollowing(apply_brake, stopped);
|
|
|
|
|
// respect maximum altitude
|
|
|
|
|
_respectMaxAltitude();
|
2018-04-25 10:16:45 +02:00
|
|
|
|
|
|
|
|
} else {
|
2018-05-24 18:03:21 +02:00
|
|
|
// normal mode where height is dependent on local frame
|
2018-04-25 10:16:45 +02:00
|
|
|
|
|
|
|
|
if (apply_brake && stopped && !PX4_ISFINITE(_position_setpoint(2))) {
|
|
|
|
|
// lock position
|
|
|
|
|
_position_setpoint(2) = _position(2);
|
2018-05-24 18:03:21 +02:00
|
|
|
|
|
|
|
|
// Ensure that minimum altitude is respected if
|
2018-06-25 10:00:08 +02:00
|
|
|
// there is a distance sensor and distance to bottom is below minimum.
|
2018-06-25 07:48:19 +02:00
|
|
|
if (PX4_ISFINITE(_dist_to_bottom) && _dist_to_bottom < _constraints.min_distance_to_ground) {
|
2018-06-25 10:00:08 +02:00
|
|
|
_terrainFollowing(apply_brake, stopped);
|
2018-05-24 18:03:21 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_dist_to_ground_lock = NAN;
|
|
|
|
|
}
|
2017-12-22 09:36:46 +01:00
|
|
|
|
2018-04-30 09:40:02 +02:00
|
|
|
} else if (PX4_ISFINITE(_position_setpoint(2)) && apply_brake) {
|
|
|
|
|
// Position is locked but check if a reset event has happened.
|
|
|
|
|
// We will shift the setpoints.
|
2019-09-30 18:16:36 -04:00
|
|
|
if (_sub_vehicle_local_position.get().z_reset_counter != _reset_counter) {
|
2018-04-30 09:40:02 +02:00
|
|
|
_position_setpoint(2) = _position(2);
|
2019-09-30 18:16:36 -04:00
|
|
|
_reset_counter = _sub_vehicle_local_position.get().z_reset_counter;
|
2018-04-30 09:40:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
2018-04-25 10:16:45 +02:00
|
|
|
// user demands velocity change
|
|
|
|
|
_position_setpoint(2) = NAN;
|
2018-06-25 10:00:08 +02:00
|
|
|
// ensure that maximum altitude is respected
|
|
|
|
|
_respectMaxAltitude();
|
2018-04-18 17:24:11 +02:00
|
|
|
}
|
2018-04-25 10:16:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlightTaskManualAltitude::_respectMinAltitude()
|
|
|
|
|
{
|
2018-06-25 07:48:19 +02:00
|
|
|
const bool respectAlt = PX4_ISFINITE(_dist_to_bottom)
|
|
|
|
|
&& _dist_to_bottom < _constraints.min_distance_to_ground;
|
2018-04-25 10:16:45 +02:00
|
|
|
|
|
|
|
|
// Height above ground needs to be limited (flow / range-finder)
|
|
|
|
|
if (respectAlt) {
|
|
|
|
|
// increase altitude to minimum flow distance
|
|
|
|
|
_position_setpoint(2) = _position(2)
|
2018-06-25 07:48:19 +02:00
|
|
|
- (_constraints.min_distance_to_ground - _dist_to_bottom);
|
2017-12-08 19:44:27 +01:00
|
|
|
}
|
2017-12-09 13:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-25 10:00:08 +02:00
|
|
|
void FlightTaskManualAltitude::_terrainFollowing(bool apply_brake, bool stopped)
|
2018-04-25 10:16:45 +02:00
|
|
|
{
|
|
|
|
|
if (apply_brake && stopped && !PX4_ISFINITE(_dist_to_ground_lock)) {
|
2018-04-25 10:23:40 +02:00
|
|
|
// User wants to break and vehicle reached zero velocity. Lock height to ground.
|
2018-04-25 10:16:45 +02:00
|
|
|
|
|
|
|
|
// lock position
|
|
|
|
|
_position_setpoint(2) = _position(2);
|
|
|
|
|
// ensure that minimum altitude is respected
|
|
|
|
|
_respectMinAltitude();
|
|
|
|
|
// lock distance to ground but adjust first for minimum altitude
|
|
|
|
|
_dist_to_ground_lock = _dist_to_bottom - (_position_setpoint(2) - _position(2));
|
|
|
|
|
|
|
|
|
|
} else if (apply_brake && PX4_ISFINITE(_dist_to_ground_lock)) {
|
|
|
|
|
// vehicle needs to follow terrain
|
|
|
|
|
|
|
|
|
|
// difference between the current distance to ground and the desired distance to ground
|
|
|
|
|
const float delta_distance_to_ground = _dist_to_ground_lock - _dist_to_bottom;
|
|
|
|
|
// adjust position setpoint for the delta (note: NED frame)
|
|
|
|
|
_position_setpoint(2) = _position(2) - delta_distance_to_ground;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// user demands velocity change in D-direction
|
|
|
|
|
_dist_to_ground_lock = _position_setpoint(2) = NAN;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-25 10:00:08 +02:00
|
|
|
|
|
|
|
|
void FlightTaskManualAltitude::_respectMaxAltitude()
|
|
|
|
|
{
|
|
|
|
|
if (PX4_ISFINITE(_dist_to_bottom)) {
|
|
|
|
|
|
2018-07-04 14:35:53 +10:00
|
|
|
// if there is a valid maximum distance to ground, linearly increase speed limit with distance
|
|
|
|
|
// below the maximum, preserving control loop vertical position error gain.
|
2018-06-25 10:00:08 +02:00
|
|
|
if (PX4_ISFINITE(_constraints.max_distance_to_ground)) {
|
2019-03-20 10:28:17 +01:00
|
|
|
_constraints.speed_up = math::constrain(_param_mpc_z_p.get() * (_constraints.max_distance_to_ground - _dist_to_bottom),
|
2020-01-17 10:27:43 +01:00
|
|
|
-_max_speed_down, _max_speed_up);
|
2018-06-25 10:00:08 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_constraints.speed_up = _max_speed_up;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if distance to bottom exceeded maximum distance, slowly approach maximum distance
|
|
|
|
|
if (_dist_to_bottom > _constraints.max_distance_to_ground) {
|
|
|
|
|
// difference between current distance to ground and maximum distance to ground
|
|
|
|
|
const float delta_distance_to_max = _dist_to_bottom - _constraints.max_distance_to_ground;
|
|
|
|
|
// set position setpoint to maximum distance to ground
|
|
|
|
|
_position_setpoint(2) = _position(2) + delta_distance_to_max;
|
|
|
|
|
// limit speed downwards to 0.7m/s
|
2020-01-17 10:27:43 +01:00
|
|
|
_constraints.speed_down = math::min(_max_speed_down, 0.7f);
|
2018-06-25 10:00:08 +02:00
|
|
|
|
|
|
|
|
} else {
|
2020-01-17 10:27:43 +01:00
|
|
|
_constraints.speed_down = _max_speed_down;
|
2018-06-25 10:00:08 +02:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 15:43:25 +01:00
|
|
|
void FlightTaskManualAltitude::_respectGroundSlowdown()
|
|
|
|
|
{
|
2019-03-01 22:51:46 +01:00
|
|
|
// limit speed gradually within the altitudes MPC_LAND_ALT1 and MPC_LAND_ALT2
|
2019-11-21 18:20:13 +01:00
|
|
|
if (PX4_ISFINITE(_dist_to_ground)) {
|
|
|
|
|
const float limit_down = math::gradual(_dist_to_ground,
|
2019-03-20 10:28:17 +01:00
|
|
|
_param_mpc_land_alt2.get(), _param_mpc_land_alt1.get(),
|
|
|
|
|
_param_mpc_land_speed.get(), _constraints.speed_down);
|
2019-11-21 18:20:13 +01:00
|
|
|
const float limit_up = math::gradual(_dist_to_ground,
|
2019-03-20 10:28:17 +01:00
|
|
|
_param_mpc_land_alt2.get(), _param_mpc_land_alt1.get(),
|
|
|
|
|
_param_mpc_tko_speed.get(), _constraints.speed_up);
|
2019-03-01 22:51:46 +01:00
|
|
|
_velocity_setpoint(2) = math::constrain(_velocity_setpoint(2), -limit_up, limit_down);
|
2019-02-25 15:43:25 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 10:40:46 +01:00
|
|
|
void FlightTaskManualAltitude::_rotateIntoHeadingFrame(Vector2f &v)
|
|
|
|
|
{
|
|
|
|
|
float yaw_rotate = PX4_ISFINITE(_yaw_setpoint) ? _yaw_setpoint : _yaw;
|
|
|
|
|
Vector3f v_r = Vector3f(Dcmf(Eulerf(0.0f, 0.0f, yaw_rotate)) * Vector3f(v(0), v(1), 0.0f));
|
|
|
|
|
v(0) = v_r(0);
|
|
|
|
|
v(1) = v_r(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlightTaskManualAltitude::_updateHeadingSetpoints()
|
|
|
|
|
{
|
2019-11-09 14:20:57 +01:00
|
|
|
if (_isYawInput()) {
|
|
|
|
|
_unlockYaw();
|
2018-11-05 10:40:46 +01:00
|
|
|
|
|
|
|
|
} else {
|
2019-11-09 14:20:57 +01:00
|
|
|
_lockYaw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FlightTaskManualAltitude::_isYawInput()
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* A threshold larger than FLT_EPSILON is required because the
|
|
|
|
|
* _yawspeed_setpoint comes from an IIR filter and takes too much
|
|
|
|
|
* time to reach zero.
|
|
|
|
|
*/
|
|
|
|
|
return fabsf(_yawspeed_setpoint) > 0.001f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlightTaskManualAltitude::_unlockYaw()
|
|
|
|
|
{
|
|
|
|
|
// no fixed heading when rotating around yaw by stick
|
|
|
|
|
_yaw_setpoint = NAN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlightTaskManualAltitude::_lockYaw()
|
|
|
|
|
{
|
|
|
|
|
// hold the current heading when no more rotation commanded
|
|
|
|
|
if (!PX4_ISFINITE(_yaw_setpoint)) {
|
|
|
|
|
_yaw_setpoint = _yaw;
|
2018-11-05 10:40:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 13:42:06 +02:00
|
|
|
void FlightTaskManualAltitude::_ekfResetHandlerHeading(float delta_psi)
|
|
|
|
|
{
|
|
|
|
|
// Only reset the yaw setpoint when the heading is locked
|
|
|
|
|
if (PX4_ISFINITE(_yaw_setpoint)) {
|
|
|
|
|
_yaw_setpoint += delta_psi;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-29 10:04:47 +01:00
|
|
|
void FlightTaskManualAltitude::_updateSetpoints()
|
2017-12-09 13:36:03 +01:00
|
|
|
{
|
2018-11-05 10:40:46 +01:00
|
|
|
_updateHeadingSetpoints(); // get yaw setpoint
|
2018-02-15 11:12:24 +01:00
|
|
|
|
2018-04-25 10:23:40 +02:00
|
|
|
// Thrust in xy are extracted directly from stick inputs. A magnitude of
|
|
|
|
|
// 1 means that maximum thrust along xy is demanded. A magnitude of 0 means no
|
|
|
|
|
// thrust along xy is demanded. The maximum thrust along xy depends on the thrust
|
|
|
|
|
// setpoint along z-direction, which is computed in PositionControl.cpp.
|
|
|
|
|
|
2018-10-01 11:39:43 +02:00
|
|
|
Vector2f sp(&_sticks(0));
|
2018-02-22 08:33:48 +01:00
|
|
|
_rotateIntoHeadingFrame(sp);
|
2018-01-09 08:58:35 +01:00
|
|
|
|
|
|
|
|
if (sp.length() > 1.0f) {
|
|
|
|
|
sp.normalize();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 17:17:43 +01:00
|
|
|
_acceleration_setpoint.xy() = sp * tanf(math::radians(_param_mpc_man_tilt_max.get())) * CONSTANTS_ONE_G;
|
2018-01-09 08:58:35 +01:00
|
|
|
|
2018-02-15 11:12:24 +01:00
|
|
|
_updateAltitudeLock();
|
2019-02-25 15:43:25 +01:00
|
|
|
_respectGroundSlowdown();
|
2017-12-08 19:44:27 +01:00
|
|
|
}
|
2018-11-05 10:40:46 +01:00
|
|
|
|
2019-05-13 21:07:05 +02:00
|
|
|
bool FlightTaskManualAltitude::_checkTakeoff()
|
|
|
|
|
{
|
2019-05-22 15:38:00 +01:00
|
|
|
// stick is deflected above 65% throttle (_sticks(2) is in the range [-1,1])
|
2019-05-13 21:07:05 +02:00
|
|
|
return _sticks(2) < -0.3f;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-05 10:40:46 +01:00
|
|
|
bool FlightTaskManualAltitude::update()
|
|
|
|
|
{
|
2020-01-15 02:24:41 +01:00
|
|
|
_updateConstraintsFromEstimator();
|
2018-11-05 10:40:46 +01:00
|
|
|
_scaleSticks();
|
|
|
|
|
_updateSetpoints();
|
2019-05-13 21:07:05 +02:00
|
|
|
_constraints.want_takeoff = _checkTakeoff();
|
2018-11-05 10:40:46 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|