Swarm-SLAM  1.0.0
C-SLAM Framework
loop_closure_detection_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # Loop Closure Detection service
3 # Abstraction to support multiple implementations of loop closure detection for benchmarking
4 
5 import rclpy
6 from rclpy.node import Node
7 from rclpy.clock import Clock
8 from sensor_msgs.msg import Image
9 
10 from cslam.global_descriptor_loop_closure_detection import GlobalDescriptorLoopClosureDetection
11 
12 
14  """ Global image descriptor matching for loop closure detection """
15 
16  def __init__(self):
17  """Initialization and parameter parsing"""
18  super().__init__('loop_closure_detection')
19 
20  self.declare_parameters(
21  namespace='',
22  parameters=[('frontend.similarity_threshold', 0.9),
23  ('frontend.global_descriptor_technique', 'cosplace'),
24  ('frontend.netvlad.pca_checkpoint', ''), ('frontend.nn_checkpoint', 'models/resnet18_64.pth'),
25  ('robot_id', 0), ('max_nb_robots', 10),
26  ('frontend.inter_robot_loop_closure_budget', 5),
27  ('frontend.inter_robot_detection_period_sec', 5),
28  ('frontend.nb_best_matches', 10), ('frontend.image_crop_size', 376),
29  ('frontend.intra_loop_min_inbetween_keyframes', 10),
30  ('neighbor_management.max_heartbeat_delay_sec', 5.0),
31  ('neighbor_management.init_delay_sec', 5.0),
32  ('neighbor_management.heartbeat_period_sec', 0.5),
33  ('frontend.detection_publication_period_sec', 1.0),
34  ('frontend.detection_publication_max_elems_per_msg',
35  10), ('neighbor_management.enable_neighbor_monitoring', False),
36  ('frontend.enable_intra_robot_loop_closures', False),
37  ('frontend.global_descriptors_topic', "global_descriptors"),
38  ('frontend.inter_robot_matches_topic', "inter_robot_matches"),
39  ('frontend.enable_sparsification', True),
40  ('frontend.use_vertex_cover_selection', True),
41  ('frontend.cosplace.descriptor_dim', 64),
42  ('frontend.cosplace.backbone', "resnet18"),
43  ('frontend.sensor_type', "stereo"),
44  ('evaluation.enable_logs', False),
45  ('evaluation.enable_sparsification_comparison', False),
46  ])
47  self.paramsparams = {}
48  self.paramsparams['frontend.similarity_threshold'] = self.get_parameter(
49  'frontend.similarity_threshold').value
50  self.paramsparams['frontend.intra_loop_min_inbetween_keyframes'] = self.get_parameter(
51  'frontend.intra_loop_min_inbetween_keyframes').value
52  self.paramsparams['frontend.nb_best_matches'] = self.get_parameter(
53  'frontend.nb_best_matches').value
54  self.paramsparams['frontend.global_descriptor_technique'] = self.get_parameter(
55  'frontend.global_descriptor_technique').value
56  self.paramsparams['frontend.nn_checkpoint'] = self.get_parameter(
57  'frontend.nn_checkpoint').value
58  self.paramsparams['robot_id'] = self.get_parameter('robot_id').value
59  self.paramsparams['max_nb_robots'] = self.get_parameter('max_nb_robots').value
60  self.paramsparams['frontend.inter_robot_loop_closure_budget'] = self.get_parameter(
61  'frontend.inter_robot_loop_closure_budget').value
62  self.paramsparams['frontend.enable_intra_robot_loop_closures'] = self.get_parameter(
63  'frontend.enable_intra_robot_loop_closures').value
64  self.paramsparams['frontend.inter_robot_detection_period_sec'] = self.get_parameter(
65  'frontend.inter_robot_detection_period_sec').value
66  self.paramsparams["frontend.image_crop_size"] = self.get_parameter(
67  'frontend.image_crop_size').value
68  self.paramsparams["frontend.enable_sparsification"] = self.get_parameter(
69  'frontend.enable_sparsification').value
70  self.paramsparams["neighbor_management.enable_neighbor_monitoring"] = self.get_parameter(
71  'neighbor_management.enable_neighbor_monitoring').value
72  self.paramsparams["neighbor_management.max_heartbeat_delay_sec"] = self.get_parameter(
73  'neighbor_management.max_heartbeat_delay_sec').value
74  self.paramsparams["neighbor_management.init_delay_sec"] = self.get_parameter(
75  'neighbor_management.init_delay_sec').value
76  self.paramsparams["neighbor_management.heartbeat_period_sec"] = self.get_parameter(
77  'neighbor_management.heartbeat_period_sec').value
78  self.paramsparams[
79  "frontend.detection_publication_period_sec"] = self.get_parameter(
80  'frontend.detection_publication_period_sec').value
81  self.paramsparams[
82  "frontend.detection_publication_max_elems_per_msg"] = self.get_parameter(
83  'frontend.detection_publication_max_elems_per_msg').value
84  self.paramsparams["frontend.use_vertex_cover_selection"] = self.get_parameter(
85  'frontend.use_vertex_cover_selection').value
86  self.paramsparams["frontend.cosplace.descriptor_dim"] = self.get_parameter(
87  'frontend.cosplace.descriptor_dim').value
88  self.paramsparams["frontend.cosplace.backbone"] = self.get_parameter(
89  'frontend.cosplace.backbone').value
90  self.paramsparams["frontend.sensor_type"] = self.get_parameter(
91  'frontend.sensor_type').value.lower()
92  self.paramsparams["evaluation.enable_logs"] = self.get_parameter(
93  'evaluation.enable_logs').value
94  self.paramsparams["evaluation.enable_sparsification_comparison"] = self.get_parameter(
95  'evaluation.enable_sparsification_comparison').value
96 
98  self.paramsparams, self)
99  self.inter_robot_detection_timerinter_robot_detection_timer = self.create_timer(
100  self.paramsparams['frontend.inter_robot_detection_period_sec'],
101  self.glcdglcd.detect_inter, clock=Clock())
102 
103 
104 if __name__ == '__main__':
105 
106  rclpy.init(args=None)
108  lcd.get_logger().info('Initialization done.')
109  rclpy.spin(lcd)
110  rclpy.shutdown()