-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlidarInfer.m
41 lines (32 loc) · 1.04 KB
/
lidarInfer.m
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
function lidarInfer()
%#codegen
node = ros2node("/detector_node");
pclSub = ros2subscriber(node, "/static_cloud","sensor_msgs/PointCloud2");
% Create a bounding box publisher
bboxPub = ros2publisher(node, '/bbox','std_msgs/Float32MultiArray');
bboxMsg = ros2message("std_msgs/Float32MultiArray");
% Create a label publisher
labelPub = ros2publisher(node, '/label', 'std_msgs/String');
labelMsg = ros2message("std_msgs/String");
r = ros2rate(node, 30);
reset(r);
while(1)
[data, ~, ~] = receive(pclSub, 5);
if ~isempty(data)
rawData = rosReadXYZ(data);
pclData = pointCloud(rawData);
[bboxes, scores, labels] = pillarPredict(pclData.Location);
[~,idx] = max(scores);
bboxMsg.data = zeros(6, 1, 'single');
labelMsg.data = '';
if ~isempty(scores)
bboxMsg.data = single(bboxes(idx,:)');
label_data = cellstr(labels(idx));
labelMsg.data = label_data{1};
end
send(bboxPub, bboxMsg);
send(labelPub, labelMsg);
end
waitfor(r);
end
end