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 Command, 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 desc_dir = get_package_share_directory(
'nav2_minimal_tb4_description')
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',
'depot.yaml'),
73 description=
'Full path to map file to load',
76 declare_params_file_cmd = DeclareLaunchArgument(
78 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
79 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
82 declare_autostart_cmd = DeclareLaunchArgument(
85 description=
'Automatically startup the nav2 stack',
88 declare_use_composition_cmd = DeclareLaunchArgument(
91 description=
'Whether to use composed bringup',
94 declare_use_respawn_cmd = DeclareLaunchArgument(
96 default_value=
'False',
97 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
100 declare_rviz_config_file_cmd = DeclareLaunchArgument(
102 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
103 description=
'Full path to the RVIZ config file to use',
106 declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
107 'use_robot_state_pub',
108 default_value=
'True',
109 description=
'Whether to start the robot state publisher',
112 declare_use_rviz_cmd = DeclareLaunchArgument(
113 'use_rviz', default_value=
'True', description=
'Whether to start RVIZ'
116 sdf = os.path.join(desc_dir,
'urdf',
'standard',
'turtlebot4.urdf.xacro')
117 start_robot_state_publisher_cmd = Node(
118 condition=IfCondition(use_robot_state_pub),
119 package=
'robot_state_publisher',
120 executable=
'robot_state_publisher',
121 name=
'robot_state_publisher',
125 {
'use_sim_time':
True,
'robot_description': Command([
'xacro',
' ', sdf])}
127 remappings=remappings,
130 rviz_cmd = IncludeLaunchDescription(
131 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'rviz_launch.py')),
132 condition=IfCondition(use_rviz),
134 'namespace': namespace,
135 'use_namespace': use_namespace,
136 'use_sim_time':
'True',
137 'rviz_config': rviz_config_file,
141 bringup_cmd = IncludeLaunchDescription(
142 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'bringup_launch.py')),
144 'namespace': namespace,
145 'use_namespace': use_namespace,
146 'map': map_yaml_file,
147 'use_sim_time':
'True',
148 'params_file': params_file,
149 'autostart': autostart,
150 'use_composition': use_composition,
151 'use_respawn': use_respawn,
152 'use_localization':
'False',
156 loopback_sim_cmd = IncludeLaunchDescription(
157 PythonLaunchDescriptionSource(
158 os.path.join(loopback_sim_dir,
'loopback_simulation.launch.py')),
160 'params_file': params_file,
161 'scan_frame_id':
'rplidar_link',
165 static_publisher_cmd = Node(
167 executable=
'static_transform_publisher',
169 '0.0',
'0.0',
'0.0',
'0',
'0',
'0',
170 'base_footprint',
'base_link']
173 configured_params = ParameterFile(
175 source_file=params_file,
183 start_map_server = GroupAction(
185 SetParameter(
'use_sim_time',
True),
187 package=
'nav2_map_server',
188 executable=
'map_server',
193 parameters=[configured_params, {
'yaml_filename': map_yaml_file}],
194 remappings=remappings,
197 package=
'nav2_lifecycle_manager',
198 executable=
'lifecycle_manager',
199 name=
'lifecycle_manager_map_server',
203 {
'autostart': autostart}, {
'node_names': [
'map_server']}],
209 ld = LaunchDescription()
212 ld.add_action(declare_namespace_cmd)
213 ld.add_action(declare_use_namespace_cmd)
214 ld.add_action(declare_map_yaml_cmd)
215 ld.add_action(declare_params_file_cmd)
216 ld.add_action(declare_autostart_cmd)
217 ld.add_action(declare_use_composition_cmd)
219 ld.add_action(declare_rviz_config_file_cmd)
220 ld.add_action(declare_use_robot_state_pub_cmd)
221 ld.add_action(declare_use_rviz_cmd)
222 ld.add_action(declare_use_respawn_cmd)
225 ld.add_action(start_robot_state_publisher_cmd)
226 ld.add_action(static_publisher_cmd)
227 ld.add_action(start_map_server)
228 ld.add_action(loopback_sim_cmd)
229 ld.add_action(rviz_cmd)
230 ld.add_action(bringup_cmd)