We’re happy to announce some improvements that will benefit the integration of Gazebo and ROS. These improvements affect two important aspects of the ros_gz tools : ergonomics and performance.
Ergonomics
A set of new launch files and launch actions have been merged into the ros_gz_bridge and ros_gz_sim packages and have been released into Rolling.
You can find a detailed description of the new launch files in the next updated tutorials:
- ROS 2 integration overview
- Launch Gazebo from ROS 2
- Use ROS 2 to interact with Gazebo
- Spawn a Gazebo model from ROS 2
The new launch files let you start Gazebo using a more idiomatic approach, following standard ROS launch tooling. Here’s an example:
ros2 launch ros_gz_sim ros_gz_sim.launch.py world_sdf_file:=sensors_demo.sdf bridge_name:=ros_gz_bridge config_file:=bridge_config.yaml use_composition:=True create_own_container:=True
We can now start Gazebo and the ros_gz bridge in a very simple way. Additionally, new XML and YAML elements are available to simplify the creation of launch files. As an example, here’s how you can start gzserver and the bridge from an XML file:
<launch>
<gz_server world_sdf_file="$(find-pkg-share my_package)/worlds/my_world.sdf" use_composition="True" create_own_container="True" />
<ros_gz_bridge bridge_name="bridge1" config_file="$(find-pkg-share my_package)/config/bridge_config.yaml" use_composition="True" create_own_container="False"/>
</launch>
Or from Python:
from launch import LaunchDescription
from launch_ros.substitutions import FindPackageShare
from launch.substitutions import PathJoinSubstitution
from ros_gz_sim.actions import GzServer
from ros_gz_bridge.actions import RosGzBridge
def generate_launch_description():
return LaunchDescription([
GzServer(
world_sdf_file=PathJoinSubstitution([FindPackageShare('my_package'), 'worlds/my_world.sdf']),
use_composition=str(True),
create_own_container=str(True),),
RosGzBridge(
bridge_name='bridge1',
config_file=PathJoinSubstitution([FindPackageShare('ros_gz_bridge'), 'config/my_config.yaml']),
use_composition=str(True),
create_own_container=str(False),)
])
Performance
Two new parameters use_composition and create_own_container are also available in all the new launch files to leverage the ability to launch composable nodes. The use_composition parameter allows us to run Gazebo, the ros_gz bridge, and other potential ROS composable nodes within the same process. This improves performance by avoiding message serialization between Gazebo and ROS.
The parameter create_own_container only makes sense when use_composition is set to True. This parameter lets you control whether you start a ROS container for your composable nodes or you defer to an external ROS container.
Here’s an example plot showing the time needed to receive 1000 images on the ROS side, published from Gazebo Transport. You can see how the time needed to receive the images drops when we combine more nodes within the same ROS container.
You can find the code and commands to generate this plot in this gist.