From f2c973e699a09b4cbd10d5e60e75111c96a3daae Mon Sep 17 00:00:00 2001 From: Silvan Fuhrer Date: Thu, 8 Dec 2022 11:44:07 +0100 Subject: [PATCH] FW Att C: add sys ID ramps for pitch and throttle Signed-off-by: Silvan Fuhrer --- .../FixedwingAttitudeControl.cpp | 27 +++++++++++++++++-- .../FixedwingAttitudeControl.hpp | 9 +++++-- .../fw_att_control/fw_att_control_params.c | 13 +++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/modules/fw_att_control/FixedwingAttitudeControl.cpp b/src/modules/fw_att_control/FixedwingAttitudeControl.cpp index b57df7962bb7..554f353cf7b4 100644 --- a/src/modules/fw_att_control/FixedwingAttitudeControl.cpp +++ b/src/modules/fw_att_control/FixedwingAttitudeControl.cpp @@ -85,7 +85,7 @@ FixedwingAttitudeControl::parameters_update() } void -FixedwingAttitudeControl::vehicle_manual_poll(const float yaw_body) +FixedwingAttitudeControl::vehicle_manual_poll(const float yaw_body, const float dt) { if (_vcontrol_mode.flag_control_manual_enabled && _in_fw_or_transition_wo_tailsitter_transition) { @@ -106,6 +106,29 @@ FixedwingAttitudeControl::vehicle_manual_poll(const float yaw_body) _att_sp.yaw_body = yaw_body; // yaw is not controlled, so set setpoint to current yaw _att_sp.thrust_body[0] = (_manual_control_setpoint.throttle + 1.f) * .5f; + if (_param_sysid_ramp_en.get() == 1 && _manual_control_setpoint.aux1 > 0.8f) { // use .yaw if aux1 is unavailabe + const float pitch_ramp_gradient = radians(0.8f); // 0.8deg/s ramp gradient + _att_sp.pitch_body = _pitch_ramp_last - pitch_ramp_gradient * dt; + _att_sp.thrust_body[0] = 0.f; // gliding + _pitch_ramp_last = _att_sp.pitch_body; + + } else if (_param_sysid_ramp_en.get() == 2 && _manual_control_setpoint.aux1 > 0.8f) { // use .yaw if aux1 is unavailabe + const float pitch_ramp_gradient = radians(0.8f); // 0.8deg/s ramp gradient + _att_sp.pitch_body = _pitch_ramp_last + pitch_ramp_gradient * dt; + _att_sp.thrust_body[0] = 0.f; // gliding + _pitch_ramp_last = _att_sp.pitch_body; + + } else if (_param_sysid_ramp_en.get() == 3 && _manual_control_setpoint.aux1 > 0.8f) { + const float throttle_ramp_gradient = 2.f; // %/s throttle gradient + _att_sp.thrust_body[0] = _throttle_ramp_last + throttle_ramp_gradient * 0.01f * dt; + _att_sp.pitch_body = radians(_param_fw_psp_off.get()); // set pitch set to trim pitch + _throttle_ramp_last = _att_sp.thrust_body[0]; + + } else { + _pitch_ramp_last = _att_sp.pitch_body; + _throttle_ramp_last = _manual_control_setpoint.throttle; + } + Quatf q(Eulerf(_att_sp.roll_body, _att_sp.pitch_body, _att_sp.yaw_body)); q.copyTo(_att_sp.q_d); @@ -258,7 +281,7 @@ void FixedwingAttitudeControl::Run() const matrix::Eulerf euler_angles(_R); - vehicle_manual_poll(euler_angles.psi()); + vehicle_manual_poll(euler_angles.psi(), dt); vehicle_attitude_setpoint_poll(); diff --git a/src/modules/fw_att_control/FixedwingAttitudeControl.hpp b/src/modules/fw_att_control/FixedwingAttitudeControl.hpp index 63bb8cbd9339..9cd764b8f78f 100644 --- a/src/modules/fw_att_control/FixedwingAttitudeControl.hpp +++ b/src/modules/fw_att_control/FixedwingAttitudeControl.hpp @@ -130,6 +130,9 @@ class FixedwingAttitudeControl final : public ModuleBase) _param_fw_airspd_max, (ParamFloat) _param_fw_airspd_min, @@ -155,7 +158,9 @@ class FixedwingAttitudeControl final : public ModuleBase) _param_fw_wr_imax, (ParamFloat) _param_fw_wr_p, - (ParamFloat) _param_fw_y_rmax + (ParamFloat) _param_fw_y_rmax, + + (ParamInt) _param_sysid_ramp_en ) ECL_RollController _roll_ctrl; @@ -164,7 +169,7 @@ class FixedwingAttitudeControl final : public ModuleBase