Michael Fritsche d34142bc4e refactor(rover): run each rover controller on its own trigger topic (#29630)
* refactor(rover): run each rover controller on its own trigger topic

The rover modules ran the whole controller cascade from the gyro callback,
so the position and speed controllers ran several times per EKF output on
stale estimates. Each controller is now a work item triggered by the topic
it consumes (local position, attitude, angular velocity, steering
setpoint), and the module only generates setpoints and enables the
controllers the active control mode needs. All work items share the
rate_ctrl queue, so enabling and resetting never overlaps a controller run.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* fix(rover): register controller callbacks top-down

Position and speed control share the vehicle_local_position trigger and
uORB schedules callbacks in registration order. Speed was registered
first, so it always consumed the previous cycle's position-control
setpoint, adding one EKF period of latency.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* docs(rover): move controller update descriptions back to their functions

The init() and setEnabled() declarations were inserted between the
update*Control() doc comments and their functions, leaving two stacked
@brief blocks.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* fix(rover): widen the dt clamp of the EKF-triggered controllers

Attitude and speed control now run on vehicle_attitude and
vehicle_local_position instead of the gyro. Their period is the EKF2
output period, nominally exactly the old 10 ms upper bound, so jitter or
a larger EKF2_PREDICT_US clipped dt and slowed the slew-rate limiters and
PID integrators below real time. Allow up to 50 ms.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* docs(rover): correct the attitude controller dt comment

vehicle_attitude is published on every EKF2 output predictor update at
IMU_INTEG_RATE, not at the EKF2_PREDICT_US filter update rate.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* fix(rover): restart the controller dt when a controller is re-enabled

A controller keeps its last run timestamp while it is disabled, so the
first run after a mode switch computed dt over the whole disabled time
and hit the upper clamp. With the speed and attitude clamps at 50 ms that
step was six EKF periods long for the slew limiters and integrators.
Restart the timestamp on enabling, so the first dt is the lower bound.

SIH rover (10045), position -> manual -> position while driving, speed
PID integral after the first re-enabled run: dt 50 ms before, 1 ms after
(normal runs 8 ms).

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* fix(rover): pace the actuator controllers by the gyro

The actuator controllers ran only when a steering setpoint arrived. A
mode change resets the rate controller's setpoint to NaN, so the next
cycle published no steering setpoint and therefore no actuator setpoint.
SIH lockstep waits for an actuator output every step and froze there:
switching to stabilized or offboard velocity stalled the simulation.
Trigger the actuator controllers on vehicle_angular_velocity, registered
after the rate controller, so they publish every cycle with the steering
setpoint of the same cycle.

SIH rover (10045), manual/acro/stab/position/offboard velocity cycle, 3 runs
each: before all 3 runs froze (offboard switch in all, stab switch in one), after no
lockstep timeouts, actuator outputs every cycle (max gap 8 ms) and >= 99.7 %
of them use the steering setpoint of the same cycle.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* perf(rover): only wake the enabled controllers

All controllers stayed registered on their trigger topics, so in every
mode and while disarmed the disabled ones were scheduled at up to gyro
rate just to return. Register a controller's callback when it gets
enabled and unregister it when it gets disabled. A newly enabled
controller runs once right away, because it registered after the trigger
of the current cycle fired; without that the lockstep simulation misses
the cycle's actuator output and stalls. When an upper controller is
enabled while the lower one sharing its trigger topic keeps running
(position/speed on vehicle_local_position, rate/actuator on
vehicle_angular_velocity), the lower one is re-registered behind it to
keep the cascade order.

SIH rover (10045), 3 runs each:
- work_queue status: disarmed only the module runs, manual adds the
  actuator controller, acro rate + actuator, stab + attitude, position all
  five, offboard velocity all but position; no lockstep timeouts.
- Value-based order check (servo command vs steering setpoint, speed
  controller setpoint vs position controller setpoint): every consumer
  uses the setpoint of the same cycle after manual -> acro, manual ->
  offboard velocity and offboard velocity -> Go-To. With the
  re-registration disabled the actuator controller used the previous
  cycle's steering setpoint after acro / offboard, and the speed
  controller the previous cycle's speed setpoint in Go-To (153 of 153).
- Re-enable probe: first dt after position -> manual -> position is still
  1-2 ms.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* fix(rover): assign the rover control workitems to nav_and_controllers

* fix(rover): retry a failed controller callback registration

setEnabled() marked a controller enabled even when registering its
trigger callback failed. The next call then saw no change and never
retried, so the controller ran once from ScheduleNow() and then stayed
idle with a single error. A controller now only counts as enabled once
its callback is registered, so the next module cycle retries. A failed
re-registration for the cascade order clears it the same way. The
modules report a failure once instead of every cycle.

SIH rover (10045), attitude controller registration forced to fail for
the first 1500 attempts: the controller stays off while it fails and
starts at 250 Hz on the first successful retry, one error per failure
episode. Mode cycle without the fault unchanged.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* refactor(rover): share the controller trigger logic in a base class

All 15 rover controllers carried the same copy of init(), setEnabled(),
enabled(), reregisterTrigger() and the enabled check in Run(). Copies of
the code that decides when a controller runs and in which order can
drift apart, so RoverControllerWorkItem in lib/rover_control now owns
the trigger subscription, the work queue and the enable state. A
controller only implements its step and, if it has a time step, the
restart on enabling.

The trigger only wakes the controller, so the controllers read their
inputs through plain subscriptions again. The actuator controllers no
longer drain the gyro topic: callbacks are scheduled on new
publications, not on unread data.

A functional test covers the contract the modules rely on: no runs
while disabled, one run right away on enabling, a run on every trigger,
registration order for controllers sharing a trigger and re-registering
to restore the cascade order.

SIH rover (10045), manual/acro/stab/position cycle: each mode wakes the
same controllers at the same rates as before, actuator setpoints at
250 Hz, no errors.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

* fix(rover): drop the protected destructor of the controller base class

clang-tidy (cppcoreguidelines-virtual-class-destructor) rejects a
destructor that is both protected and virtual. WorkItem already has a
public virtual destructor, so the implicit one is enough.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Fritsche <frimi999@gmail.com>

---------

Signed-off-by: Michael Fritsche <frimi999@gmail.com>
2026-11-09 08:23:12 -05: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.7%
C 36%
Python 4.9%
CMake 4.4%
Linker Script 3.3%
Other 1.5%