This package demonstrates how to create and use PX4 custom flight modes from ROS 2 using the PX4-ROS2 Interface Library. It showcases the implementation of custom flight behaviors that integrate seamlessly with PX4's mode management system.
The Custom Mode Demo implements two custom flight modes using the PX4-ROS2 Interface Library:
- CustomWaypoints Mode: Autonomous waypoint navigation with predefined trajectory
- CustomYaw Mode: Controlled yaw rotation while maintaining position
These modes are orchestrated by a CustomModeExecutor that manages the complete flight sequence through a state machine architecture. You have to select CustomWaypoints for the sequence to start.
The demo executes the following autonomous sequence:
- Takeoff - Automatic takeoff to predefined altitude
- CustomWaypoints - Navigate through rectangular waypoint pattern
- CustomYaw - Perform 360-degree rotation while hovering
- Land - Automatic landing
- WaitUntilDisarmed - Safe completion state
- Start the simulation, PX4 and QGC as described in the setup guide.
- Ensure the vehicle is armed (GPS lock, all sensors healthy)
- Verify QGroundControl connection for mode monitoring
-
Start the simulation, PX4 and QGC as described in the setup guide.
-
Start the additional ROS 2 node through the common launchfile
ros2 launch px4_roscon_25 common.launch.py
-
Run
custom_mode_demo.launch.pyfrom inside the docker containerros2 launch custom_mode_demo custom_mode_demo.launch.py
-
Differently from the Offboard control exercise, the custom mode demo does not automatically switch to the correct external mode CustomWaypoints and it does not arm the drone.
The custom_mode_demo.launch.py can also start the MicroXrceAgent and the gz clock bridge. Set the launch arguments run_uxrcedds_agent or run_gz_clock_bridge to true to run them if you don't use common.launch.py.
- Add any kind of parameter, that affects CustomWaypoint or CustomYaw
- Explore what happens if you want to change the Mode order in the Executor
- Add another Mode after yaw, where you change the altitude to 3 m before landing
The solution to the exercise is commented out at the end of the CustomMode.cpp, CustomMode.hpp, CustomModeExecutor.cpp and CustomModeExecutor.hpp
Feel free to uncomment it and recompile the package to unveil it.

