PX4IO Mixer uses NaNs to send disarm PWM values


Exploring through the mixer code on the px4io firmware I’ve noticed that we are protecting against motors spinning during disarm by doing the following:

-Assigning the actuator_control_0->controls[3] to NaN (in mixer.cpp/mixer_callback)
-Having this NaN propagate through the mixer and corrupt the calculations to make the outputs[i] index for the motors be NaN
-In pwm_limit.cpp if the control_value is not finite, set the pwm to “disarmed_pwm” for that channel.

Is this correct?

If so, is this the best method to handle ensuring safe values are passed through the mixer during disarm? I believe this could be documented a little better for people making custom mixers- they should expect a NaN value for thrust control during disarm and need to be able to handle that case.


Hi @dlwalter ,
Yes, this is correct. I also find that we should maybe force disarmed values withou relaying on the propagation on NANs. I discovered that when one day I decided to make a mixer to output that output 1 or zero depending on the thrust. I realized that I was unable to disarm the drone because the result of a NAN thrust was 1.

I think that the reason is that we want to output PWM values to the servos even when disarmed (as long as the vehicle is prearmed - safety switch pressed) but not the motors. Since the motors signals are directly computed using - at least - thrust, setting a NAN to thrust should output a NAN and the FMU/IO/… driver is then able to identify when it should set disarmed values.


Yeah, the passthrough of NAN can be pretty obscured for anyone unfamiliar with the system. Maybe it should just be better documented in mixer.h or somewhere.

It would have definitely saved me some development time if the NaN logic was explicit in the mixer - especially since the whole PWM architecture is completely different in SITL and the NaNs never show up.


I totally agree. Could you add a comment in mixer.h and make a PR please?

1 Like

That sounds good. Won’t be able to in the next couple weeks but I’ll see what I can squeeze in.