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_strikes_back_dir = get_package_share_directory("sm_dance_bot_strikes_back")
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_strikes_back_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_strikes_back_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'),
98 # 'behavior_trees', 'navigate_w_replanning_and_recovery.xml'),
99 default_value=os.path.join(
100 sm_dance_bot_strikes_back_dir,
101 "params",
102 "nav2z_client",
103 "navigation_tree.xml",
104 ),
105 description="Full path to the behavior tree xml file to use",
106 ),
107 DeclareLaunchArgument(
108 "map_subscribe_transient_local",
109 default_value="false",
110 description="Whether to set the map subscriber QoS to transient local",
111 ),
112 Node(
113 package="nav2_controller",
114 executable="controller_server",
115 output="screen",
116 prefix=xtermprefix,
117 parameters=[configured_params],
118 remappings=remappings,
119 arguments=["--ros-args", "--log-level", "INFO"],
120 ),
121 Node(
122 package="nav2_planner",
123 executable="planner_server",
124 name="planner_server",
125 output="screen",
126 prefix=xtermprefix,
127 parameters=[configured_params],
128 remappings=remappings,
129 arguments=["--ros-args", "--log-level", "INFO"],
130 ),
131 Node(
132 package="nav2_recoveries",
133 executable="recoveries_server",
134 name="recoveries_server",
135 output="screen",
136 parameters=[configured_params],
137 remappings=remappings,
138 arguments=["--ros-args", "--log-level", "INFO"],
139 ),
140 Node(
141 package="nav2_bt_navigator",
142 executable="bt_navigator",
143 name="bt_navigator",
144 output="screen",
145 prefix=xtermprefix,
146 parameters=[configured_params],
147 remappings=remappings,
148 arguments=["--ros-args", "--log-level", "INFO"],
149 ),
150 Node(
151 package="nav2_waypoint_follower",
152 executable="waypoint_follower",
153 name="waypoint_follower",
154 output="screen",
155 parameters=[configured_params],
156 remappings=remappings,
157 ),
158 Node(
159 package="nav2_lifecycle_manager",
160 executable="lifecycle_manager",
161 name="lifecycle_manager_navigation",
162 output="screen",
163 prefix=xtermprefix,
164 parameters=[
165 {"use_sim_time": use_sim_time},
166 {"autostart": autostart},
167 {"node_names": lifecycle_nodes},
168 ],
169 arguments=["--ros-args", "--log-level", "INFO"],
170 ),
171 ]
172 )