11import numpy as np
2+ import uuid
23from scipy .optimize import linear_sum_assignment
34
45from nav2_dynamic_msgs .msg import Obstacle , ObstacleArray
@@ -23,7 +24,6 @@ class KFHungarianTracker(Node):
2324
2425 Attributes:
2526 obstacle_list: a list of ObstacleClass that currently present in the scene
26- max_id: the maximum id assigned
2727 sec, nanosec: timing from sensor msg
2828 detection_sub: subscrib detection result from detection node
2929 tracker_obstacle_pub: publish tracking obstacles with ObstacleArray
@@ -58,7 +58,6 @@ def __init__(self):
5858 self .cost_filter = self .get_parameter ("cost_filter" )._value
5959
6060 self .obstacle_list = []
61- self .max_id = 0
6261 self .sec = 0
6362 self .nanosec = 0
6463
@@ -167,11 +166,13 @@ def callback(self, msg):
167166 marker_list = []
168167 # add current active obstacles
169168 for obs in filtered_obstacle_list :
170- (r , g , b ) = colorsys .hsv_to_rgb (obs .msg .id * 30. % 360 / 360. , 1. , 1. ) # encode id with rgb color
169+ obstacle_uuid = uuid .UUID (bytes = bytes (obs .msg .uuid .uuid ))
170+ (r , g , b ) = colorsys .hsv_to_rgb (obstacle_uuid .int % 360 / 360. , 1. , 1. ) # encode id with rgb color
171171 # make a cube
172172 marker = Marker ()
173173 marker .header = msg .header
174- marker .id = obs .msg .id
174+ marker .ns = str (obstacle_uuid )
175+ marker .id = 0
175176 marker .type = 1 # CUBE
176177 marker .action = 0
177178 marker .color .a = 0.5
@@ -187,7 +188,8 @@ def callback(self, msg):
187188 # make an arrow
188189 arrow = Marker ()
189190 arrow .header = msg .header
190- arrow .id = 255 - obs .msg .id
191+ arrow .ns = str (obstacle_uuid )
192+ arrow .id = 1
191193 arrow .type = 0
192194 arrow .action = 0
193195 arrow .color .a = 1.0
@@ -202,27 +204,28 @@ def callback(self, msg):
202204 arrow .scale .z = 0.05
203205 marker_list .append (arrow )
204206 # add dead obstacles to delete in rviz
205- for idx in dead_object_list :
207+ for uuid in dead_object_list :
206208 marker = Marker ()
207209 marker .header = msg .header
208- marker .id = idx
210+ marker .ns = str (uuid )
211+ marker .id = 0
209212 marker .action = 2 # delete
210213 arrow = Marker ()
211214 arrow .header = msg .header
212- arrow .id = 255 - idx
215+ arrow .ns = str (uuid )
216+ arrow .id = 1
213217 arrow .action = 2
214218 marker_list .append (marker )
215219 marker_list .append (arrow )
216-
217220 marker_array .markers = marker_list
218221 self .tracker_marker_pub .publish (marker_array )
219222
220223 def birth (self , det_ind , num_of_detect , detections ):
221224 '''generate new ObstacleClass for detections that do not match any in current obstacle list'''
222225 for det in range (num_of_detect ):
223226 if det not in det_ind :
224- self . obstacle_list . append ( ObstacleClass (detections [det ], self .max_id , self . top_down , self .measurement_noise_cov , self .error_cov_post , self .process_noise_cov ) )
225- self .max_id = self . max_id + 1
227+ obstacle = ObstacleClass (detections [det ], self .top_down , self .measurement_noise_cov , self .error_cov_post , self .process_noise_cov )
228+ self .obstacle_list . append ( obstacle )
226229
227230 def death (self , obj_ind , num_of_obstacle ):
228231 '''count obstacles' missing frames and delete when reach threshold'''
@@ -238,7 +241,8 @@ def death(self, obj_ind, num_of_obstacle):
238241 if self .obstacle_list [obs ].dying < self .death_threshold :
239242 new_object_list .append (self .obstacle_list [obs ])
240243 else :
241- dead_object_list .append (self .obstacle_list [obs ].msg .id )
244+ obstacle_uuid = uuid .UUID (bytes = bytes (self .obstacle_list [obs ].msg .uuid .uuid ))
245+ dead_object_list .append (obstacle_uuid )
242246
243247 # add newly born obstacles
244248 for obs in range (num_of_obstacle , len (self .obstacle_list )):
0 commit comments