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_dir = get_package_share_directory("sm_dance_bot")
36 launch_dir = os.path.join(sm_dance_bot_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(sm_dance_bot_dir, "worlds", "ridgeback_race.world"),
55 description="Full path to world model file to load",
56 condition=IfCondition(show_gz_lidar),
57 )
58
59 declare_world_cmd_2 = DeclareLaunchArgument(
60 "world",
61 default_value=os.path.join(sm_dance_bot_dir, "worlds", "ridgeback_race_no_lidar.world"),
62 description="Full path to world model file to load",
63 condition=UnlessCondition(show_gz_lidar),
64 )
65
66 # Create the launch description and populate
67 ld = LaunchDescription()
68
69 # xtermprefix = "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' " \
70 # "-hold -geometry 1000x600 -sl 10000 -e"
71
72 gzenv = dict(os.environ)
73 model_database_uri = os.environ["GAZEBO_MODEL_PATH"]
74 gzenv["GAZEBO_MODEL_DATABASE_URI"] = model_database_uri
75
76 # Specify the actions
77 start_gazebo_server_cmd = ExecuteProcess(
78 condition=IfCondition(use_simulator),
79 cmd=["gzserver", "-s", "libgazebo_ros_init.so", world, "--verbose"],
80 env=gzenv,
81 cwd=[launch_dir],
82 output="screen",
83 )
84
85 start_gazebo_client_cmd = ExecuteProcess(
86 condition=IfCondition(PythonExpression([use_simulator, " and not ", headless])),
87 cmd=["gzclient"],
88 cwd=[launch_dir],
89 env=gzenv,
90 output="screen",
91 )
92
93 # Add any conditioned actions
94 ld.add_action(declare_simulator_cmd)
95 ld.add_action(declare_use_simulator_cmd)
96 ld.add_action(declare_world_cmd)
97 ld.add_action(declare_world_cmd_2)
98
99 ld.add_action(declare_show_gz_lidar)
100
101 ld.add_action(start_gazebo_server_cmd)
102 ld.add_action(start_gazebo_client_cmd)
103
104 return ld
def generate_launch_description()