ROS/MAVROS with Gazebo Simulation
ROS (Robot Operating System) can be used with PX4 and the Gazebo simulator. It uses the MAVROS MAVLink node to communicate with PX4.
The ROS/Gazebo integration with PX4 follows the pattern in the diagram below (this shows the generic PX4 simulation environment). PX4 communicates with the simulator (e.g. Gazebo) to receive sensor data from the simulated world and send motor and actuator values. It communicates with the GCS and an Offboard API (e.g. ROS) to send telemetry from the simulated environment and receive commands.
The only slight difference to "normal behaviour" is that ROS initiates the connection on port 14557, while it is more typical for an offboard API to listen for connections on UDP port 14540.
Installing ROS and Gazebo
ROS is only supported on Linux (not macOS or Windows).
The easiest way to setup PX4 simulation with ROS on Ubuntu Linux is to use the standard installation script that can be found at Development Environment on Linux > Gazebo with ROS. The script installs everything you need: PX4, ROS "Melodic", the Gazebo 9 simulator, and MAVROS.
The script follows the standard ROS "Melodic" installation instructions, which includes Gazebo 9.
Launching ROS/Simulation
The command below can be used to launch the simulation and connect ROS to it via MAVROS, where fcu_url
is the IP / port of the computer running the simulation:
To connect to localhost, use this URL:
It can be useful to call roslaunch with the -w
(warn) and/or -v
(verbose) in order to get warnings about missing dependencies in your setup. For example:
Launching Gazebo with ROS Wrappers
The Gazebo simulation can be modified to integrate sensors publishing directly to ROS topics e.g. the Gazebo ROS laser plugin. To support this feature, Gazebo must be launched with the appropriate ROS wrappers.
There are ROS launch scripts available to run the simulation wrapped in ROS:
posix_sitl.launch: plain SITL launch
mavros_posix_sitl.launch: SITL and MAVROS
To run SITL wrapped in ROS the ROS environment needs to be updated, then launch as usual:
(optional): only source the catkin workspace if you compiled MAVROS or other ROS packages from source:
Include one of the above mentioned launch files in your own launch file to run your ROS application in the simulation.
What's Happening Behind the Scenes
This section shows how the roslaunch instructions provided previously actually work (you can follow them to manually launch the simulation and ROS).
First start the simulator using the command below:
The console will look like this:
Now in a new terminal make sure you will be able to insert the Iris model through the Gazebo menus, to do this set your environment variables to include the appropriate sitl_gazebo
folders.
Now start Gazebo like you would when working with ROS and insert the Iris quadcopter model. Once the Iris is loaded it will automatically connect to the px4 app.
Last updated