Isak Åslund b364d30a88 fix(mc_att_control): reject invalid attitude setpoints (#29008)
* fix(mc_att_control): ignore invalid attitude setpoints in the reference model

Since the reference model (2a0e048171, PR #27255) the controller tracks _q_ref,
which is integrated from its previous value and only snapped to the setpoint on
the first call. A single attitude setpoint with a zero or non-finite quaternion
(normalizing a zero quaternion gives NaN) therefore makes _q_ref NaN for the rest
of the boot: every later setpoint is ignored, the rate setpoint stays NaN and the
vehicle has no attitude control, even after a mode switch. Before the reference
model the controller used q_d directly, so a bad sample only lasted one cycle.

One MAVLink SET_ATTITUDE_TARGET with q = [0, 0, 0, 0] in Offboard reproduces it
in SIH: vehicle_rates_setpoint stays NaN and the vehicle no longer responds to
the sticks after switching to Position mode.

Ignore setpoints and heading-reset deltas that are zero or non-finite, keeping
the last valid reference, and snap the reference to the next valid setpoint if
it ever becomes non-finite.

Signed-off-by: Isak Åslund <isak.aslund@airolit.com>

* fix(mc_att_control): drop the whole attitude setpoint when its quaternion is invalid

When the controller rejects an invalid quaternion, the thrust and timestamp
from the same message were still applied. The vehicle then flew the last
valid attitude with thrust from a message that cannot be trusted.

setAttitudeSetpoint() now returns whether the setpoint was accepted. The
thrust and the setpoint timestamp are only updated when it was. Keeping the
timestamp also gives the next valid setpoint the true dt since the last
accepted one.

Signed-off-by: Isak Åslund <isak.aslund@airolit.com>

* fix(mc_att_control): reject overflowing quaternions and drop invalid SET_ATTITUDE_TARGET

Review follow-ups:
- Validate the setpoint through its norm. A quaternion with a finite component
  above ~1.8e19 (e.g. q = (1e20, 0, 0, 0)) passed isAllFinite(), its norm
  overflowed to inf and normalizing it gave a zero quaternion. As the first
  setpoint this made the reference NaN for the next setpoint. One finite norm
  check rejects NaN, inf, zero and overflow.
- Drop the ref_valid / dt finiteness recovery branch: with every input of the
  reference model validated it cannot be reached, and it costs flash.
- Drop the adaptAttitudeSetpoint() guard: no estimator publishes an invalid
  delta with a changed reset counter, and it only protected the reference,
  not the yaw setpoint and StickYaw that use the same delta.
- MAVLink SET_ATTITUDE_TARGET: drop a message with an unusable q before
  publishing offboard_control_mode. Otherwise a companion streaming only
  invalid quaternions keeps the offboard heartbeat alive and the vehicle holds
  the last valid tilt and thrust indefinitely without triggering
  COM_OF_LOSS_T.

Signed-off-by: Isak Åslund <isak.aslund@airolit.com>

* docs(offboard): note that SET_ATTITUDE_TARGET with an invalid q is dropped

Since the previous commit, such a message no longer counts as the offboard
signal, which is a behavior change MAVLink users can see. Also name the 1e-3
norm threshold in the setAttitudeSetpoint() doc, and point the MAVLink and
controller checks at each other: if the MAVLink threshold were lowered below
the controller's, messages the controller drops would keep offboard alive.

Signed-off-by: Isak Åslund <isak.aslund@airolit.com>

---------

Signed-off-by: Isak Åslund <isak.aslund@airolit.com>
(cherry picked from commit 7902349f7a)
2026-11-16 07:26:09 -08:00
…

PX4 Autopilot

The autopilot stack the industry builds on.

Release DOI Discord

OpenSSF Best Practices LFX Health Score LFX Contributors LFX Active Contributors


About

PX4 is an open-source autopilot stack for drones and unmanned vehicles. It supports multirotors, fixed-wing, VTOL, rovers, and many more experimental platforms from racing quads to industrial survey aircraft. It runs on NuttX, Linux, and macOS. Licensed under BSD 3-Clause.

Why PX4

Modular architecture. PX4 is built around uORB, a DDS-compatible publish/subscribe middleware. Modules are fully parallelized and thread safe. You can build custom configurations and trim what you don't need.

Wide hardware support. PX4 runs on a wide range of autopilot boards and supports an extensive set of sensors, telemetry radios, and actuators through the Pixhawk ecosystem.

Developer friendly. First-class support for MAVLink and DDS / ROS 2 integration. Comprehensive SITL simulation, hardware-in-the-loop testing, and log analysis tools. An active developer community on Discord and the weekly dev call.

Vendor neutral governance. PX4 is hosted under the Dronecode Foundation, part of the Linux Foundation. Business-friendly BSD-3 license. No single vendor controls the roadmap.

Supported Vehicles

Multicopter
Multicopter
Fixed Wing
Fixed Wing
VTOL
VTOL
Rover
Rover

…and many more: helicopters, autogyros, airships, submarines, boats, and other experimental platforms. These frames have basic support but are not part of the regular flight-test program. See the full airframe reference.

Try PX4

Run PX4 in simulation with a single command. No build tools, no dependencies beyond Docker:

docker run --rm -it -p 14550:14550/udp px4io/px4-sitl:latest

Open QGroundControl and fly. See PX4 Simulation Quickstart for more options.

Build from Source

git clone https://github.com/PX4/PX4-Autopilot.git --recursive
cd PX4-Autopilot
make px4_sitl

Note

See the Development Guide for toolchain setup and build options.

Documentation & Resources

Resource Description
User Guide Build, configure, and fly with PX4
Developer Guide Modify the flight stack, add peripherals, port to new hardware
Airframe Reference Full list of supported frames
Autopilot Hardware Compatible flight controllers
Release Notes What's new in each release
Contribution Guide How to contribute to PX4

Community

Contributing

We welcome contributions of all kinds — bug reports, documentation, new features, and code reviews. Please read the Contribution Guide to get started.

Citation

If you use PX4 in academic work, please cite it. BibTeX:

@software{px4_autopilot,
  author    = {Meier, Lorenz and {The PX4 Contributors}},
  title     = {{PX4 Autopilot}},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.595432},
  url       = {https://px4.io}
}

The DOI above is a Zenodo concept DOI that always resolves to the latest release. For a version-pinned citation, see the Zenodo record or our CITATION.cff.

Governance

The PX4 Autopilot project is hosted by the Dronecode Foundation, a Linux Foundation Collaborative Project. Dronecode holds all PX4 trademarks and serves as the project's legal guardian, ensuring vendor-neutral stewardship — no single company owns the name or controls the roadmap. The source code is licensed under the BSD 3-Clause license, so you are free to use, modify, and distribute it in your own projects.

Dronecode Logo

Languages
C++ 49.8%
C 35.9%
Python 4.9%
CMake 4.4%
Linker Script 3.3%
Other 1.5%