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
23
24
26 declare_use_simulator_cmd = DeclareLaunchArgument(
27 "use_simulator", default_value="False", description="Whether to execute gzclient)"
28 )
29
30 use_simulator = LaunchConfiguration("use_simulator")
31 world = LaunchConfiguration("world")
32 headless = LaunchConfiguration("headless")
33 show_gz_lidar = LaunchConfiguration("show_gz_lidar")
34
35 sm_dance_bot_strikes_back_dir = get_package_share_directory("sm_dance_bot_strikes_back")
36 launch_dir = os.path.join(sm_dance_bot_strikes_back_dir, "launch")
37
38 declare_use_simulator_cmd = DeclareLaunchArgument(
39 "use_simulator", default_value="True", description="Whether to start the simulator"
40 )
41
42 declare_simulator_cmd = DeclareLaunchArgument(
43 "headless", default_value="False", description="Whether to execute gzclient)"
44 )
45
46 declare_show_gz_lidar = DeclareLaunchArgument(
47 "show_gz_lidar",
48 default_value="True",
49 description="Whether to apply a namespace to the navigation stack",
50 )
51
52 declare_world_cmd = DeclareLaunchArgument(
53 "world",
54 default_value=os.path.join(
55 sm_dance_bot_strikes_back_dir, "worlds", "ridgeback_race.world"
56 ),
57 description="Full path to world model file to load",
58 condition=IfCondition(show_gz_lidar),
59 )
60
61 declare_world_cmd_2 = DeclareLaunchArgument(
62 "world",
63 default_value=os.path.join(
64 sm_dance_bot_strikes_back_dir, "worlds", "ridgeback_race_no_lidar.world"
65 ),
66 description="Full path to world model file to load",
67 condition=UnlessCondition(show_gz_lidar),
68 )
69
70 # Create the launch description and populate
71 ld = LaunchDescription()
72
73 # xtermprefix = "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' " \
74 # "-hold -geometry 1000x600 -sl 10000 -e"
75
76 gzenv = dict(os.environ)
77 model_database_uri = os.environ["GAZEBO_MODEL_PATH"]
78 gzenv["GAZEBO_MODEL_DATABASE_URI"] = model_database_uri
79
80 # Specify the actions
81 start_gazebo_server_cmd = ExecuteProcess(
82 condition=IfCondition(use_simulator),
83 cmd=["gzserver", "-s", "libgazebo_ros_init.so", world, "--verbose"],
84 env=gzenv,
85 cwd=[launch_dir],
86 output="screen",
87 )
88
89 start_gazebo_client_cmd = ExecuteProcess(
90 condition=IfCondition(PythonExpression([use_simulator, " and not ", headless])),
91 cmd=["gzclient"],
92 cwd=[launch_dir],
93 env=gzenv,
94 output="screen",
95 )
96
97 # Add any conditioned actions
98 ld.add_action(declare_simulator_cmd)
99 ld.add_action(declare_use_simulator_cmd)
100 ld.add_action(declare_world_cmd)
101 ld.add_action(declare_world_cmd_2)
102
103 ld.add_action(declare_show_gz_lidar)
104
105 ld.add_action(start_gazebo_server_cmd)
106 ld.add_action(start_gazebo_client_cmd)
107
108 return ld
def generate_launch_description()