Skip to content

ROS/ROS2 Interface Reference


RflySim can connect to flight controller status, control commands, vision sensors, and swarm algorithms via ROS 1 and ROS 2. The currently bundled RflySim-20.04 WinWSL provides ROS 1 Noetic and ROS 2 Humble by default; whether other ROS distributions can be used depends on the environment and dependency compatibility installed by the user.

Communication Method Selection

Communication Method Applicable Scenarios Main Topic Prefixes
MAVROS / MAVROS2 Reading PX4 status, arming, switching modes, and sending Offboard setpoints via MAVLink /mavros/..., /mavrosN/...
uXRCE-DDS PX4 v1.14+ native communication with ROS 2, accessing uORB topics exposed by firmware configuration /fmu/out/..., /fmu/in/...
RosTrans Multi-protocol conversion among CopterSim, RflySim3D, vision sensors, MAVLink, and ROS Determined by RosTrans configuration

The three methods are not the same interface. When using MAVROS, look for /mavros/...; when using PX4 uXRCE-DDS, look for /fmu/...; when using RosTrans, refer to its parameter files and filtering rules.


MAVROS / MAVROS2

MAVROS converts PX4's MAVLink messages into ROS topics and services. In RflySim's standard SITL/HITL link, MAVLink data first passes through CopterSim in Mavlink_Full mode, and is then connected to ROS by MAVROS:

RflySim MAVROS Data Chain

Ports and Multi-Vehicle Namespaces

For a vehicle with CopterID N, RflySim uses the following rules by default:

CopterSim target port = 20100 + N * 2 - 2
MAVROS receive port   = CopterSim target port + 1
MAVLink System ID     = N
CopterID MAVROS Namespace MAVROS Receive Port CopterSim Target Port
1 /mavros 20101 20100
2 /mavros2 20103 20102
N /mavrosN 20100 + N * 2 - 1 20100 + N * 2 - 2

The topics below use vehicle 1's /mavros as an example. When operating other vehicles, the prefix should be replaced with the corresponding /mavrosN.

Common Subscribed Topics

Topic ROS 1 Type ROS 2 Type Description
/mavros/state mavros_msgs/State mavros_msgs/msg/State Connection, arming, and flight mode status
/mavros/local_position/pose geometry_msgs/PoseStamped geometry_msgs/msg/PoseStamped Local position and attitude
/mavros/local_position/velocity_local geometry_msgs/TwistStamped geometry_msgs/msg/TwistStamped Local velocity
/mavros/global_position/global sensor_msgs/NavSatFix sensor_msgs/msg/NavSatFix GPS global coordinates
/mavros/imu/data sensor_msgs/Imu sensor_msgs/msg/Imu IMU data
/mavros/battery sensor_msgs/BatteryState sensor_msgs/msg/BatteryState Battery status

Common Published Topics

Topic ROS 1 Type ROS 2 Type Description
/mavros/setpoint_position/local geometry_msgs/PoseStamped geometry_msgs/msg/PoseStamped Position setpoint
/mavros/setpoint_velocity/cmd_vel_unstamped geometry_msgs/Twist geometry_msgs/msg/Twist Velocity setpoint
/mavros/setpoint_raw/local mavros_msgs/PositionTarget mavros_msgs/msg/PositionTarget Raw position, velocity, and acceleration setpoint
/mavros/setpoint_raw/attitude mavros_msgs/AttitudeTarget mavros_msgs/msg/AttitudeTarget Attitude setpoint

Common Services

Service ROS 1 Type ROS 2 Type Description
/mavros/cmd/arming mavros_msgs/CommandBool mavros_msgs/srv/CommandBool Arm or disarm
/mavros/set_mode mavros_msgs/SetMode mavros_msgs/srv/SetMode Switch flight mode
/mavros/cmd/takeoff mavros_msgs/CommandTOL mavros_msgs/srv/CommandTOL Takeoff
/mavros/cmd/land mavros_msgs/CommandTOL mavros_msgs/srv/CommandTOL Land

