diff --git a/src/modules/vtol_att_control/tiltrotor.cpp b/src/modules/vtol_att_control/tiltrotor.cpp index ea218f3d8b..7648856742 100644 --- a/src/modules/vtol_att_control/tiltrotor.cpp +++ b/src/modules/vtol_att_control/tiltrotor.cpp @@ -70,6 +70,8 @@ Tiltrotor::Tiltrotor(VtolAttitudeControl *attc) : _params_handles_tiltrotor.front_trans_dur_p2 = param_find("VT_TRANS_P2_DUR"); _params_handles_tiltrotor.fw_motors_off = param_find("VT_FW_MOT_OFFID"); _params_handles_tiltrotor.airspeed_mode = param_find("FW_ARSP_MODE"); + _params_handles_tiltrotor.diff_thrust = param_find("VT_FW_DIFTHR_EN"); + _params_handles_tiltrotor.diff_thrust_scale = param_find("VT_FW_DIFTHR_SC"); } Tiltrotor::~Tiltrotor() @@ -134,6 +136,11 @@ Tiltrotor::parameters_update() /* airspeed mode */ param_get(_params_handles_tiltrotor.airspeed_mode, &l); _params_tiltrotor.airspeed_mode = math::constrain(l, 0, 2); + + param_get(_params_handles_tiltrotor.diff_thrust, &_params_tiltrotor.diff_thrust); + + param_get(_params_handles_tiltrotor.diff_thrust_scale, &v); + _params_tiltrotor.diff_thrust_scale = math::constrain(v, -1.0f, 1.0f); } int Tiltrotor::get_motor_off_channels(int channels) @@ -425,6 +432,12 @@ void Tiltrotor::fill_actuator_outputs() _actuators_out_0->control[actuator_controls_s::INDEX_THROTTLE] = _actuators_fw_in->control[actuator_controls_s::INDEX_THROTTLE]; + /* allow differential thrust if enabled */ + if (_params_tiltrotor.diff_thrust == 1) { + _actuators_out_0->control[actuator_controls_s::INDEX_ROLL] = + _actuators_fw_in->control[actuator_controls_s::INDEX_YAW] * _params_tiltrotor.diff_thrust_scale; + } + } else { _actuators_out_0->control[actuator_controls_s::INDEX_THROTTLE] = _actuators_mc_in->control[actuator_controls_s::INDEX_THROTTLE];; diff --git a/src/modules/vtol_att_control/tiltrotor.h b/src/modules/vtol_att_control/tiltrotor.h index 39363a7744..3d791db8ea 100644 --- a/src/modules/vtol_att_control/tiltrotor.h +++ b/src/modules/vtol_att_control/tiltrotor.h @@ -73,6 +73,8 @@ private: float front_trans_dur_p2; int fw_motors_off; /**< bitmask of all motors that should be off in fixed wing mode */ int airspeed_mode; + int diff_thrust; + float diff_thrust_scale; } _params_tiltrotor; struct { @@ -87,6 +89,8 @@ private: param_t front_trans_dur_p2; param_t fw_motors_off; param_t airspeed_mode; + param_t diff_thrust; + param_t diff_thrust_scale; } _params_handles_tiltrotor; enum vtol_mode { diff --git a/src/modules/vtol_att_control/tiltrotor_params.c b/src/modules/vtol_att_control/tiltrotor_params.c index bbd5ec3e7d..6f4cb7bb45 100644 --- a/src/modules/vtol_att_control/tiltrotor_params.c +++ b/src/modules/vtol_att_control/tiltrotor_params.c @@ -98,3 +98,28 @@ PARAM_DEFINE_FLOAT(VT_TRANS_P2_DUR, 0.5f); * @group VTOL Attitude Control */ PARAM_DEFINE_INT32(VT_FW_MOT_OFFID, 0); + +/** + * Differential thrust in forwards flight. + * + * Set to 1 to enable differential thrust in fixed-wing flight. + * + * @min 0 + * @max 1 + * @decimal 0 + * @group VTOL Attitude Control + */ +PARAM_DEFINE_INT32(VT_FW_DIFTHR_EN, 0); + +/** + * Differential thrust scaling factor + * + * This factor specifies how the yaw input gets mapped to differential thrust in forwards flight. + * + * @min 0.0 + * @max 1.0 + * @decimal 2 + * @increment 0.1 + * @group VTOL Attitude Control + */ +PARAM_DEFINE_FLOAT(VT_FW_DIFTHR_SC, 0.1f);