ROS/ROS2 Interface Reference¶
The RflySim toolchain supports communication with the simulation system via ROS 1 (Noetic) and ROS 2 (Humble/Jazzy), and mainly uses MAVROS / MAVROS2 to implement the bridge between PX4 and the ROS ecosystem.
MAVROS Overview¶
MAVROS is a bridge that connects the PX4 autopilot to the ROS ecosystem, responsible for converting MAVLink messages into ROS topics and services:
graph LR
PX4[PX4 SITL/HITL] <-->|MAVLink<br>UDP| MAVROS[MAVROS]
MAVROS <-->|ROS Topics/Services| ROS[ROS Nodes]
ROS --> ALGO[Perception/Planning/Control Algorithms]
Common ROS Topics¶
Subscribed Topics (Read Status)¶
| Topic | Message Type | Description |
|---|---|---|
/mavros/state |
mavros_msgs/State |
Autopilot connection/arming/flight mode status |
/mavros/local_position/pose |
geometry_msgs/PoseStamped |
Position and attitude in local coordinate frame |
/mavros/local_position/velocity_local |
geometry_msgs/TwistStamped |
Velocity in local frame |
/mavros/global_position/global |
sensor_msgs/NavSatFix |
GPS global coordinates |
/mavros/imu/data |
sensor_msgs/Imu |
IMU data |
/mavros/battery |
sensor_msgs/BatteryState |
Battery status |
Published Topics (Send Control Commands)¶
| Topic | Message Type | Description |
|---|---|---|
/mavros/setpoint_position/local |
geometry_msgs/PoseStamped |
Position setpoint |
/mavros/setpoint_velocity/cmd_vel_unstamped |
geometry_msgs/Twist |
Velocity setpoint |
/mavros/setpoint_raw/local |
mavros_msgs/PositionTarget |
Raw position/velocity/acceleration setpoint |
/mavros/setpoint_raw/attitude |
mavros_msgs/AttitudeTarget |
Attitude setpoint |
Common Services¶
| Service | Type | Description |
|---|---|---|
/mavros/cmd/arming |
mavros_msgs/CommandBool |
Arm/Disarm |
/mavros/set_mode |
mavros_msgs/SetMode |
Switch flight mode |
/mavros/cmd/takeoff |
mavros_msgs/CommandTOL |
Takeoff |
/mavros/cmd/land |
mavros_msgs/CommandTOL |
Land |
ROS 2 (uXRCE-DDS)¶
PX4 v1.14+ natively supports ROS 2 communication. Through Micro XRCE-DDS Agent, uORB messages are directly converted into ROS 2 topics, no MAVROS required:
graph LR
PX4[PX4] <-->|uXRCE-DDS| AGENT[Micro XRCE-DDS Agent]
AGENT <-->|ROS 2 Topics| ROS2[ROS 2 Nodes]
Quick Start¶
ROS 1 + MAVROS¶
# Execute in WinWSL
# Start MAVROS and connect to SITL (default port 14540)
roslaunch mavros px4.launch fcu_url:="udp://:14540@127.0.0.1:14557"
Or use the shortcut RflyTools\MavrosRun.
ROS 2 + MAVROS2¶
Related Examples¶
| Example | Path |
|---|---|
| MAVROS Function Test | RflySimAPIs\2.RflySimUsage\0.ApiExps\e6_ROSMavrosReadme |
| ROS Visual Perception | RflySimAPIs\8.VisionPerception\ |
| ROS Swarm Control | RflySimAPIs\10.SwarmControl\ |