Coordinate Frames and ROS 2 QoS

  • MAVROS typically uses ENU world coordinates and FLU body coordinates on the ROS side, while PX4 internally uses NED/FRD. /mavros/local_position/pose and ordinary position setpoints cannot be directly filled with unconverted PX4 NED values.
  • The interpretation of /mavros/setpoint_raw/local also depends on mavros_msgs/PositionTarget.coordinate_frame and type_mask; the coordinate frame and enabled fields should be clarified before sending.
  • The QoS on the ROS 2 subscriber side must be compatible with the MAVROS2 publisher side. RflySim's MAVROS2 Offboard example uses BEST_EFFORT, TRANSIENT_LOCAL, KEEP_LAST, depth=1 when subscribing to /mavros/state; if the topic exists but no messages are received, use ros2 topic info -v <topic> to check the actual QoS.

ROS 2 uXRCE-DDS

PX4 v1.14+ can connect to ROS 2 via the uXRCE-DDS Client and Micro XRCE-DDS Agent, without requiring MAVROS. This link only bridges the uORB topics configured in the PX4 firmware's dds_topics.yaml, and does not automatically expose all uORB messages.

PX4 uXRCE-DDS Data Chain

Before use, you need to:

  • Use PX4 firmware that supports uXRCE-DDS, and ensure the PX4-side Client is enabled and the port is correctly configured.
  • Install px4_msgs matching the PX4 version; when developing custom bridge packages, px4_ros_com is also typically used.
  • Start the Agent in WinWSL:
MicroXRCEAgent udp4 -p 8888

A typical output topic is /fmu/out/vehicle_local_position, and control input topics are located under /fmu/in/.... You can verify the link with the following commands:

ros2 topic list | grep '^/fmu/'
ros2 topic echo /fmu/out/vehicle_local_position

Quick Start for MAVROS

  1. First run Environment Check via the RflySim unified launcher to confirm that the WinWSL, PX4, and ROS environments are working properly.
  2. Run RflyTools\SITLRunROS. This script starts CopterSim in Mavlink_Full mode and automatically launches the corresponding MAVROS/MAVROS2 nodes.
  3. If the simulation and CopterSim are already running, you can run RflyTools\MavrosRun to start MAVROS separately. Entering 1 means vehicle 1; entering 4,3 means starting 3 nodes beginning from vehicle 4.

CopterSim Mode Requirement

The MAVROS link requires CopterSim to use Mavlink_Full (UDPSIMMODE=2). If normal SITL is already running but CopterSim is not in this mode, starting only MavrosRun cannot establish proper communication.

Manually Starting ROS 1

After confirming that CopterSim for vehicle 1 is in Mavlink_Full mode, execute in WinWSL:

roslaunch mavros px4.launch \
  namespace:=mavros \
  tgt_system:=1 \
  fcu_url:="udp://:20101@127.0.0.1:20100"

Manually Starting ROS 2

ros2 launch mavros px4.launch.xml \
  namespace:=mavros \
  tgt_system:=1 \
  fcu_url:="udp://:20101@127.0.0.1:20100"

The currently bundled MAVROS2 provides both px4.launch and px4.launch.xml; the SDK's RflyRosStart.py uses px4.launch.xml. If you are using a self-installed MAVROS, refer to the actual filenames in its share/mavros/launch directory.

After startup, you can check the connection status:

# ROS 1
rostopic echo /mavros/state

# ROS 2
ros2 topic echo /mavros/state

If connected remains false, check the CopterSim mode, CopterID, port, tgt_system, and namespace in sequence. For distributed simulation, you also need to replace 127.0.0.1 with the reachable IP of the computer running CopterSim, and check the firewall and UDP routing.


Content Path
MAVROS/MAVROS2 Installation and Offboard Control RflySimAPIs\2.RflySimUsage\0.ApiExps\e10_Mavros
PX4 ROS 2 and uXRCE-DDS RflySimAPIs\2.RflySimUsage\0.ApiExps\e12_PX4ROS2
ROS Vision Sensor Python/C++ Communication RflySimAPIs\2.RflySimUsage\0.ApiExps\e13_VisAPIPyCpp
RosTrans Multi-Protocol Conversion RflySimAPIs\6.RflySimExtCtrl\0.ApiExps\e21.RosTransExps
ROS 2 Swarm Control RflySimAPIs\10.RflySimSwarm\0.ApiExps\e10.ROS2Swarm