SMACC2
sm_dance_bot_strikes_back_launch.py
Go to the documentation of this file.
1# Copyright (c) 2018 Intel Corporation
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
15"""This is all-in-one launch script intended for use by nav2 developers."""
16
17import os
18
19from ament_index_python.packages import get_package_share_directory
20
21from launch import LaunchDescription
22from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
23from launch.conditions import IfCondition
24from launch.launch_description_sources import PythonLaunchDescriptionSource
25from launch.substitutions import LaunchConfiguration
26from launch_ros.actions import Node
27
28
30 # Get the launch directory
31 sm_dance_bot_strikes_back_dir = get_package_share_directory("sm_dance_bot_strikes_back")
32 sm_dance_bot_strikes_back_launch_dir = os.path.join(sm_dance_bot_strikes_back_dir, "launch")
33
34 # Create the launch configuration variables
35 slam = LaunchConfiguration("slam")
36 namespace = LaunchConfiguration("namespace")
37 use_namespace = LaunchConfiguration("use_namespace")
38 map_yaml_file = LaunchConfiguration("map")
39 use_sim_time = LaunchConfiguration("use_sim_time")
40 params_file = LaunchConfiguration("params_file")
41 default_nav_to_pose_bt_xml = LaunchConfiguration("default_nav_to_pose_bt_xml")
42 autostart = LaunchConfiguration("autostart")
43 show_gz_lidar = LaunchConfiguration("show_gz_lidar")
44
45 # Launch configuration variables specific to simulation
46 rviz_config_file = LaunchConfiguration("rviz_config_file")
47
48 use_robot_state_pub = LaunchConfiguration("use_robot_state_pub")
49 use_rviz = LaunchConfiguration("use_rviz")
50
51 urdf = os.path.join(sm_dance_bot_strikes_back_dir, "urdf", "turtlebot3_waffle.urdf")
52
53 # Map fully qualified names to relative ones so the node's namespace can be prepended.
54 # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
55 # https://github.com/ros/geometry2/issues/32
56 # https://github.com/ros/robot_state_publisher/pull/30
57 # TODO(orduno) Substitute with `PushNodeRemapping`
58 # https://github.com/ros2/launch_ros/issues/56
59 remappings = [("/tf", "tf"), ("/tf_static", "tf_static")]
60
61 # Declare the launch arguments
62 declare_namespace_cmd = DeclareLaunchArgument(
63 "namespace", default_value="", description="Top-level namespace"
64 )
65
66 declare_use_namespace_cmd = DeclareLaunchArgument(
67 "use_namespace",
68 default_value="false",
69 description="Whether to apply a namespace to the navigation stack",
70 )
71
72 declare_show_gz_lidar = DeclareLaunchArgument(
73 "show_gz_lidar",
74 default_value="true",
75 description="Whether to apply a namespace to the navigation stack",
76 )
77
78 declare_slam_cmd = DeclareLaunchArgument(
79 "slam", default_value="True", description="Whether run a SLAM"
80 )
81
82 declare_use_sim_time_cmd = DeclareLaunchArgument(
83 "use_sim_time", default_value="true", description="Use simulation (Gazebo) clock if true"
84 )
85
86 declare_params_file_cmd = DeclareLaunchArgument(
87 "params_file",
88 default_value=os.path.join(
89 sm_dance_bot_strikes_back_dir, "params", "nav2z_client", "nav2_params.yaml"
90 ),
91 description="Full path to the ROS2 parameters file to use for all launched nodes",
92 )
93
94 declare_bt_xml_cmd = DeclareLaunchArgument(
95 "default_nav_to_pose_bt_xml",
96 default_value=os.path.join(
97 sm_dance_bot_strikes_back_dir, "params", "nav2z_client", "navigation_tree.xml"
98 ),
99 description="Full path to the behavior tree xml file to use",
100 )
101
102 declare_autostart_cmd = DeclareLaunchArgument(
103 "autostart", default_value="true", description="Automatically startup the nav2 stack"
104 )
105
106 declare_rviz_config_file_cmd = DeclareLaunchArgument(
107 "rviz_config_file",
108 default_value=os.path.join(
109 sm_dance_bot_strikes_back_dir, "rviz", "nav2_default_view.rviz"
110 ),
111 description="Full path to the RVIZ config file to use",
112 )
113
114 declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
115 "use_robot_state_pub",
116 default_value="True",
117 description="Whether to start the robot state publisher",
118 )
119
120 declare_use_rviz_cmd = DeclareLaunchArgument(
121 "use_rviz", default_value="True", description="Whether to start RVIZ"
122 )
123
124 declare_map_yaml_cmd = DeclareLaunchArgument(
125 "map",
126 default_value=os.path.join(
127 sm_dance_bot_strikes_back_launch_dir, "maps", "turtlebot3_world.yaml"
128 ),
129 description="Full path to map file to load",
130 )
131
132 start_robot_state_publisher_cmd = Node(
133 condition=IfCondition(use_robot_state_pub),
134 package="robot_state_publisher",
135 executable="robot_state_publisher",
136 name="robot_state_publisher",
137 namespace=namespace,
138 output="screen",
139 parameters=[{"use_sim_time": use_sim_time}],
140 remappings=remappings,
141 arguments=[urdf],
142 )
143
144 rviz_cmd = IncludeLaunchDescription(
145 PythonLaunchDescriptionSource(
146 os.path.join(sm_dance_bot_strikes_back_launch_dir, "rviz_launch.py")
147 ),
148 condition=IfCondition(use_rviz),
149 launch_arguments={
150 "namespace": "",
151 "use_namespace": "False",
152 "rviz_config": rviz_config_file,
153 }.items(),
154 )
155
156 bringup_cmd = IncludeLaunchDescription(
157 PythonLaunchDescriptionSource(
158 os.path.join(sm_dance_bot_strikes_back_launch_dir, "bringup_launch.py")
159 ),
160 launch_arguments={
161 "namespace": namespace,
162 "use_namespace": use_namespace,
163 "autostart": autostart,
164 "params_file": params_file,
165 "slam": slam,
166 "map": map_yaml_file,
167 "use_sim_time": use_sim_time,
168 "default_nav_to_pose_bt_xml": default_nav_to_pose_bt_xml,
169 }.items(),
170 )
171
172 gazebo_simulator = IncludeLaunchDescription(
173 PythonLaunchDescriptionSource(
174 os.path.join(sm_dance_bot_strikes_back_launch_dir, "gazebo_launch.py")
175 ),
176 launch_arguments={"show_gz_lidar": show_gz_lidar}.items(),
177 )
178
179 xtermprefix = "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' -hold -geometry 1000x600 -sl 10000 -e"
180
181 sm_dance_bot_strikes_back_node = Node(
182 package="sm_dance_bot_strikes_back",
183 executable="sm_dance_bot_strikes_back_node",
184 name="SmDanceBotStrikesBack",
185 output="screen",
186 prefix=xtermprefix,
187 parameters=[
188 os.path.join(
189 get_package_share_directory("sm_dance_bot_strikes_back"),
190 "params/sm_dance_bot_strikes_back_config.yaml",
191 ),
192 ],
193 remappings=[
194 # ("/odom", "/odometry/filtered"),
195 # ("/sm_dance_bot_strikes_back_2/odom_tracker/odom_tracker_path", "/odom_tracker_path"),
196 # ("/sm_dance_bot_strikes_back_2/odom_tracker/odom_tracker_stacked_path", "/odom_tracker_path_stacked")
197 ],
198 arguments=["--ros-args", "--log-level", "INFO"],
199 )
200
201 led_action_server_node = Node(
202 package="sm_dance_bot_strikes_back",
203 executable="led_action_server_node",
204 output="screen",
205 prefix=xtermprefix,
206 )
207
208 temperature_action_server = Node(
209 package="sm_dance_bot_strikes_back",
210 executable="temperature_sensor_node",
211 output="screen",
212 prefix=xtermprefix,
213 )
214
215 service3_node = Node(
216 package="sm_dance_bot_strikes_back",
217 executable="service_node_3.py",
218 output="screen",
219 prefix=xtermprefix,
220 parameters=[
221 {"autostart": True, "node_names": ["ss", "dfa"]},
222 ],
223 )
224
225 # Create the launch description and populate
226 ld = LaunchDescription()
227
228 # Declare the launch options
229 ld.add_action(declare_namespace_cmd)
230 ld.add_action(declare_use_namespace_cmd)
231 ld.add_action(declare_slam_cmd)
232 ld.add_action(declare_map_yaml_cmd)
233 ld.add_action(declare_use_sim_time_cmd)
234 ld.add_action(declare_params_file_cmd)
235 ld.add_action(declare_bt_xml_cmd)
236 ld.add_action(declare_autostart_cmd)
237 ld.add_action(declare_map_yaml_cmd)
238 ld.add_action(declare_show_gz_lidar)
239
240 ld.add_action(declare_rviz_config_file_cmd)
241 ld.add_action(declare_use_robot_state_pub_cmd)
242 ld.add_action(declare_use_rviz_cmd)
243 ld.add_action(gazebo_simulator)
244
245 ld.add_action(sm_dance_bot_strikes_back_node)
246 ld.add_action(service3_node)
247 ld.add_action(temperature_action_server)
248 ld.add_action(led_action_server_node)
249
250 # # Add the actions to launch all of the navigation nodes
251 ld.add_action(start_robot_state_publisher_cmd)
252 ld.add_action(rviz_cmd)
253 ld.add_action(bringup_cmd)
254
255 return ld