A modern ROS 2 package that provides a convenient wrapper for launching Gazebo Harmonic simulations with customizable parameters and seamless integration.
- Overview
- Features
- Prerequisites
- Installation
- Usage
- Launch Arguments
- Package Structure
- Examples
- Contributing
- License
The gazebo_ros2 package simplifies the process of launching Gazebo Harmonic simulations within ROS 2 environments. It provides a configurable launch file that handles common Gazebo setup tasks, including world loading, resource path configuration, and simulation parameters.
- π Easy Integration: Simple launch file inclusion in your ROS 2 projects
- βοΈ Configurable Parameters: Extensive customization options for simulation setup
- π¨ GUI Control: Toggle between headless and GUI modes
- π Resource Management: Flexible path configuration for models and worlds
- π§ Plugin Support: Custom plugin path configuration
- π Auto-start: Optional automatic simulation start
- ROS 2 Jazzy or later
- Gazebo Harmonic
- Ubuntu 22.04 or later
sudo apt update && sudo apt install -y \
ros-${ROS_DISTRO}-ros-gz \
ros-${ROS_DISTRO}-ros-gz-sim-
Clone the repository:
cd ~/your_ws/src git clone https://github.com/your-username/gazebo_ros2.git
-
Build the package:
cd ~/your_ws colcon build --packages-select gazebo_ros2
-
Source the workspace:
source ~/your_ws/install/setup.bash
ros2 launch gazebo_ros2 gazebo_ros2.launch.pyros2 launch gazebo_ros2 gazebo_ros2.launch.py world_path:=/path/to/your/world.sdfros2 launch gazebo_ros2 gazebo_ros2.launch.py gui:=false| Parameter | Type | Default | Description |
|---|---|---|---|
gui |
bool |
true |
Enable GUI. If false, launches in server-only mode |
verbose |
string |
3 |
Verbosity level (0-4) for Gazebo simulation |
world_path |
string |
'' |
Absolute path to .world or .sdf file |
gz_sim_resource_path |
string |
'' |
Additional resource paths (colon-separated) |
gz_sim_plugin_path |
string |
'' |
Additional plugin paths (colon-separated) |
run_on_start |
bool |
true |
Start simulation immediately |
gazebo_ros2/
βββ gazebo_ros2/
β βββ __init__.py # Python package initialization
βββ launch/
β βββ gazebo_ros2.launch.py # Main launch file
βββ resource/
β βββ gazebo_ros2 # ROS 2 resource marker
βββ test/
β βββ test_copyright.py # Copyright compliance tests
β βββ test_flake8.py # Code style tests
β βββ test_pep257.py # Docstring tests
βββ LICENSE # License file
βββ package.xml # Package metadata
βββ README.md # This file
βββ setup.cfg # Setup configuration
βββ setup.py # Package setup script
#!/usr/bin/env python3
import os
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
# Get package directory
gazebo_ros2_share = get_package_share_directory('gazebo_ros2')
# Include gazebo_ros2 launch
gazebo_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([
os.path.join(gazebo_ros2_share, 'launch', 'gazebo_ros2.launch.py')
]),
launch_arguments={
'gui': 'true',
'verbose': '3'
}.items()
)
return LaunchDescription([gazebo_launch])#!/usr/bin/env python3
import os
from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory
def generate_launch_description():
# Package paths in the package share directory
tb3_gz_pkg_share = get_package_share_directory('turtlebot3_gazebo')
gz_ros2_share = get_package_share_directory('gazebo_ros2')
# Join file paths with package share directory
world_path = os.path.join(tb3_gz_pkg_share, 'worlds', 'turtlebot3_dqn_stage2.world')
gazebo_ros2_launch_path = os.path.join(gz_ros2_share, 'launch', 'gazebo_ros2.launch.py')
# Include gazebo_ros2 launch file + pass args
gazebo_ros2_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource(gazebo_ros2_launch_path),
launch_arguments={
'world_path': world_path,
'gz_sim_resource_path': os.path.join(tb3_gz_pkg_share, 'models'),
'gui': 'true',
'verbose': '4',
'run_on_start': 'true',
}.items(),
)
return LaunchDescription([
gazebo_ros2_launch
])
Fig. 1: LaunchMap visualization of example code
Run the package tests:
# Run all tests
colcon test --packages-select gazebo_ros2
# Run specific tests
python3 -m pytest src/gazebo_ros2/test/Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Maintainer: Kevin Eppacher