From e50af4085d03855242523de05500d3316700d1af Mon Sep 17 00:00:00 2001 From: treston Date: Tue, 13 Oct 2026 11:59:44 -0500 Subject: [PATCH] fix(control_allocator): zero non-finite torque setpoint components (#29156) * fix(control_allocator): zero non-finite torque setpoint components vehicle_torque_setpoint is also written by external producers over uXRCE-DDS and Zenoh. The torque vector was copied unchecked while the thrust path is sanitised; one NaN component makes every actuator setpoint NaN, which the mixer maps to the disarmed output. Zero non-finite components as the rate controllers do, on both allocation instances (and the second instance's thrust). * fix(control_allocator): note that the second instance has no NaN based motor stopping --- .../control_allocator/ControlAllocator.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/modules/control_allocator/ControlAllocator.cpp b/src/modules/control_allocator/ControlAllocator.cpp index c371c6a441c..82bbb624fae 100644 --- a/src/modules/control_allocator/ControlAllocator.cpp +++ b/src/modules/control_allocator/ControlAllocator.cpp @@ -383,6 +383,13 @@ ControlAllocator::Run() if (_vehicle_torque_setpoint_sub.update(&vehicle_torque_setpoint)) { _torque_sp = matrix::Vector3f(vehicle_torque_setpoint.xyz); + // the topic is also written externally; one non-finite component would reach every actuator + for (int i = 0; i < 3; i++) { + if (!PX4_ISFINITE(_torque_sp(i))) { + _torque_sp(i) = 0.f; + } + } + do_update = true; _timestamp_sample = vehicle_torque_setpoint.timestamp_sample; @@ -412,16 +419,18 @@ ControlAllocator::Run() c[0](5) = _thrust_sp(2); if (_num_control_allocation > 1) { + // The second instance has no NaN based motor stopping (stopMotorsBasedOnThrustSetpoint only reads the + // first thrust setpoint), so a non-finite component here carries no meaning and is zeroed. if (_vehicle_torque_setpoint1_sub.copy(&vehicle_torque_setpoint)) { - c[1](0) = vehicle_torque_setpoint.xyz[0]; - c[1](1) = vehicle_torque_setpoint.xyz[1]; - c[1](2) = vehicle_torque_setpoint.xyz[2]; + for (int i = 0; i < 3; i++) { + c[1](i) = PX4_ISFINITE(vehicle_torque_setpoint.xyz[i]) ? vehicle_torque_setpoint.xyz[i] : 0.f; + } } if (_vehicle_thrust_setpoint1_sub.copy(&vehicle_thrust_setpoint)) { - c[1](3) = vehicle_thrust_setpoint.xyz[0]; - c[1](4) = vehicle_thrust_setpoint.xyz[1]; - c[1](5) = vehicle_thrust_setpoint.xyz[2]; + for (int i = 0; i < 3; i++) { + c[1](3 + i) = PX4_ISFINITE(vehicle_thrust_setpoint.xyz[i]) ? vehicle_thrust_setpoint.xyz[i] : 0.f; + } } }