English | 简体中文
px4_offboard_control is a ROS 1 PX4 Offboard trajectory publisher. It generates analytic
position, velocity, acceleration, yaw, and yaw-rate references and sends them through MAVROS
to the built-in PX4 position controller. It does not contain a ROS-side flight controller.
Analytic trajectory -> mavros_msgs/PositionTarget -> MAVROS -> PX4
| Horizontal figure eight | Vertical figure eight |
|---|---|
![]() |
![]() |
| Sinusoidal flip | Fast circle |
|---|---|
![]() |
![]() |
- Publishes position, velocity, acceleration, yaw, and yaw-rate references at a configurable rate
- Pre-streams Offboard setpoints and can automatically request OFFBOARD mode and arm
- Uses a quintic transition from the current vehicle state to the trajectory start
- Decelerates smoothly and holds position when trajectory tracking is stopped
- Uses a fixed angular speed with smooth online speed changes and continuous trajectory phase
- Publishes a
nav_msgs/Pathreference preview for visualization - Provides an RQT reference-trajectory panel with trajectory parameters and start/stop controls
- Publishes PX4-direct setpoints at 250 Hz by default and shows measured setpoint/feedback rates
- Starts RViz with the reference path and MAVROS vehicle pose by default
Available analytic trajectories:
figure8_horizontalfigure8_verticalhelix_fliphelix_flip_yflip_loop_sinefast_circle
- Ubuntu 20.04
- ROS Noetic
- PX4 Autopilot
- MAVROS
- Eigen3
Install the ROS dependencies:
sudo apt update
sudo apt install ros-noetic-mavros ros-noetic-mavros-extras \
ros-noetic-rqt-reconfigure ros-noetic-rqt-gui ros-noetic-rviz libeigen3-devPlace this package in the src directory of a catkin workspace, then run:
cd ~/mavros_ws
catkin build px4_offboard_control
source devel/setup.bashFor a catkin_make workspace:
cd ~/mavros_ws
catkin_make
source devel/setup.bashThis package does not require a specific PX4 source repository. Start either an upstream PX4
firmware or simulation environment, or the df-main firmware described below.
For example, start upstream PX4 with Gazebo Classic on Ubuntu 20.04:
cd ~/PX4-Autopilot
make px4_sitl gazebo-classic_irisAlternatively, use the df-main branch of
DuctedFanUAV-Autopilot.
This branch includes a modified iris and also supports ducted-fan UAV airframes:
git clone --branch df-main --recursive \
https://github.com/mengchaoheng/DuctedFanUAV-Autopilot.git
cd DuctedFanUAV-Autopilot
make px4_sitl gazebo-classic_iris
# or
make px4_sitl gazebo-classic_ductedfan4Replace ductedfan4 with another supported ducted-fan UAV airframe when required. On real
hardware, run the corresponding flight-controller firmware; PX4 SITL is not required on the
companion computer.
Build the package before the first launch and whenever the source code changes:
cd ~/mavros_ws
source /opt/ros/noetic/setup.bash
catkin build px4_offboard_control
source devel/setup.bashAfter PX4 starts, open a second terminal and connect MAVROS:
cd ~/mavros_ws
source /opt/ros/noetic/setup.bash
source devel/setup.bash
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"Open a third terminal and start the trajectory node:
cd ~/mavros_ws
source /opt/ros/noetic/setup.bash
source devel/setup.bash
roslaunch px4_offboard_control px4_direct.launchThis command starts the px4_direct node, the reference-trajectory panel, and RViz. To run
without either graphical tool:
roslaunch px4_offboard_control px4_direct.launch visualization:=false trajectory_panel:=falseThe package uses the MAVLink SET_POSITION_TARGET_LOCAL_NED interface and does not depend on
PX4 ROS 2 message versions. This MAVLink interface is available across multiple PX4 releases,
but each selected PX4/MAVROS combination should still be regression-tested in SITL before flight.
The launch file enables automatic trajectory start, OFFBOARD mode requests, and arming by default. Confirm that the flight area, trajectory altitude, and amplitudes are safe. For initial real-flight tests, disabling automatic arming is recommended:
<param name="auto_arm" value="false"/>Start trajectory tracking:
rosservice call /px4_direct/start "data: true"Stop smoothly and hold position:
rosservice call /px4_direct/start "data: false"| Parameter | Default | Description |
|---|---|---|
traj_name |
figure8_horizontal |
Trajectory type |
omega_value |
0.15 |
Fixed angular speed in rad/s |
omega_transition_duration |
2.0 |
Smooth online speed-transition duration in seconds |
setpoint_rate_hz |
250.0 |
PX4-direct setpoint publication rate in Hz |
auto_start |
true |
Start tracking automatically after the vehicle is ready |
auto_offboard |
true |
Request OFFBOARD mode automatically |
auto_arm |
true |
Arm automatically |
trajectory_yaw_lock |
true |
Use a fixed yaw angle |
trajectory_yaw_fixed |
0.0 |
Fixed yaw angle in radians |
trajectory_start_ramp_duration |
5.0 |
Smooth trajectory ramp duration in seconds |
trajectory_switch_transition_duration |
3.0 |
Nominal transition time to the trajectory start |
The trajectory geometry defaults match geometric_controller: amplitudes/radii are 3.0 m,
center heights are 6.0 m, and the helical translation speed is 0.3 m/s.
Trajectory amplitudes, heights, initial phases, Offboard retry settings, and transition limits
are configured in launch/px4_direct.launch.
Change the angular speed during flight; the node transitions smoothly while preserving phase:
rosparam set /px4_direct/omega_value 1.0The same angular-speed setting, trajectory selection, geometry, yaw settings, and transition parameters are available in the RQT panel. Geometry or trajectory-type changes trigger a smooth switch from the current vehicle state. The panel displays the measured setpoint rate and MAVROS local-position feedback rate. PX4 control loops remain internal and are therefore not reported as a ROS controller rate. The panel contains no ROS-side controller settings.
Increasing setpoint_rate_hz reduces reference update latency but does not increase the PX4
controller gains. More aggressive motion is set with omega_value; more aggressive tracking
response requires PX4-side tuning and may use the df-main firmware where appropriate. Confirm
MAVLink bandwidth before using high rates on a serial connection.
Published topics:
mavros/setpoint_raw/local(mavros_msgs/PositionTarget): PX4 P/V/A/yaw/yaw-rate setpointreference/trajectory(nav_msgs/Path): reference trajectory previewreference/current_pose(geometry_msgs/PoseStamped): current reference posevehicle/current_pose(geometry_msgs/PoseStamped): MAVROS vehicle pose for RVizvehicle/path(nav_msgs/Path): actual vehicle trail
Subscribed topics:
mavros/statemavros/local_position/posemavros/local_position/velocity_local
Service:
/px4_direct/start(std_srvs/SetBool)
The node generates local references using the ROS/MAVROS ENU convention and sets
PositionTarget::FRAME_LOCAL_NED. MAVROS converts the setpoint from ENU to NED before sending
the MAVLink message.



