Skip to content

Commit 7ce643c

Browse files
Merge pull request #23 from simutisernestas/uuid
uuid for obstacle message
2 parents c5a1d94 + ea6f484 commit 7ce643c

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

kf_hungarian_tracker/kf_hungarian_tracker/kf_hungarian_node.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import uuid
23
from scipy.optimize import linear_sum_assignment
34

45
from 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)):

kf_hungarian_tracker/kf_hungarian_tracker/obstacle_class.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import numpy as np
22
import cv2
3+
import uuid
4+
from unique_identifier_msgs.msg import UUID
35

46
class ObstacleClass:
57
"""wrap a kalman filter and extra information for one single obstacle
@@ -13,10 +15,14 @@ class ObstacleClass:
1315
dying: count missing frames for this obstacle, if reach threshold, delete this obstacle
1416
"""
1517

16-
def __init__(self, obstacle_msg, idx, top_down, measurement_noise_cov, error_cov_post, process_noise_cov):
18+
def __init__(self, obstacle_msg, top_down, measurement_noise_cov, error_cov_post, process_noise_cov):
1719
'''Initialize with an Obstacle msg and an assigned id'''
1820
self.msg = obstacle_msg
19-
self.msg.id = idx
21+
22+
uuid_msg = UUID()
23+
uuid_msg.uuid = list(uuid.uuid4().bytes)
24+
self.msg.uuid = uuid_msg
25+
2026
position = np.array([[obstacle_msg.position.x, obstacle_msg.position.y, obstacle_msg.position.z]]).T # shape 3*1
2127
velocity = np.array([[obstacle_msg.velocity.x, obstacle_msg.velocity.y, obstacle_msg.velocity.z]]).T
2228

nav2_dynamic_msgs/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ find_package(rosidl_default_generators REQUIRED)
2525
find_package(builtin_interfaces REQUIRED)
2626
find_package(std_msgs REQUIRED)
2727
find_package(sensor_msgs REQUIRED)
28+
find_package(unique_identifier_msgs REQUIRED)
2829

2930
rosidl_generate_interfaces(${PROJECT_NAME}
3031
"msg/Obstacle.msg"
3132
"msg/ObstacleArray.msg"
32-
DEPENDENCIES std_msgs sensor_msgs
33+
DEPENDENCIES std_msgs sensor_msgs unique_identifier_msgs
3334
)
3435

3536
if(BUILD_TESTING)

nav2_dynamic_msgs/msg/Obstacle.msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int8 id
1+
unique_identifier_msgs/UUID uuid
22
float32 score # detection confidence
33
geometry_msgs/Point position # center
44
geometry_msgs/Vector3 velocity

nav2_dynamic_msgs/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<depend>sensor_msgs</depend>
1818
<depend>std_msgs</depend>
19+
<depend>unique_identifier_msgs</depend>
1920

2021
<test_depend>ament_lint_auto</test_depend>
2122
<test_depend>ament_lint_common</test_depend>

0 commit comments

Comments
 (0)