-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgazebo.launch.py
63 lines (55 loc) · 2.23 KB
/
gazebo.launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import launch
from launch.substitutions import Command, LaunchConfiguration
from launch.actions import DeclareLaunchArgument
import launch_ros
from launch_ros.actions import Node
import os
def generate_launch_description():
pkg_share = launch_ros.substitutions.FindPackageShare(
package='tortoisebot_gazebo').find('tortoisebot_gazebo')
world_path = os.path.join(pkg_share, 'worlds/room2.sdf')
# Define launch arguments
use_sim_time = LaunchConfiguration('use_sim_time')
# Set default value to 'true'
gui = LaunchConfiguration('gui')
# Set default value to 'false'
headless = LaunchConfiguration('headless')
return launch.LaunchDescription([
# Declare launch arguments
launch.actions.DeclareLaunchArgument(
name='use_sim_time',
default_value='False',
description='Flag to enable use_sim_time'
),
launch.actions.DeclareLaunchArgument(
name='gui',
default_value='false',
description='Flag to enable Gazebo GUI'
),
launch.actions.DeclareLaunchArgument(
name='headless',
default_value='true',
description='Flag to enable headless mode'
),
# Execute Gazebo with specified arguments
launch.actions.ExecuteProcess(
cmd=['gazebo', '--verbose', '-s', 'libgazebo_ros_init.so',
'-s', 'libgazebo_ros_factory.so', world_path],
output='screen',
additional_env={'GAZEBO_PLUGIN_PATH': os.environ['GAZEBO_PLUGIN_PATH'],
'GAZEBO_MODEL_PATH': os.environ['GAZEBO_MODEL_PATH'],
'GAZEBO_MASTER_URI': os.environ['GAZEBO_MASTER_URI']},
# Pass the gui and headless arguments to Gazebo
arguments=['--', '-gui' if gui == 'true' else '',
'--headless' if headless == 'true' else '']
),
# Spawn Gazebo entity
Node(
package='gazebo_ros',
executable='spawn_entity.py',
arguments=['-entity', 'tortoisebot',
'-topic', 'robot_description'],
parameters=[{'use_sim_time': use_sim_time}],
output='screen',
),
])