diff --git a/src/modules/vtol_att_control/tailsitter.cpp b/src/modules/vtol_att_control/tailsitter.cpp index 8b159d24818..6cd7622193b 100644 --- a/src/modules/vtol_att_control/tailsitter.cpp +++ b/src/modules/vtol_att_control/tailsitter.cpp @@ -56,6 +56,48 @@ Tailsitter::parameters_update() } +Eulerf Tailsitter::getFixedWingAttitudeEuler() const +{ + // Tailsitter attitude is estimated in MC frame; rotate it to FW frame before checking FW limits. + return Eulerf(Quatf(_v_att->q) * _q_fw_to_mc); +} + +bool Tailsitter::isPitchExceeded() +{ + if (_common_vtol_mode != mode::FIXED_WING) { + return false; + } + + // fixed-wing maximum pitch angle + if (_param_vt_fw_qc_p.get() > 0) { + const Eulerf euler = getFixedWingAttitudeEuler(); + + if (fabsf(euler.theta()) > fabsf(math::radians(static_cast(_param_vt_fw_qc_p.get())))) { + return true; + } + } + + return false; +} + +bool Tailsitter::isRollExceeded() +{ + if (_common_vtol_mode != mode::FIXED_WING) { + return false; + } + + // fixed-wing maximum roll angle + if (_param_vt_fw_qc_r.get() > 0) { + const Eulerf euler = getFixedWingAttitudeEuler(); + + if (fabsf(euler.phi()) > fabsf(math::radians(static_cast(_param_vt_fw_qc_r.get())))) { + return true; + } + } + + return false; +} + void Tailsitter::update_vtol_state() { /* simple logic using a two way switch to perform transitions. diff --git a/src/modules/vtol_att_control/tailsitter.h b/src/modules/vtol_att_control/tailsitter.h index 135acd6c92a..f26f0be2a5d 100644 --- a/src/modules/vtol_att_control/tailsitter.h +++ b/src/modules/vtol_att_control/tailsitter.h @@ -88,9 +88,15 @@ private: matrix::Quatf _q_trans_sp; matrix::Vector3f _trans_rot_axis; + inline static const matrix::Quatf _q_fw_to_mc{matrix::Eulerf{0.f, M_PI_2_F, 0.f}}; + void parameters_update() override; bool isFrontTransitionCompletedBase() override; + bool isPitchExceeded() override; + bool isRollExceeded() override; + + matrix::Eulerf getFixedWingAttitudeEuler() const; DEFINE_PARAMETERS_CUSTOM_PARENT(VtolType, (ParamFloat) _param_fw_psp_off diff --git a/src/modules/vtol_att_control/vtol_type.h b/src/modules/vtol_att_control/vtol_type.h index 69d1bed6f4d..1709753bf3f 100644 --- a/src/modules/vtol_att_control/vtol_type.h +++ b/src/modules/vtol_att_control/vtol_type.h @@ -182,14 +182,14 @@ public: * * @return true if exeeded */ - bool isPitchExceeded(); + virtual bool isPitchExceeded(); /** * @brief Indicates if the absolute value of the vehicle roll angle exceeds the threshold defined by VT_FW_QC_R * * @return true if exeeded */ - bool isRollExceeded(); + virtual bool isRollExceeded(); /** * @brief Indicates if the front transition duration has exceeded the timeout definded by VT_TRANS_TIMEOUT