15 """This is all-in-one launch script intended for use by nav2 developers."""
19 from ament_index_python.packages
import get_package_share_directory
21 from launch
import LaunchDescription
22 from launch.actions
import (
23 DeclareLaunchArgument,
25 IncludeLaunchDescription,
27 from launch.conditions
import IfCondition
28 from launch.launch_description_sources
import PythonLaunchDescriptionSource
29 from launch.substitutions
import LaunchConfiguration
30 from launch_ros.actions
import Node, SetParameter
31 from launch_ros.descriptions
import ParameterFile
36 def generate_launch_description():
38 bringup_dir = get_package_share_directory(
'nav2_bringup')
39 loopback_sim_dir = get_package_share_directory(
'nav2_loopback_sim')
40 launch_dir = os.path.join(bringup_dir,
'launch')
41 sim_dir = get_package_share_directory(
'nav2_minimal_tb3_sim')
44 namespace = LaunchConfiguration(
'namespace')
45 use_namespace = LaunchConfiguration(
'use_namespace')
46 map_yaml_file = LaunchConfiguration(
'map')
47 params_file = LaunchConfiguration(
'params_file')
48 autostart = LaunchConfiguration(
'autostart')
49 use_composition = LaunchConfiguration(
'use_composition')
50 use_respawn = LaunchConfiguration(
'use_respawn')
53 rviz_config_file = LaunchConfiguration(
'rviz_config_file')
54 use_robot_state_pub = LaunchConfiguration(
'use_robot_state_pub')
55 use_rviz = LaunchConfiguration(
'use_rviz')
57 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
60 declare_namespace_cmd = DeclareLaunchArgument(
61 'namespace', default_value=
'', description=
'Top-level namespace'
64 declare_use_namespace_cmd = DeclareLaunchArgument(
66 default_value=
'false',
67 description=
'Whether to apply a namespace to the navigation stack',
70 declare_map_yaml_cmd = DeclareLaunchArgument(
72 default_value=os.path.join(bringup_dir,
'maps',
'tb3_sandbox.yaml'),
75 declare_params_file_cmd = DeclareLaunchArgument(
77 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
78 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
81 declare_autostart_cmd = DeclareLaunchArgument(
84 description=
'Automatically startup the nav2 stack',
87 declare_use_composition_cmd = DeclareLaunchArgument(
90 description=
'Whether to use composed bringup',
93 declare_use_respawn_cmd = DeclareLaunchArgument(
95 default_value=
'False',
96 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
99 declare_rviz_config_file_cmd = DeclareLaunchArgument(
101 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
102 description=
'Full path to the RVIZ config file to use',
105 declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
106 'use_robot_state_pub',
107 default_value=
'True',
108 description=
'Whether to start the robot state publisher',
111 declare_use_rviz_cmd = DeclareLaunchArgument(
112 'use_rviz', default_value=
'True', description=
'Whether to start RVIZ'
115 urdf = os.path.join(sim_dir,
'urdf',
'turtlebot3_waffle.urdf')
116 with open(urdf,
'r')
as infp:
117 robot_description = infp.read()
119 start_robot_state_publisher_cmd = Node(
120 condition=IfCondition(use_robot_state_pub),
121 package=
'robot_state_publisher',
122 executable=
'robot_state_publisher',
123 name=
'robot_state_publisher',
127 {
'use_sim_time':
True,
'robot_description': robot_description}
129 remappings=remappings,
132 rviz_cmd = IncludeLaunchDescription(
133 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'rviz_launch.py')),
134 condition=IfCondition(use_rviz),
136 'namespace': namespace,
137 'use_namespace': use_namespace,
138 'use_sim_time':
'True',
139 'rviz_config': rviz_config_file,
143 bringup_cmd = IncludeLaunchDescription(
144 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'bringup_launch.py')),
146 'namespace': namespace,
147 'use_namespace': use_namespace,
148 'map': map_yaml_file,
149 'use_sim_time':
'True',
150 'params_file': params_file,
151 'autostart': autostart,
152 'use_composition': use_composition,
153 'use_respawn': use_respawn,
154 'use_localization':
'False',
158 loopback_sim_cmd = IncludeLaunchDescription(
159 PythonLaunchDescriptionSource(
160 os.path.join(loopback_sim_dir,
'loopback_simulation.launch.py')),
162 'params_file': params_file,
166 configured_params = ParameterFile(
168 source_file=params_file,
176 start_map_server = GroupAction(
178 SetParameter(
'use_sim_time',
True),
180 package=
'nav2_map_server',
181 executable=
'map_server',
186 parameters=[configured_params, {
'yaml_filename': map_yaml_file}],
187 remappings=remappings,
190 package=
'nav2_lifecycle_manager',
191 executable=
'lifecycle_manager',
192 name=
'lifecycle_manager_map_server',
196 {
'autostart': autostart}, {
'node_names': [
'map_server']}],
202 ld = LaunchDescription()
205 ld.add_action(declare_namespace_cmd)
206 ld.add_action(declare_use_namespace_cmd)
207 ld.add_action(declare_map_yaml_cmd)
208 ld.add_action(declare_params_file_cmd)
209 ld.add_action(declare_autostart_cmd)
210 ld.add_action(declare_use_composition_cmd)
212 ld.add_action(declare_rviz_config_file_cmd)
213 ld.add_action(declare_use_robot_state_pub_cmd)
214 ld.add_action(declare_use_rviz_cmd)
215 ld.add_action(declare_use_respawn_cmd)
218 ld.add_action(start_robot_state_publisher_cmd)
219 ld.add_action(start_map_server)
220 ld.add_action(loopback_sim_cmd)
221 ld.add_action(rviz_cmd)
222 ld.add_action(bringup_cmd)