-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleHelperGetBoxPoses.m
More file actions
37 lines (26 loc) · 1.05 KB
/
exampleHelperGetBoxPoses.m
File metadata and controls
37 lines (26 loc) · 1.05 KB
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
function positionArray = exampleHelperGetBoxPoses(graspState,ID,maxNumOfBoxes)
%EXAMPLEHELPERGETBOXPOSES This helper queries the sim3D environment to get
%the pose of all the boxes currently on the pallet
% Copyright 2024 The MathWorks, Inc.
positionArray = NaN(maxNumOfBoxes,3);
W = sim3d.World.getWorld(bdroot);
actorList = W.Actors;
actorNames = fieldnames(actorList);
% Extract the collision environment
collIdxArray = find(contains(actorNames,'coll'));
% If graspState is true, remove collBox(ID) from the list
if graspState == true
idx = find(contains(actorNames,['collBox',num2str(ID)]));
collIdxArray = collIdxArray(collIdxArray~=idx);
end
for i=1:numel(collIdxArray)
actor = actorList.(actorNames{collIdxArray(i)});
maxVertices = max(double(actor.Vertices));
minVertices = min(double(actor.Vertices));
boxCenterLoc = (maxVertices + minVertices)/2;
objLoc = double(actor.Translation) + boxCenterLoc;
% Convert to SL frame
boxPose = [objLoc(1) -objLoc(2) objLoc(3)];
positionArray(i,3) = boxPose;
end
end