SMACC2
gazebo_launch.py
Go to the documentation of this file.
1# Copyright 2021 RobosoftAI Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import os
16
17from ament_index_python.packages import get_package_share_directory
18
19from launch import LaunchDescription
20from launch.actions import DeclareLaunchArgument, ExecuteProcess
21from launch.conditions import IfCondition, UnlessCondition
22from launch.substitutions import LaunchConfiguration, PythonExpression
23from launch_ros.actions.node import Node
24
25
27 declare_use_simulator_cmd = DeclareLaunchArgument(
28 "use_simulator", default_value="False", description="Whether to execute gzclient)"
29 )
30
31 use_simulator = LaunchConfiguration("use_simulator")
32 world = LaunchConfiguration("world")
33 headless = LaunchConfiguration("headless")
34 show_gz_lidar = LaunchConfiguration("show_gz_lidar")
35
36 sm_dance_bot_warehouse_2_dir = get_package_share_directory("sm_dance_bot_warehouse_2")
37 launch_dir = os.path.join(sm_dance_bot_warehouse_2_dir, "launch")
38
39 declare_use_simulator_cmd = DeclareLaunchArgument(
40 "use_simulator", default_value="True", description="Whether to start the simulator"
41 )
42
43 declare_headless_simulator_argument = DeclareLaunchArgument(
44 "headless", default_value="True", description="Whether to execute gzclient)"
45 )
46
47 declare_show_gz_lidar = DeclareLaunchArgument(
48 "show_gz_lidar",
49 default_value="True",
50 description="Whether to apply a namespace to the navigation stack",
51 )
52
53 declare_world_cmd = DeclareLaunchArgument(
54 "world",
55 default_value=os.path.join(sm_dance_bot_warehouse_2_dir, "worlds", "industrial_sim.world"),
56 description="Full path to world model file to load",
57 condition=IfCondition(show_gz_lidar),
58 )
59
60 # nolidar world
61 declare_world_cmd_2 = DeclareLaunchArgument(
62 "world",
63 default_value=os.path.join(sm_dance_bot_warehouse_2_dir, "worlds", "industrial_sim.world"),
64 description="Full path to world model file to load",
65 condition=UnlessCondition(show_gz_lidar),
66 )
67
68 declare_urdf = DeclareLaunchArgument(
69 "urdf",
70 default_value=os.path.join(
71 sm_dance_bot_warehouse_2_dir, "models", "turtlebot3_waffle", "model.sdf"
72 ),
73 description="",
74 )
75
76 # Create the launch description and populate
77 ld = LaunchDescription()
78
79 xtermprefix = (
80 "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' "
81 "-hold -geometry 1000x600 -sl 10000 -e"
82 )
83
84 gzenv = dict(os.environ)
85 model_database_uri = os.environ["GAZEBO_MODEL_PATH"]
86 gzenv["GAZEBO_MODEL_DATABASE_URI"] = model_database_uri
87
88 # Specify the actions
89 start_gazebo_server_cmd = ExecuteProcess(
90 condition=IfCondition(use_simulator),
91 cmd=[
92 "gzserver",
93 "-s",
94 "libgazebo_ros_init.so",
95 "-s",
96 "libgazebo_ros_factory.so",
97 world,
98 "--verbose",
99 ],
100 env=gzenv,
101 cwd=[launch_dir],
102 output="screen",
103 prefix=xtermprefix,
104 )
105
106 start_gazebo_client_cmd = ExecuteProcess(
107 condition=IfCondition(PythonExpression([use_simulator, " and not ", headless])),
108 cmd=["gzclient"],
109 cwd=[launch_dir],
110 env=gzenv,
111 output="screen",
112 )
113
114 spawn_entity_node = Node(
115 package="gazebo_ros",
116 executable="spawn_entity.py",
117 name="gazebo_ros",
118 arguments=[
119 "-entity",
120 "turtlebot3_waffle",
121 "-file",
122 LaunchConfiguration("urdf"),
123 "-x",
124 "0",
125 "-y",
126 "0",
127 "-z",
128 "0.5",
129 "-Y",
130 "0",
131 ],
132 )
133
134 # Add any conditioned actions
135 ld.add_action(declare_headless_simulator_argument)
136 ld.add_action(declare_use_simulator_cmd)
137 ld.add_action(declare_world_cmd)
138 ld.add_action(declare_world_cmd_2)
139 ld.add_action(declare_urdf)
140
141 ld.add_action(declare_show_gz_lidar)
142
143 ld.add_action(start_gazebo_server_cmd)
144 ld.add_action(start_gazebo_client_cmd)
145 ld.add_action(spawn_entity_node)
146
147 return ld
def generate_launch_description()