Skip to content

Instantly share code, notes, and snippets.

@rfzeg
Last active March 10, 2022 21:51
Show Gist options
  • Save rfzeg/6bcb59ed777340b39c08fa9b82e409a4 to your computer and use it in GitHub Desktop.
Save rfzeg/6bcb59ed777340b39c08fa9b82e409a4 to your computer and use it in GitHub Desktop.
ROS2 launch file that launches Gazebo including a Gazebo world
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
def generate_launch_description():
# gazebo.launch.py package
pkg_gazebo_ros = get_package_share_directory('gazebo_ros')
# determine package where .world file is located
pkg_dolly_gazebo = get_package_share_directory('dolly_gazebo')
# Gazebo launch
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_gazebo_ros, 'launch', 'gazebo.launch.py'),
)
)
return LaunchDescription([
DeclareLaunchArgument(
'world',
default_value=[os.path.join(pkg_dolly_gazebo, 'worlds', 'dolly_empty.world'), ''],
description='SDF world file'),
gazebo
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment