Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
loopback_simulation.launch.py
1 # Copyright (c) 2024 Open Navigation LLC
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 
15 import os
16 
17 from ament_index_python.packages import get_package_share_directory
18 from launch import LaunchDescription
19 from launch.actions import DeclareLaunchArgument
20 from launch.substitutions import LaunchConfiguration
21 from launch_ros.actions import LifecycleNode
22 from launch_ros.descriptions import ParameterFile
23 from nav2_common.launch import RewrittenYaml
24 
25 
26 def generate_launch_description() -> LaunchDescription:
27  bringup_dir = get_package_share_directory('nav2_bringup')
28  namespace = LaunchConfiguration('namespace')
29  declare_namespace_cmd = DeclareLaunchArgument(
30  'namespace',
31  default_value='',
32  description='Top-level namespace',
33  )
34 
35  params_file = LaunchConfiguration('params_file')
36  declare_params_file_cmd = DeclareLaunchArgument(
37  'params_file',
38  default_value=os.path.join(bringup_dir, 'params', 'nav2_params.yaml'),
39  description='Full path to the ROS2 parameters file to use for all launched nodes',
40  )
41 
42  scan_frame_id = LaunchConfiguration('scan_frame_id')
43  declare_scan_frame_id_cmd = DeclareLaunchArgument(
44  'scan_frame_id',
45  default_value='base_scan',
46  )
47 
48  remappings = [('/tf', 'tf'), ('/tf_static', 'tf_static')]
49 
50  configured_params = ParameterFile(
51  RewrittenYaml(
52  source_file=params_file,
53  root_key=namespace,
54  param_rewrites={},
55  convert_types=True,
56  ),
57  allow_substs=True,
58  )
59 
60  loopback_sim_cmd = LifecycleNode(
61  package='nav2_loopback_sim',
62  executable='loopback_simulator',
63  name='loopback_simulator',
64  namespace=namespace,
65  output='screen',
66  autostart=True,
67  parameters=[
68  configured_params,
69  {'scan_frame_id': scan_frame_id, 'use_sim_time': True},
70  ],
71  remappings=remappings,
72  )
73 
74  ld = LaunchDescription()
75  ld.add_action(declare_namespace_cmd)
76  ld.add_action(declare_scan_frame_id_cmd)
77  ld.add_action(declare_params_file_cmd)
78  ld.add_action(loopback_sim_cmd)
79  return ld