Skip to content

Commit b54f082

Browse files
Add scan_topic launch argument (#32)
* Add `scan_topic` launch argument for slam, nav2 localization launch files
1 parent 8dc0a3a commit b54f082

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

launch/localization.launch.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@
4848

4949
from launch_ros.actions import PushRosNamespace
5050

51+
from nav2_common.launch import RewrittenYaml
52+
5153

5254
ARGUMENTS = [
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

@@ -68,6 +73,7 @@ def launch_setup(context, *args, **kwargs):
6873
use_sim_time = LaunchConfiguration('use_sim_time')
6974
setup_path = LaunchConfiguration('setup_path')
7075
map = LaunchConfiguration('map') # noqa:A001
76+
scan_topic = LaunchConfiguration('scan_topic')
7177

7278
# Read robot YAML
7379
config = read_yaml(os.path.join(setup_path.perform(context), 'robot.yaml'))
@@ -77,12 +83,24 @@ def launch_setup(context, *args, **kwargs):
7783
namespace = clearpath_config.system.namespace
7884
platform_model = clearpath_config.platform.get_platform_model()
7985

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+
8090
file_parameters = PathJoinSubstitution([
8191
pkg_clearpath_nav2_demos,
8292
'config',
8393
platform_model,
8494
'localization.yaml'])
8595

96+
rewritten_parameters = RewrittenYaml(
97+
source_file=file_parameters,
98+
param_rewrites={
99+
'scan_topic': eval_scan_topic,
100+
},
101+
convert_types=True
102+
)
103+
86104
launch_localization = PathJoinSubstitution(
87105
[pkg_nav2_bringup, 'launch', 'localization_launch.py'])
88106

@@ -95,7 +113,7 @@ def launch_setup(context, *args, **kwargs):
95113
('namespace', namespace),
96114
('map', map),
97115
('use_sim_time', use_sim_time),
98-
('params_file', file_parameters)
116+
('params_file', rewritten_parameters)
99117
]
100118
),
101119
])

launch/nav2.launch.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@
4848

4949
from launch_ros.actions import PushRosNamespace, SetRemap
5050

51+
from nav2_common.launch import RewrittenYaml
52+
5153

5254
ARGUMENTS = [
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
]

launch/slam.launch.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
DeclareLaunchArgument('sync', default_value='true',
6868
choices=['true', 'false'],
6969
description='Use synchronous SLAM'),
70+
DeclareLaunchArgument('scan_topic',
71+
default_value='',
72+
description='Override the default 2D laserscan topic')
7073
]
7174

7275

@@ -81,6 +84,7 @@ def launch_setup(context, *args, **kwargs):
8184
autostart = LaunchConfiguration('autostart')
8285
use_lifecycle_manager = LaunchConfiguration('use_lifecycle_manager')
8386
sync = LaunchConfiguration('sync')
87+
scan_topic = LaunchConfiguration('scan_topic')
8488

8589
# Read robot YAML
8690
config = read_yaml(os.path.join(setup_path.perform(context), 'robot.yaml'))
@@ -89,6 +93,10 @@ def launch_setup(context, *args, **kwargs):
8993

9094
namespace = clearpath_config.system.namespace
9195
platform_model = clearpath_config.platform.get_platform_model()
96+
eval_scan_topic = scan_topic.perform(context)
97+
98+
if len(eval_scan_topic) == 0:
99+
eval_scan_topic = f'/{namespace}/sensors/lidar2d_0/scan'
92100

93101
file_parameters = PathJoinSubstitution([
94102
pkg_clearpath_nav2_demos,
@@ -101,7 +109,7 @@ def launch_setup(context, *args, **kwargs):
101109
root_key=namespace,
102110
param_rewrites={
103111
'map_name': '/' + namespace + '/map',
104-
'scan_topic': '/' + namespace + '/sensors/lidar2d_0/scan',
112+
'scan_topic': eval_scan_topic,
105113
},
106114
convert_types=True
107115
)

0 commit comments

Comments
 (0)