SMACC2
navigation_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
15import os
16
17from ament_index_python.packages import get_package_share_directory
18
19from launch import LaunchDescription
20from launch.actions import DeclareLaunchArgument, SetEnvironmentVariable
21from launch.substitutions import LaunchConfiguration
22from launch_ros.actions import Node
23from nav2_common.launch import RewrittenYaml
24
25
27 # Get the launch directory
28 sm_dance_bot_warehouse_2_dir = get_package_share_directory("sm_dance_bot_warehouse_2")
29
30 namespace = LaunchConfiguration("namespace")
31 use_sim_time = LaunchConfiguration("use_sim_time")
32 autostart = LaunchConfiguration("autostart")
33 params_file = LaunchConfiguration("params_file")
34 default_nav_to_pose_bt_xml = LaunchConfiguration("default_nav_to_pose_bt_xml")
35 map_subscribe_transient_local = LaunchConfiguration("map_subscribe_transient_local")
36
37 lifecycle_nodes = ["controller_server", "planner_server", "recoveries_server", "bt_navigator"]
38
39 # Map fully qualified names to relative ones so the node's namespace can be prepended.
40 # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
41 # https://github.com/ros/geometry2/issues/32
42 # https://github.com/ros/robot_state_publisher/pull/30
43 # TODO(orduno) Substitute with `PushNodeRemapping`
44 # https://github.com/ros2/launch_ros/issues/56
45 remappings = [("/tf", "tf"), ("/tf_static", "tf_static")]
46
47 # Create our own temporary YAML files that include substitutions
48 param_substitutions = {
49 "use_sim_time": use_sim_time,
50 # 'default_nav_to_pose_bt_xml': default_nav_to_pose_bt_xml,
51 "default_nav_to_pose_bt_xml": os.path.join(
52 sm_dance_bot_warehouse_2_dir, "params", "nav2z_client", "navigation_tree.xml"
53 ),
54 "autostart": autostart,
55 "map_subscribe_transient_local": map_subscribe_transient_local,
56 }
57
58 configured_params = RewrittenYaml(
59 source_file=params_file,
60 root_key=namespace,
61 param_rewrites=param_substitutions,
62 convert_types=True,
63 )
64
65 xtermprefix = "xterm -xrm 'XTerm*scrollBar: true' -xrm 'xterm*rightScrollBar: true' -hold -geometry 1000x600 -sl 10000 -e"
66
67 print("+********************************")
68 print(str(param_substitutions))
69 print(str(default_nav_to_pose_bt_xml))
70
71 return LaunchDescription(
72 [
73 # Set env var to print messages to stdout immediately
74 SetEnvironmentVariable("RCUTILS_LOGGING_BUFFERED_STREAM", "1"),
75 DeclareLaunchArgument(
76 "namespace", default_value="", description="Top-level namespace"
77 ),
78 DeclareLaunchArgument(
79 "use_sim_time",
80 default_value="false",
81 description="Use simulation (Gazebo) clock if true",
82 ),
83 DeclareLaunchArgument(
84 "autostart",
85 default_value="true",
86 description="Automatically startup the nav2 stack",
87 ),
88 DeclareLaunchArgument(
89 "params_file",
90 default_value=os.path.join(
91 sm_dance_bot_warehouse_2_dir, "params", "nav2z_client", "nav2_params.yaml"
92 ),
93 description="Full path to the ROS2 parameters file to use",
94 ),
95 DeclareLaunchArgument(
96 "default_nav_to_pose_bt_xml",
97 # default_value=os.path.join(get_package_share_directory('nav2_bt_navigator'),'behavior_trees', 'navigate_w_replanning_and_recovery.xml'),
98 default_value=os.path.join(
99 sm_dance_bot_warehouse_2_dir, "params", "nav2z_client", "navigation_tree.xml"
100 ),
101 description="Full path to the behavior tree xml file to use",
102 ),
103 DeclareLaunchArgument(
104 "map_subscribe_transient_local",
105 default_value="false",
106 description="Whether to set the map subscriber QoS to transient local",
107 ),
108 Node(
109 package="nav2_controller",
110 executable="controller_server",
111 output="screen",
112 prefix=xtermprefix,
113 parameters=[configured_params],
114 remappings=remappings,
115 arguments=["--ros-args", "--log-level", "INFO"],
116 ),
117 Node(
118 package="nav2_planner",
119 executable="planner_server",
120 name="planner_server",
121 output="screen",
122 prefix=xtermprefix,
123 parameters=[configured_params],
124 remappings=remappings,
125 arguments=["--ros-args", "--log-level", "INFO"],
126 ),
127 Node(
128 package="nav2_recoveries",
129 executable="recoveries_server",
130 name="recoveries_server",
131 output="screen",
132 parameters=[configured_params],
133 remappings=remappings,
134 arguments=["--ros-args", "--log-level", "INFO"],
135 ),
136 Node(
137 package="nav2_bt_navigator",
138 executable="bt_navigator",
139 name="bt_navigator",
140 output="screen",
141 prefix=xtermprefix,
142 parameters=[configured_params],
143 remappings=remappings,
144 arguments=["--ros-args", "--log-level", "INFO"],
145 ),
146 Node(
147 package="nav2_waypoint_follower",
148 executable="waypoint_follower",
149 name="waypoint_follower",
150 output="screen",
151 parameters=[configured_params],
152 remappings=remappings,
153 ),
154 Node(
155 package="nav2_lifecycle_manager",
156 executable="lifecycle_manager",
157 name="lifecycle_manager_navigation",
158 output="screen",
159 prefix=xtermprefix,
160 parameters=[
161 {"use_sim_time": use_sim_time},
162 {"autostart": autostart},
163 {"node_names": lifecycle_nodes},
164 ],
165 arguments=["--ros-args", "--log-level", "INFO"],
166 ),
167 ]
168 )