PX4 Simulation
PX4 Gazebo Simulation in ROS
ROS (Robot Operating System) can be used with PX4 and simulate it in 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 with the TCP communication. It communicates with the GCS and an Offboard API (e.g. ROS) to send telemetry from the simulated environment and receive commands.
Note
The only slight difference to “normal behavior” 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.
Install ROS and Gazebo
I hope that all of you have already installed ROS and Gazebo correctly with the official guide. And the following commands will help you to install the MAVROS.
1 |
|
1 |
|
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:
1 |
|
To connect to localhost, use this URL:
1 |
|
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, to run SITL wrapped in ROS the ROS environment needs to be updated, the launch as usual:
1 |
|