4848
4949from launch_ros .actions import PushRosNamespace , SetRemap
5050
51+ from nav2_common .launch import RewrittenYaml
52+
5153
5254ARGUMENTS = [
5355 DeclareLaunchArgument ('use_sim_time' , default_value = 'false' ,
5456 choices = ['true' , 'false' ],
5557 description = 'Use sim time' ),
5658 DeclareLaunchArgument ('setup_path' ,
5759 default_value = '/etc/clearpath/' ,
58- description = 'Clearpath setup path' )
60+ description = 'Clearpath setup path' ),
61+ DeclareLaunchArgument ('scan_topic' ,
62+ default_value = '' ,
63+ description = 'Override the default 2D laserscan topic' )
5964]
6065
6166
@@ -67,6 +72,7 @@ def launch_setup(context, *args, **kwargs):
6772 # Launch Configurations
6873 use_sim_time = LaunchConfiguration ('use_sim_time' )
6974 setup_path = LaunchConfiguration ('setup_path' )
75+ scan_topic = LaunchConfiguration ('scan_topic' )
7076
7177 # Read robot YAML
7278 config = read_yaml (os .path .join (setup_path .perform (context ), 'robot.yaml' ))
@@ -76,29 +82,40 @@ def launch_setup(context, *args, **kwargs):
7682 namespace = clearpath_config .system .namespace
7783 platform_model = clearpath_config .platform .get_platform_model ()
7884
85+ # see if we've overridden the scan_topic
86+ eval_scan_topic = scan_topic .perform (context )
87+ if len (eval_scan_topic ) == 0 :
88+ eval_scan_topic = f'/{ namespace } /sensors/lidar2d_0/scan'
89+
7990 file_parameters = PathJoinSubstitution ([
8091 pkg_clearpath_nav2_demos ,
8192 'config' ,
8293 platform_model ,
8394 'nav2.yaml' ])
8495
96+ rewritten_parameters = RewrittenYaml (
97+ source_file = file_parameters ,
98+ param_rewrites = {
99+ # the only *.topic parameters are scan.topic, so rewrite all of them to point to
100+ # our desired scan_topic
101+ 'topic' : eval_scan_topic ,
102+ },
103+ convert_types = True
104+ )
105+
85106 launch_nav2 = PathJoinSubstitution (
86107 [pkg_nav2_bringup , 'launch' , 'navigation_launch.py' ])
87108
88109 nav2 = GroupAction ([
89110 PushRosNamespace (namespace ),
90- SetRemap ('/' + namespace + '/global_costmap/sensors/lidar2d_0/scan' ,
91- '/' + namespace + '/sensors/lidar2d_0/scan' ),
92- SetRemap ('/' + namespace + '/local_costmap/sensors/lidar2d_0/scan' ,
93- '/' + namespace + '/sensors/lidar2d_0/scan' ),
94111 SetRemap ('/' + namespace + '/odom' ,
95112 '/' + namespace + '/platform/odom' ),
96113
97114 IncludeLaunchDescription (
98115 PythonLaunchDescriptionSource (launch_nav2 ),
99116 launch_arguments = [
100117 ('use_sim_time' , use_sim_time ),
101- ('params_file' , file_parameters ),
118+ ('params_file' , rewritten_parameters ),
102119 ('use_composition' , 'False' ),
103120 ('namespace' , namespace )
104121 ]
0 commit comments