Gazebo(gz) - Grisson/ros2_learning_notes GitHub Wiki
Installation
- I'm using ros2 jazzy. So, the recommended Gazebo version is Harmoni .
Launch Gazebo
gz sim shapes.sdf
gz sim -v 4 shapes.sdf
env -u WAYLAND_DISPLAY gz sim -v 4 shapes.sdf
QT_QPA_PLATFORM=xcb gz sim -v 4 shapes.sdf
ROS2 Integration
- Composition
-
use_composition
True means both Gazebo and bridge are loaded into same ROS container (may or may be be created by ros_gz) -
create_own_container
False means Gazebo are loaded into container created by other launch files.
-
Launch from ROS2
-
Leverage
ros_gz_sim
package- gz_server.launch.py
Start Gazebo server only. e.g.ros2 launch ros_gz_sim gz_server.launch.py world_sdf_file:=empty.sdf
- gz_sim.launch.py
Start Gazebo (both server and UI). e.g.ros2 launch ros_gz_sim gz_sim.launch.py gz_args:=empty.sdf
- gz_server.launch.py
-
Python launch file
- Easy approach via
gzserver
- Easy approach via
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from ros_gz_sim.actions import GzServer
def generate_launch_description():
declare_world_sdf_file_cmd = DeclareLaunchArgument(
'world_sdf_file', default_value='',
description='Path to the SDF world file')
# Create the launch description and populate
ld = LaunchDescription([
GzServer(
world_sdf_file=LaunchConfiguration('world_sdf_file')
),
])
# Declare the launch options
ld.add_action(declare_world_sdf_file_cmd)
return ld
- Launching with ros_gz_bridge
- ros2 launch ros_gz_sim ros_gz_sim.launch.py world_sdf_file:=empty.sdf bridge_name:=ros_gz_bridge config_file:=<path_to_your_YAML_file> use_composition:=True create_own_container:=True
Q&A
- Q: libEGL warning: egl: failed to create dri2 screen
A: This warning is printed by Ogre 2, the underlying rendering engine used by Gazebo, during its initialization phase. It might suggest a fallback to using the Mesa driver with llvmpipe, which indicates that hardware acceleration might not be fully utilized. It's usually just a harmless message from the underlying rendering engine Ogre 2 and doesn't affect Gazebo's functionality.