Skip to content

TW-Robotics/gazebo_ros2

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

gazebo_ros2

License ROS2 Jazzy Gazebo Harmonic

A modern ROS 2 package that provides a convenient wrapper for launching Gazebo Harmonic simulations with customizable parameters and seamless integration.

πŸ“‹ Table of Contents

🎯 Overview

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.

✨ Features

  • πŸš€ 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

πŸ“¦ Prerequisites

  • ROS 2 Jazzy or later
  • Gazebo Harmonic
  • Ubuntu 22.04 or later

πŸ› οΈ Installation

System Dependencies

sudo apt update && sudo apt install -y \
    ros-${ROS_DISTRO}-ros-gz \
    ros-${ROS_DISTRO}-ros-gz-sim

Package Installation

  1. Clone the repository:

    cd ~/your_ws/src
    git clone https://github.com/your-username/gazebo_ros2.git
  2. Build the package:

    cd ~/your_ws
    colcon build --packages-select gazebo_ros2
  3. Source the workspace:

    source ~/your_ws/install/setup.bash

πŸš€ Usage

Basic Launch

ros2 launch gazebo_ros2 gazebo_ros2.launch.py

With Custom World

ros2 launch gazebo_ros2 gazebo_ros2.launch.py world_path:=/path/to/your/world.sdf

Headless Mode

ros2 launch gazebo_ros2 gazebo_ros2.launch.py gui:=false

βš™οΈ Launch Arguments

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

πŸ“ Package Structure

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

πŸ“š Examples

Example 1: Basic Integration

#!/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])

Example 2: Load Turtlebot3 World

#!/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

πŸ§ͺ Testing

Run the package tests:

# Run all tests
colcon test --packages-select gazebo_ros2

# Run specific tests
python3 -m pytest src/gazebo_ros2/test/

🀝 Contributing

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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

πŸ”— Related Projects


Maintainer: Kevin Eppacher

About

Gazebo (Harmonic) Wrapper for ROS 2 Jazzy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%