SMACC2
localization_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 bringup_dir = get_package_share_directory("nav2_bringup")
29
30 namespace = LaunchConfiguration("namespace")
31 map_yaml_file = LaunchConfiguration("map")
32 use_sim_time = LaunchConfiguration("use_sim_time")
33 autostart = LaunchConfiguration("autostart")
34 params_file = LaunchConfiguration("params_file")
35 lifecycle_nodes = ["map_server", "amcl"]
36
37 # Map fully qualified names to relative ones so the node's namespace can be prepended.
38 # In case of the transforms (tf), currently, there doesn't seem to be a better alternative
39 # https://github.com/ros/geometry2/issues/32
40 # https://github.com/ros/robot_state_publisher/pull/30
41 # TODO(orduno) Substitute with `PushNodeRemapping`
42 # https://github.com/ros2/launch_ros/issues/56
43 remappings = [("/tf", "tf"), ("/tf_static", "tf_static")]
44
45 # Create our own temporary YAML files that include substitutions
46 param_substitutions = {"use_sim_time": use_sim_time, "yaml_filename": map_yaml_file}
47
48 configured_params = RewrittenYaml(
49 source_file=params_file,
50 root_key=namespace,
51 param_rewrites=param_substitutions,
52 convert_types=True,
53 )
54
55 return LaunchDescription(
56 [
57 # Set env var to print messages to stdout immediately
58 SetEnvironmentVariable("RCUTILS_LOGGING_BUFFERED_STREAM", "1"),
59 DeclareLaunchArgument(
60 "namespace", default_value="", description="Top-level namespace"
61 ),
62 DeclareLaunchArgument(
63 "map",
64 default_value=os.path.join(bringup_dir, "maps", "turtlebot3_world.yaml"),
65 description="Full path to map yaml file to load",
66 ),
67 DeclareLaunchArgument(
68 "use_sim_time",
69 default_value="false",
70 description="Use simulation (Gazebo) clock if true",
71 ),
72 DeclareLaunchArgument(
73 "autostart",
74 default_value="true",
75 description="Automatically startup the nav2 stack",
76 ),
77 DeclareLaunchArgument(
78 "params_file",
79 default_value=os.path.join(bringup_dir, "params", "nav2_params.yaml"),
80 description="Full path to the ROS2 parameters file to use",
81 ),
82 Node(
83 package="nav2_map_server",
84 executable="map_server",
85 name="map_server",
86 output="screen",
87 parameters=[configured_params],
88 remappings=remappings,
89 ),
90 Node(
91 package="nav2_amcl",
92 executable="amcl",
93 name="amcl",
94 output="screen",
95 parameters=[configured_params],
96 remappings=remappings,
97 ),
98 Node(
99 package="nav2_lifecycle_manager",
100 executable="lifecycle_manager",
101 name="lifecycle_manager_localization",
102 output="screen",
103 parameters=[
104 {"use_sim_time": use_sim_time},
105 {"autostart": autostart},
106 {"node_names": lifecycle_nodes},
107 ],
108 ),
109 ]
110 )