Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not handle yaw stick multiple times in Altitude and Position mode #21781

Merged
merged 3 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ bool FlightTaskManualAcceleration::update()
{
bool ret = FlightTaskManualAltitudeSmoothVel::update();

_stick_yaw.generateYawSetpoint(_yawspeed_setpoint, _yaw_setpoint, _sticks.getYawExpo(), _yaw, _is_yaw_good_for_control,
_deltatime);

_stick_acceleration_xy.generateSetpoints(_sticks.getPitchRollExpo(), _yaw, _yaw_setpoint, _position,
_velocity_setpoint_feedback.xy(), _deltatime);
_stick_acceleration_xy.getSetpoints(_position_setpoint, _velocity_setpoint, _acceleration_setpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,5 @@ class FlightTaskManualAcceleration : public FlightTaskManualAltitudeSmoothVel
void _ekfResetHandlerVelocityXY(const matrix::Vector2f &delta_vxy) override;

StickAccelerationXY _stick_acceleration_xy{this};
StickYaw _stick_yaw{this};

WeatherVane _weathervane{this}; /**< weathervane library, used to implement a yaw control law that turns the vehicle nose into the wind */
};
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ void FlightTaskManualAltitude::_updateConstraintsFromEstimator()

void FlightTaskManualAltitude::_scaleSticks()
{
// Use stick input with deadzone, exponential curve and first order lpf for yawspeed
_stick_yaw.generateYawSetpoint(_yawspeed_setpoint, _yaw_setpoint, _sticks.getYawExpo(), _yaw,
_is_yaw_good_for_control, _deltatime);

// Use sticks input with deadzone and exponential curve for vertical velocity
const float vel_max_z = (_sticks.getPosition()(2) > 0.0f) ? _param_mpc_z_vel_max_dn.get() :
_param_mpc_z_vel_max_up.get();
Expand Down Expand Up @@ -273,40 +269,6 @@ void FlightTaskManualAltitude::_respectGroundSlowdown()
}
}

void FlightTaskManualAltitude::_updateHeadingSetpoints()
{
if (_isYawInput() || !_is_yaw_good_for_control) {
_unlockYaw();

} else {
_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;
}
}

void FlightTaskManualAltitude::_ekfResetHandlerHeading(float delta_psi)
{
// Only reset the yaw setpoint when the heading is locked
Expand All @@ -317,7 +279,8 @@ void FlightTaskManualAltitude::_ekfResetHandlerHeading(float delta_psi)

void FlightTaskManualAltitude::_updateSetpoints()
{
_updateHeadingSetpoints(); // get yaw setpoint
_stick_yaw.generateYawSetpoint(_yawspeed_setpoint, _yaw_setpoint, _sticks.getYawExpo(), _yaw,
_is_yaw_good_for_control, _deltatime);
_acceleration_setpoint.xy() = _stick_tilt_xy.generateAccelerationSetpoints(_sticks.getPitchRoll(), _deltatime, _yaw,
_yaw_setpoint);
_updateAltitudeLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class FlightTaskManualAltitude : public FlightTask
bool update() override;

protected:
void _updateHeadingSetpoints(); /**< sets yaw or yaw speed */
void _ekfResetHandlerHeading(float delta_psi) override; /**< adjust heading setpoint in case of EKF reset event */
virtual void _updateSetpoints(); /**< updates all setpoints */
virtual void _scaleSticks(); /**< scales sticks to velocity in z */
Expand Down Expand Up @@ -89,10 +88,6 @@ class FlightTaskManualAltitude : public FlightTask
_param_mpc_tko_speed /**< desired upwards speed when still close to the ground */
)
private:
bool _isYawInput();
void _unlockYaw();
void _lockYaw();

/**
* Terrain following.
* During terrain following, the position setpoint is adjusted
Expand Down
16 changes: 8 additions & 8 deletions src/modules/mc_pos_control/multicopter_altitude_mode_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@
* Maximum upwards acceleration in climb rate controlled modes
*
* @unit m/s^2
* @min 2.0
* @max 15.0
* @min 2
* @max 15
* @decimal 1
* @increment 1
* @group Multicopter Position Control
*/
PARAM_DEFINE_FLOAT(MPC_ACC_UP_MAX, 4.0f);
PARAM_DEFINE_FLOAT(MPC_ACC_UP_MAX, 4.f);

/**
* Maximum downwards acceleration in climb rate controlled modes
*
* @unit m/s^2
* @min 2.0
* @max 15.0
* @min 2
* @max 15
* @decimal 1
* @increment 1
* @group Multicopter Position Control
*/
PARAM_DEFINE_FLOAT(MPC_ACC_DOWN_MAX, 3.0f);
PARAM_DEFINE_FLOAT(MPC_ACC_DOWN_MAX, 3.f);

/**
* Manual yaw rate input filter time constant
Expand All @@ -62,8 +62,8 @@ PARAM_DEFINE_FLOAT(MPC_ACC_DOWN_MAX, 3.0f);
* Setting this parameter to 0 disables the filter
*
* @unit s
* @min 0.0
* @max 5.0
* @min 0
* @max 5
* @decimal 2
* @increment 0.01
* @group Multicopter Position Control
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ PARAM_DEFINE_INT32(MPC_USE_HTE, 1);
* To avoid completely starving horizontal control with high vertical error.
*
* @unit norm
* @min 0.0
* @min 0
* @max 0.5
* @decimal 2
* @increment 0.01
Expand All @@ -78,7 +78,7 @@ PARAM_DEFINE_FLOAT(MPC_THR_XY_MARG, 0.3f);
* Numerical velocity derivative low pass cutoff frequency
*
* @unit Hz
* @min 0.0
* @min 0
* @max 10
* @decimal 1
* @increment 0.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ PARAM_DEFINE_FLOAT(MPC_MAN_Y_MAX, 150.f);
* Airmode is used to keep torque authority with zero thrust (see MC_AIRMODE).
*
* @unit norm
* @min 0.0
* @max 1.0
* @min 0
* @max 1
* @decimal 2
* @increment 0.01
* @group Multicopter Position Control
Expand Down
Loading