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
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
35 sm_husky_barrel_search_1 = get_package_share_directory("sm_husky_barrel_search_1")
36 launch_dir = os.path.join(sm_husky_barrel_search_1, "launch")
37
38 declare_use_simulator_cmd = DeclareLaunchArgument(
39 "use_simulator", default_value="True", description="Whether to start the simulator"
40 )
41
42 declare_headless_simulator_argument = DeclareLaunchArgument(
43 "headless", default_value="False", description="Whether to execute gzclient)"
44 )
45
46 declare_world_cmd = DeclareLaunchArgument(
47 "world",
48 default_value=os.path.join(sm_husky_barrel_search_1, "worlds", "industrial_sim.world"),
49 description="Full path to world model file to load",
50 )
51
52 # nolidar world
53 declare_world_cmd_2 = DeclareLaunchArgument(
54 "world",
55 default_value=os.path.join(sm_husky_barrel_search_1, "worlds", "industrial_sim.world"),
56 description="Full path to world model file to load",
57 )
58
59 declare_urdf = DeclareLaunchArgument(
60 "urdf",
61 default_value=os.path.join(
62 sm_husky_barrel_search_1, "models", "husky_turtlebot3_waffle", "model.sdf"
63 ),
64 description="",
65 )
66
67 # Create the launch description and populate
68 ld = LaunchDescription()
69
70 xtermprefix = (
71 "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' "
72 "-hold -geometry 1000x600 -sl 10000 -e"
73 )
74
75 gzenv = dict(os.environ)
76 model_database_uri = os.environ["GAZEBO_MODEL_PATH"]
77 gzenv["GAZEBO_MODEL_DATABASE_URI"] = model_database_uri
78
79 # Specify the actions
80 start_gazebo_server_cmd = ExecuteProcess(
81 condition=IfCondition(use_simulator),
82 cmd=[
83 "gzserver",
84 "-s",
85 "libgazebo_ros_init.so",
86 "-s",
87 "libgazebo_ros_factory.so",
88 world,
89 "--verbose",
90 ],
91 env=gzenv,
92 cwd=[launch_dir],
93 output="screen",
94 prefix=xtermprefix,
95 )
96
97 start_gazebo_client_cmd = ExecuteProcess(
98 condition=IfCondition(PythonExpression([use_simulator, " and not ", headless])),
99 cmd=["gzclient"],
100 cwd=[launch_dir],
101 env=gzenv,
102 output="screen",
103 )
104
105 spawn_entity_node = Node(
106 package="gazebo_ros",
107 executable="spawn_entity.py",
108 name="gazebo_ros",
109 arguments=[
110 "-entity",
111 "turtlebot3_waffle",
112 "-file",
113 LaunchConfiguration("urdf"),
114 "-x",
115 "0",
116 "-y",
117 "0",
118 "-z",
119 "0.1",
120 "-Y",
121 "0",
122 ],
123 )
124
125 # Add any conditioned actions
126 ld.add_action(declare_headless_simulator_argument)
127 ld.add_action(declare_use_simulator_cmd)
128 ld.add_action(declare_world_cmd)
129 ld.add_action(declare_world_cmd_2)
130 ld.add_action(declare_urdf)
131
132 ld.add_action(start_gazebo_server_cmd)
133 ld.add_action(start_gazebo_client_cmd)
134 ld.add_action(spawn_entity_node)
135
136 return ld
def generate_launch_description()