33
33
from launch import LaunchDescription
34
34
from launch .actions import (
35
35
DeclareLaunchArgument ,
36
- OpaqueFunction
36
+ GroupAction ,
37
+ IncludeLaunchDescription ,
38
+ OpaqueFunction ,
37
39
)
38
-
40
+ from launch .conditions import IfCondition , UnlessCondition
41
+ from launch .launch_description_sources import PythonLaunchDescriptionSource
39
42
from launch .substitutions import (
40
43
LaunchConfiguration ,
41
- PathJoinSubstitution
44
+ PathJoinSubstitution ,
42
45
)
43
46
44
- from launch_ros .actions import Node
47
+ from launch_ros .actions import PushRosNamespace , SetRemap
45
48
46
49
from nav2_common .launch import RewrittenYaml
47
50
52
55
description = 'Use sim time' ),
53
56
DeclareLaunchArgument ('setup_path' ,
54
57
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' ),
56
68
]
57
69
58
70
59
71
def launch_setup (context , * args , ** kwargs ):
60
72
# Packages
61
73
pkg_clearpath_nav2_demos = get_package_share_directory ('clearpath_nav2_demos' )
74
+ pkg_slam_toolbox = get_package_share_directory ('slam_toolbox' )
62
75
63
76
# Launch Configurations
64
77
use_sim_time = LaunchConfiguration ('use_sim_time' )
65
78
setup_path = LaunchConfiguration ('setup_path' )
79
+ autostart = LaunchConfiguration ('autostart' )
80
+ use_lifecycle_manager = LaunchConfiguration ('use_lifecycle_manager' )
81
+ sync = LaunchConfiguration ('sync' )
66
82
67
83
# Read robot YAML
68
84
config = read_yaml (setup_path .perform (context ) + 'robot.yaml' )
@@ -85,24 +101,43 @@ def launch_setup(context, *args, **kwargs):
85
101
convert_types = True
86
102
)
87
103
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
+ ])
106
141
107
142
return [slam ]
108
143
0 commit comments