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
This commit is contained in:
treston authored and GitHub committed 2026-10-13 10:59:44 -06:00
1 parent 4e05e04594
commit e50af4085d
1 file changed
+15 -6
@@ -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;
}
}
}