-
Notifications
You must be signed in to change notification settings - Fork 0
/
slam_module.py
332 lines (270 loc) · 9.46 KB
/
slam_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@file slam_module.py
@author Yanwei Du ([email protected])
@date 11-10-2023
@version 1.0
@license Copyright (c) 2023
@desc None
"""
import os
from typing import Dict
from closedloop_nav_slam.utils.node_module import NodeBase
from .path_definitions import SLAM_CONFIGS_PATH
# Gazebo odometry source node.
class PerfectOdometryNode(NodeBase):
"""Create perfect odometry node.
Args:
NodeBase (_type_): _description_
"""
def __init__(self, params: Dict):
names = ["map_to_odom_publisher"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return "roslaunch closedloop_nav_slam perfect_odometry.launch"
class RobotOdometryNode(NodeBase):
"""Create Robot Odometry Node.
Args:
NodeBase (_type_): _description_
"""
def __init__(self, params: Dict):
names = ["slam_map_to_odom_publisher"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return "roslaunch closedloop_nav_slam robot_odometry.launch"
class WheelOdometryNode(NodeBase):
"""Create Wheel Odcometry Node.
Args:
NodeBase (_type_): _description_
"""
def __init__(self, params: Dict):
names = ["wheel_odometry_publisher"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return "rosrun closedloop_nav_slam wheel_odometry_publisher.py"
# 2D Laser SLAM
class SlamToolboxNode(NodeBase):
def __init__(self, params: Dict):
names = ["slam_toolbox"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return (
"roslaunch slam_toolbox nav_slam_test.launch mode:=mapping output_pose_topic:="
+ self._params["et_pose_topic"]
)
class HectorSlamNode(NodeBase):
def __init__(self, params: Dict):
names = ["hector_mapping"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return "roslaunch hector_mapping nav_slam_test.launch output_pose_topic:=" + self._params["et_pose_topic"]
class AmclNode(NodeBase):
def __init__(self, params: Dict):
names = ["amcl", "slam_map_server"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return "roslaunch closedloop_nav_slam amcl.launch output_pose_topic:=" + self._params["et_pose_topic"]
class GmappingNode(NodeBase):
def __init__(self, params: Dict):
names = ["gmapping", "tf_to_pose_converter"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return "roslaunch closedloop_nav_slam gmapping.launch output_pose_topic:=" + self._params["et_pose_topic"]
class GroundTruthSlamNode(NodeBase):
def __init__(self, params: Dict):
names = ["slam_toolbox"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return (
"roslaunch slam_toolbox nav_slam_test.launch"
+ " mode:=mapping map_frame:=gt_slam_map map_name:=/gt_slam_map"
+ " invert_tf:=true transform_publish_period:=0.5"
+ " output_pose_topic:="
+ self._params["gt_pose_topic"]
)
# Visual SLAM.
class GfggNode(NodeBase):
def __init__(self, params: Dict):
names = ["visual_slam", "Stereo"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "closedloop_ws")
TRACK_LOG_DIR = self._params["path_dir"]
cmd = (
"bash "
+ str(SLAM_CONFIGS_PATH / "call_gfgg.sh ")
+ ROS_WS
+ " "
+ TRACK_LOG_DIR
+ " "
+ str(self._params["good_feature_num"])
+ " "
+ self._params["et_pose_topic"]
)
return cmd
class Orb3Node(NodeBase):
def __init__(self, params: Dict):
names = ["visual_slam", "Stereo"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "closedloop_ws")
TRACK_LOG_DIR = self._params["path_dir"]
cmd = (
"bash "
+ str(SLAM_CONFIGS_PATH / "call_orb3.sh ")
+ ROS_WS
+ " "
+ TRACK_LOG_DIR
+ " "
+ str(self._params["feature_num"])
+ " "
+ self._params["et_pose_topic"]
)
return cmd
class MsckfNode(NodeBase):
def __init__(self, params: Dict):
names = ["msckf/vio", "msckf/image_processor"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "svo_ws")
TRACK_LOG_DIR = self._params["path_dir"]
cmd = (
"bash "
+ str(SLAM_CONFIGS_PATH / "call_msckf.sh ")
+ ROS_WS
+ " "
+ TRACK_LOG_DIR
+ " "
+ str(self._params["feature_num"])
+ " "
+ self._params["et_pose_topic"]
)
return cmd
class DsolNode(NodeBase):
def __init__(self, params: Dict):
names = ["dsol_odom"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "turtlebot_ws")
TRACK_LOG_DIR = self._params["path_dir"]
cmd = (
"bash "
+ str(SLAM_CONFIGS_PATH / "call_dsol.sh ")
+ ROS_WS
+ " "
+ TRACK_LOG_DIR
+ " "
+ str(self._params["cell_size"])
+ " "
+ self._params["et_pose_topic"]
)
return cmd
class SvoNode(NodeBase):
def __init__(self, params: Dict):
names = ["svo"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
# ROS_WS = os.path.join(os.environ["HOME"], "svo_ws")
DATASET_NAME = "dummy_dataset"
TRACK_LOG_DIR = self._params["path_dir"]
cmd = (
"bash "
+ str(SLAM_CONFIGS_PATH / "call_svo.sh ")
+ str(self._params["grid_size"])
+ " "
+ DATASET_NAME
+ " "
+ TRACK_LOG_DIR
+ " "
+ self._params["et_pose_topic"]
)
return cmd
# Fusion node.
class MsfNode(NodeBase):
def __init__(self, params: Dict):
names = ["msf_pose_sensor", "odometry_converter", "visual_robot_publisher"]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
return (
"roslaunch closedloop_nav_slam msf.launch"
+ " slam_sensor_type:="
+ self._params["slam_sensor_type"]
+ " slam_pose_topic:="
+ self._params["et_pose_topic"]
+ " source_msg_parent_frame:="
+ self._params["source_msg_parent_frame"]
+ " source_msg_child_frame:="
+ self._params["source_msg_child_frame"]
)
# 3D Lidar SLAM
class HdlSlamNode(NodeBase):
def __init__(self, params: Dict):
names = [
"hdl_graph_slam_nodelet",
"prefiltering_nodelet",
"scan_matching_odometry_nodelet",
"velodyne_nodelet_manager",
]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "catkin_ws")
cmd = "bash " + str(SLAM_CONFIGS_PATH / "call_hdl_slam.sh ") + ROS_WS + " " + self._params["et_pose_topic"]
return cmd
class FastLio2Node(NodeBase):
def __init__(self, params: Dict):
names = [
"laserMapping",
]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "catkin_ws")
cmd = "bash " + str(SLAM_CONFIGS_PATH / "call_fast_lio2.sh ") + ROS_WS + " " + self._params["et_pose_topic"]
return cmd
class LiorfNode(NodeBase):
def __init__(self, params: Dict):
names = [
"liorf_imageProjection",
"liorf_imuPreintegration",
"liorf_mapOptmization",
]
super().__init__(names, params)
def compose_start_cmd(self) -> str:
ROS_WS = os.path.join(os.environ["HOME"], "catkin_ws")
cmd = "bash " + str(SLAM_CONFIGS_PATH / "call_liorf.sh ") + ROS_WS + " " + self._params["et_pose_topic"]
return cmd
# Factory.
def CreateSlamNode(params: Dict) -> NodeBase:
slam_method = params["slam_method"]
if "slam_toolbox" == slam_method:
return SlamToolboxNode(params)
elif "hector_slam" == slam_method:
return HectorSlamNode(params)
elif "amcl" == slam_method:
return AmclNode(params)
elif "gmapping" == slam_method:
return GmappingNode(params)
elif "gfgg" == slam_method:
return GfggNode(params)
elif "orb3" == slam_method:
return Orb3Node(params)
elif "msckf" == slam_method:
return MsckfNode(params)
elif "dsol" == slam_method:
return DsolNode(params)
elif "svo" == slam_method:
return SvoNode(params)
elif "perfect_odometry" == slam_method:
return PerfectOdometryNode(params)
elif "robot_odometry" == slam_method:
return RobotOdometryNode(params)
elif "hdl_slam" == slam_method:
return HdlSlamNode(params)
elif "fast_lio2" == slam_method:
return FastLio2Node(params)
elif "liorf" == slam_method:
return LiorfNode(params)
else:
print(f"{slam_method} NOT DEFINED!")
raise RuntimeError
return None