diff --git a/src/lib/control_allocation/actuator_effectiveness/ActuatorEffectiveness.hpp b/src/lib/control_allocation/actuator_effectiveness/ActuatorEffectiveness.hpp index b901d44a218..c6ff85e1613 100644 --- a/src/lib/control_allocation/actuator_effectiveness/ActuatorEffectiveness.hpp +++ b/src/lib/control_allocation/actuator_effectiveness/ActuatorEffectiveness.hpp @@ -221,6 +221,15 @@ public: */ virtual void stopMaskedMotorsWithZeroThrust(ActuatorBitmask stoppable_motors_mask, ActuatorVector &actuator_sp); + /** + * Override the collective tilt setpoint that would normally come from + * tiltrotor_extra_controls. Base implementation is a no-op. + * + * @param do_override When true, use @p collective_tilt instead of the uORB value. + * @param collective_tilt Normalised setpoint in [0, 1]. 0: vertical, 1: horizontal. + */ + virtual void overrideCollectiveTilt(bool /*do_override*/, float /*collective_tilt*/) {} + protected: FlightPhase _flight_phase{FlightPhase::HOVER_FLIGHT}; ActuatorBitmask _stopped_motors_mask{0}; diff --git a/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTiltrotorVTOL.cpp b/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTiltrotorVTOL.cpp index 3042ab825b4..0699165ff80 100644 --- a/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTiltrotorVTOL.cpp +++ b/src/modules/control_allocator/VehicleActuatorEffectiveness/ActuatorEffectivenessTiltrotorVTOL.cpp @@ -124,14 +124,45 @@ void ActuatorEffectivenessTiltrotorVTOL::allocateAuxilaryControls(const float dt } +void ActuatorEffectivenessTiltrotorVTOL::overrideCollectiveTilt(bool do_override, float collective_tilt) +{ + // When set, updateSetpoint() takes the collective tilt from + // _collective_tilt_normalized_setpoint instead of the uORB message and + // drives the tilt actuators even when motors are not yet spooled up. Used + // by the actuator-group preflight check. + + // TODO: revise. This is a pretty hacky way to pass around the + // collective tilt setpoint. + + // The main flaw is that overrideCollectiveTilt(false, ...) is + // explicitly needed to clear the override. + + // Ideally we would send a separate tiltrotor_extra_controls style + // message that contains a flag which enables the necessary override + // here, and stop the override if only the usual tiltrotor controls + // arrive. + + // But tiltrotor_extra_controls is a hack in the first place and I am + // noting this technical debt for the time when it is replaced by a + // better way. + + _do_override_collective_tilt = do_override; + _collective_tilt_normalized_setpoint = collective_tilt; +} + void ActuatorEffectivenessTiltrotorVTOL::updateSetpoint(const matrix::Vector &control_sp, int matrix_index, ActuatorVector &actuator_sp, const ActuatorVector &actuator_min, const ActuatorVector &actuator_max) { // apply tilt if (matrix_index == 0) { - tiltrotor_extra_controls_s tiltrotor_extra_controls; + tiltrotor_extra_controls_s tiltrotor_extra_controls{}; + const bool has_tiltrotor_extra_controls = _tiltrotor_extra_controls_sub.copy(&tiltrotor_extra_controls); + + if (has_tiltrotor_extra_controls || _do_override_collective_tilt) { + if (_do_override_collective_tilt) { + tiltrotor_extra_controls.collective_tilt_normalized_setpoint = _collective_tilt_normalized_setpoint; + } - if (_tiltrotor_extra_controls_sub.copy(&tiltrotor_extra_controls)) { float control_collective_tilt = tiltrotor_extra_controls.collective_tilt_normalized_setpoint * 2.f - 1.f; // set control_collective_tilt to exactly -1 or 1 if close to these end points @@ -165,7 +196,7 @@ void ActuatorEffectivenessTiltrotorVTOL::updateSetpoint(const matrix::Vector