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
20 from launch
import LaunchDescription
21 from launch.actions
import DeclareLaunchArgument, IncludeLaunchDescription
22 from launch.conditions
import IfCondition
23 from launch.launch_description_sources
import PythonLaunchDescriptionSource
24 from launch.substitutions
import Command, LaunchConfiguration
25 from launch_ros.actions
import Node
29 def generate_launch_description() -> LaunchDescription:
31 bringup_dir = get_package_share_directory(
'nav2_bringup')
32 loopback_sim_dir = get_package_share_directory(
'nav2_loopback_sim')
33 launch_dir = os.path.join(bringup_dir,
'launch')
34 desc_dir = get_package_share_directory(
'nav2_minimal_tb4_description')
37 namespace = LaunchConfiguration(
'namespace')
38 map_yaml_file = LaunchConfiguration(
'map')
39 graph_filepath = LaunchConfiguration(
'graph')
40 params_file = LaunchConfiguration(
'params_file')
41 autostart = LaunchConfigAsBool(
'autostart')
42 use_composition = LaunchConfigAsBool(
'use_composition')
43 use_intra_process_comms = LaunchConfigAsBool(
'use_intra_process_comms')
44 use_respawn = LaunchConfigAsBool(
'use_respawn')
47 rviz_config_file = LaunchConfiguration(
'rviz_config_file')
48 use_robot_state_pub = LaunchConfigAsBool(
'use_robot_state_pub')
49 use_rviz = LaunchConfigAsBool(
'use_rviz')
50 remappings = [(
'/tf',
'tf'), (
'/tf_static',
'tf_static')]
53 declare_namespace_cmd = DeclareLaunchArgument(
54 'namespace', default_value=
'', description=
'Top-level namespace'
57 declare_map_yaml_cmd = DeclareLaunchArgument(
59 default_value=os.path.join(bringup_dir,
'maps',
'depot.yaml'),
60 description=
'Full path to map file to load',
63 declare_graph_file_cmd = DeclareLaunchArgument(
65 default_value=os.path.join(bringup_dir,
'graphs',
'depot_graph.geojson'),
68 declare_params_file_cmd = DeclareLaunchArgument(
70 default_value=os.path.join(bringup_dir,
'params',
'nav2_params.yaml'),
71 description=
'Full path to the ROS2 parameters file to use for all launched nodes',
74 declare_autostart_cmd = DeclareLaunchArgument(
77 description=
'Automatically startup the nav2 stack',
80 declare_use_composition_cmd = DeclareLaunchArgument(
83 description=
'Whether to use composed bringup',
86 declare_use_intra_process_comms_cmd = DeclareLaunchArgument(
87 'use_intra_process_comms',
88 default_value=
'False',
89 description=
'Whether to use intra process communication',
92 declare_use_respawn_cmd = DeclareLaunchArgument(
94 default_value=
'False',
95 description=
'Whether to respawn if a node crashes. Applied when composition is disabled.',
98 declare_rviz_config_file_cmd = DeclareLaunchArgument(
100 default_value=os.path.join(bringup_dir,
'rviz',
'nav2_default_view.rviz'),
101 description=
'Full path to the RVIZ config file to use',
104 declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
105 'use_robot_state_pub',
106 default_value=
'True',
107 description=
'Whether to start the robot state publisher',
110 declare_use_rviz_cmd = DeclareLaunchArgument(
111 'use_rviz', default_value=
'True', description=
'Whether to start RVIZ'
114 sdf = os.path.join(desc_dir,
'urdf',
'standard',
'turtlebot4.urdf.xacro')
115 start_robot_state_publisher_cmd = Node(
116 condition=IfCondition(use_robot_state_pub),
117 package=
'robot_state_publisher',
118 executable=
'robot_state_publisher',
119 name=
'robot_state_publisher',
123 {
'use_sim_time':
True,
'robot_description': Command([
'xacro',
' ', sdf])}
125 remappings=remappings,
128 rviz_cmd = IncludeLaunchDescription(
129 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'rviz_launch.py')),
130 condition=IfCondition(use_rviz),
132 (
'namespace', namespace),
133 (
'use_sim_time',
'True'),
134 (
'rviz_config', rviz_config_file),
138 bringup_cmd = IncludeLaunchDescription(
139 PythonLaunchDescriptionSource(os.path.join(launch_dir,
'bringup_launch.py')),
141 'namespace': namespace,
142 'map': map_yaml_file,
143 'graph': graph_filepath,
144 'use_sim_time':
'True',
145 'params_file': params_file,
146 'autostart': autostart,
147 'use_composition': use_composition,
148 'use_intra_process_comms': use_intra_process_comms,
149 'use_respawn': use_respawn,
150 'use_keepout_zones':
'False',
151 'use_speed_zones':
'False',
152 'use_localization':
'False',
153 'serve_static_map':
'True',
154 'container_name':
'nav2_container',
158 loopback_sim_cmd = IncludeLaunchDescription(
159 PythonLaunchDescriptionSource(
160 os.path.join(loopback_sim_dir,
'loopback_simulation.launch.py')),
162 (
'namespace', namespace),
163 (
'params_file', params_file),
164 (
'scan_frame_id',
'rplidar_link'),
168 static_publisher_cmd = Node(
170 executable=
'static_transform_publisher',
172 '--x',
'0.0',
'--y',
'0.0',
'--z',
'0.0',
173 '--roll',
'0',
'--pitch',
'0',
'--yaw',
'0',
174 '--frame-id',
'base_footprint',
'--child-frame-id',
'base_link']
178 ld = LaunchDescription()
181 ld.add_action(declare_namespace_cmd)
182 ld.add_action(declare_map_yaml_cmd)
183 ld.add_action(declare_graph_file_cmd)
184 ld.add_action(declare_params_file_cmd)
185 ld.add_action(declare_autostart_cmd)
186 ld.add_action(declare_use_composition_cmd)
187 ld.add_action(declare_use_intra_process_comms_cmd)
189 ld.add_action(declare_rviz_config_file_cmd)
190 ld.add_action(declare_use_robot_state_pub_cmd)
191 ld.add_action(declare_use_rviz_cmd)
192 ld.add_action(declare_use_respawn_cmd)
195 ld.add_action(start_robot_state_publisher_cmd)
196 ld.add_action(static_publisher_cmd)
197 ld.add_action(loopback_sim_cmd)
198 ld.add_action(rviz_cmd)
199 ld.add_action(bringup_cmd)