Skip to content

Commit f4e206d

Browse files
committed
Fix the slam launch file to use the new lifecycle node
1 parent 7c6f811 commit f4e206d

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

launch/slam.launch.py

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@
3333
from launch import LaunchDescription
3434
from launch.actions import (
3535
DeclareLaunchArgument,
36-
OpaqueFunction
36+
GroupAction,
37+
IncludeLaunchDescription,
38+
OpaqueFunction,
3739
)
38-
40+
from launch.conditions import IfCondition, UnlessCondition
41+
from launch.launch_description_sources import PythonLaunchDescriptionSource
3942
from launch.substitutions import (
4043
LaunchConfiguration,
41-
PathJoinSubstitution
44+
PathJoinSubstitution,
4245
)
4346

44-
from launch_ros.actions import Node
47+
from launch_ros.actions import PushRosNamespace, SetRemap
4548

4649
from nav2_common.launch import RewrittenYaml
4750

@@ -52,17 +55,30 @@
5255
description='Use sim time'),
5356
DeclareLaunchArgument('setup_path',
5457
default_value='/etc/clearpath/',
55-
description='Clearpath setup path')
58+
description='Clearpath setup path'),
59+
DeclareLaunchArgument('autostart', default_value='true',
60+
choices=['true', 'false'],
61+
description='Automatically startup the slamtoolbox. Ignored when use_lifecycle_manager is true.'), # noqa: E501
62+
DeclareLaunchArgument('use_lifecycle_manager', default_value='false',
63+
choices=['true', 'false'],
64+
description='Enable bond connection during node activation'),
65+
DeclareLaunchArgument('sync', default_value='true',
66+
choices=['true', 'false'],
67+
description='Use synchronous SLAM'),
5668
]
5769

5870

5971
def launch_setup(context, *args, **kwargs):
6072
# Packages
6173
pkg_clearpath_nav2_demos = get_package_share_directory('clearpath_nav2_demos')
74+
pkg_slam_toolbox = get_package_share_directory('slam_toolbox')
6275

6376
# Launch Configurations
6477
use_sim_time = LaunchConfiguration('use_sim_time')
6578
setup_path = LaunchConfiguration('setup_path')
79+
autostart = LaunchConfiguration('autostart')
80+
use_lifecycle_manager = LaunchConfiguration('use_lifecycle_manager')
81+
sync = LaunchConfiguration('sync')
6682

6783
# Read robot YAML
6884
config = read_yaml(setup_path.perform(context) + 'robot.yaml')
@@ -85,24 +101,43 @@ def launch_setup(context, *args, **kwargs):
85101
convert_types=True
86102
)
87103

88-
slam = Node(
89-
package='slam_toolbox',
90-
executable='async_slam_toolbox_node',
91-
name='slam_toolbox',
92-
namespace=namespace,
93-
output='screen',
94-
parameters=[
95-
rewritten_parameters,
96-
{'use_sim_time': use_sim_time}
97-
],
98-
remappings=[
99-
('/tf', 'tf'),
100-
('/tf_static', 'tf_static'),
101-
('/scan', 'sensors/lidar2d_0/scan'),
102-
('/map', 'map'),
103-
('/map_metadata', 'map_metadata'),
104-
]
105-
)
104+
launch_slam_sync = PathJoinSubstitution(
105+
[pkg_slam_toolbox, 'launch', 'online_sync_launch.py'])
106+
107+
launch_slam_async = PathJoinSubstitution(
108+
[pkg_slam_toolbox, 'launch', 'online_async_launch.py'])
109+
110+
slam = GroupAction([
111+
PushRosNamespace(namespace),
112+
113+
SetRemap('/tf', '/' + namespace + '/tf'),
114+
SetRemap('/tf_static', '/' + namespace + '/tf_static'),
115+
SetRemap('/scan', '/' + namespace + '/scan'),
116+
SetRemap('/map', '/' + namespace + '/map'),
117+
SetRemap('/map_metadata', '/' + namespace + '/map_metadata'),
118+
119+
IncludeLaunchDescription(
120+
PythonLaunchDescriptionSource(launch_slam_sync),
121+
launch_arguments=[
122+
('use_sim_time', use_sim_time),
123+
('autostart', autostart),
124+
('use_lifecycle_manager', use_lifecycle_manager),
125+
('slam_params_file', rewritten_parameters)
126+
],
127+
condition=IfCondition(sync)
128+
),
129+
130+
IncludeLaunchDescription(
131+
PythonLaunchDescriptionSource(launch_slam_async),
132+
launch_arguments=[
133+
('use_sim_time', use_sim_time),
134+
('autostart', autostart),
135+
('use_lifecycle_manager', use_lifecycle_manager),
136+
('slam_params_file', rewritten_parameters)
137+
],
138+
condition=UnlessCondition(sync)
139+
)
140+
])
106141

107142
return [slam]
108143

0 commit comments

Comments
 (0)