Skip to content

Commit

Permalink
FlightTaskManualAltitude: replace 0 check with FLT_EPSILON
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Mannhart committed Sep 17, 2018
1 parent e332165 commit f2a0fd2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/lib/FlightTasks/tasks/Manual/FlightTaskManual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ bool FlightTaskManual::_evaluateSticks()
/* Sticks are rescaled linearly and exponentially to [-1,1] */
if ((_time_stamp_current - _sub_manual_control_setpoint->get().timestamp) < rc_timeout) {

/* Linear scale */
// Linear scale
_sticks(0) = _sub_manual_control_setpoint->get().x; /* NED x, "pitch" [-1,1] */
_sticks(1) = _sub_manual_control_setpoint->get().y; /* NED y, "roll" [-1,1] */
_sticks(2) = -(_sub_manual_control_setpoint->get().z - 0.5f) * 2.f; /* NED z, "thrust" resacaled from [0,1] to [-1,1] */
_sticks(3) = _sub_manual_control_setpoint->get().r; /* "yaw" [-1,1] */

/* Exponential scale */
_sticks_expo(0) = math::expo_deadzone(_sticks(0), _xy_vel_man_expo.get(), _stick_dz.get());
_sticks_expo(1) = math::expo_deadzone(_sticks(1), _xy_vel_man_expo.get(), _stick_dz.get());
_sticks_expo(2) = math::expo_deadzone(_sticks(2), _z_vel_man_expo.get(), _stick_dz.get());
_sticks_expo(3) = math::expo_deadzone(_sticks(3), _yaw_expo.get(), _stick_dz.get());
// Exponential scale
_sticks_expo(0) = math::expo_deadzone(_sticks(0), _xy_vel_man_expo.get(), MPC_HOLD_DZ.get());
_sticks_expo(1) = math::expo_deadzone(_sticks(1), _xy_vel_man_expo.get(), MPC_HOLD_DZ.get());
_sticks_expo(2) = math::expo_deadzone(_sticks(2), _z_vel_man_expo.get(), MPC_HOLD_DZ.get());
_sticks_expo(3) = math::expo_deadzone(_sticks(3), _yaw_expo.get(), MPC_HOLD_DZ.get());

// Only switch the landing gear up if the user switched from gear down to gear up.
// If the user had the switch in the gear up position and took off ignore it
Expand Down
4 changes: 2 additions & 2 deletions src/lib/FlightTasks/tasks/Manual/FlightTaskManual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FlightTaskManual : public FlightTask
matrix::Vector<float, 4> _sticks; /**< unmodified manual stick inputs */
matrix::Vector<float, 4> _sticks_expo; /**< modified manual sticks using expo function*/

float stickDeadzone() const { return _stick_dz.get(); }
float stickDeadzone() const { return MPC_HOLD_DZ.get(); }

private:

Expand All @@ -70,7 +70,7 @@ class FlightTaskManual : public FlightTask
uORB::Subscription<manual_control_setpoint_s> *_sub_manual_control_setpoint{nullptr};

DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTask,
(ParamFloat<px4::params::MPC_HOLD_DZ>) _stick_dz, /**< 0-deadzone around the center for the sticks */
(ParamFloat<px4::params::MPC_HOLD_DZ>) MPC_HOLD_DZ, /**< 0-deadzone around the center for the sticks */
(ParamFloat<px4::params::MPC_XY_MAN_EXPO>)
_xy_vel_man_expo, /**< ratio of exponential curve for stick input in xy direction */
(ParamFloat<px4::params::MPC_Z_MAN_EXPO>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ void FlightTaskManualAltitude::_scaleSticks()
FlightTaskManualStabilized::_scaleSticks();

// scale horizontal velocity with expo curve stick input
const float vel_max_z = (_sticks(2) > 0.0f) ? _constraints.speed_down : _constraints.speed_up;
float vel_max_z = (_sticks_expo(2) > FLT_EPSILON) ? _constraints.speed_down : _constraints.speed_up;
_velocity_setpoint(2) = vel_max_z * _sticks_expo(2);

// if there is a valid distance to bottom or distance to home, then
// adjust speed downwards gradually within the limits MPC_LAND_ALT1 and MPC_LAND_ALT2.
if (_sticks(2) > 0.0f) { //user demands speed downwards
if (_sticks_expo(2) > FLT_EPSILON) { //user demands speed downwards

float dist_to_ground = NAN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FlightTaskManualAltitude : public FlightTaskManualStabilized
(ParamFloat<px4::params::MPC_HOLD_MAX_Z>) MPC_HOLD_MAX_Z,
(ParamInt<px4::params::MPC_ALT_MODE>) MPC_ALT_MODE,
(ParamFloat<px4::params::MPC_HOLD_MAX_XY>) MPC_HOLD_MAX_XY,
(ParamFloat<px4::params::MPC_Z_P>) MPC_Z_P
(ParamFloat<px4::params::MPC_Z_P>) MPC_Z_P,
(ParamFloat<px4::params::MPC_LAND_ALT1>) MPC_LAND_ALT1, // altitude at which speed limit downwards reaches maximum speed
(ParamFloat<px4::params::MPC_LAND_ALT2>) MPC_LAND_ALT2, // altitude at which speed limit downwards reached minimum speed
(ParamFloat<px4::params::MPC_LAND_SPEED>) MPC_LAND_SPEED
Expand Down

0 comments on commit f2a0fd2

Please sign in to comment.