This package demonstrates how to use PX4 Offboard mode from ROS 2. It showcases a complete autonomous flight mission using a state machine that controls the drone through various flight phases.
The Offboard Demo implements a state-based flight controller that executes the following Offboard mode:
- Arm - Arms the vehicle and prepares for flight
- Takeoff - Takes off to a specified altitude
- Hover - Hovers at takeoff position for a configurable duration
- Waypoint Navigation - Flies through a predefined set of waypoints in a square pattern
- Yaw Rotation - Performs a 360-degree rotation while hovering
- Land - Lands the vehicle safely
- Disarm - Disarms the vehicle when landed
-
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
offboard_demo.launch.pyfrom inside the docker containerros2 launch offboard_demo offboard_demo.launch.py
The offboard_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.
-
Change the takeoff altitude to 3 m via ROS 2 parameter
-
Slow down the drone while going through the waypoints and speed up the yaw rotation
Hint: https://docs.px4.io/main/en/flight_stack/controller_diagrams#multicopter-velocity-controller & QGC
-
Add another state, where you change the altitude to 1.5 m before going to the waypoints
The solution to the exercise is commented out at the end of the OffboardDemo.cpp, OffboardDemo.hpp and offboard_demo.launch.py.
Feel free to uncomment it and recompile the package to unveil it.