-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensGroundTruth.m
79 lines (77 loc) · 3.42 KB
/
SensGroundTruth.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%[Location,Orientation,Time,GroundTruth]=SensGroundTruth(Robot)
% Amirkabir University of Tehran (Tehran Polytechnic)
% Summer 2011
% http://www.mechatronics3d.com
function [Location,Orientation,Time,GroundTruth]=SensGroundTruth(Robot)
while(Robot.Connection.BytesAvailable>0)
fread(Robot.Connection,Robot.Connection.BytesAvailable);
end
if nargin > 1
error('Too many input arguments');
elseif nargin < 1
error('Too few input arguments');
else
set(Robot.Connection,'ReadAsyncMode','continuous');
fscanf(Robot.Connection);
Flag=1;
i=1;
while Flag && (i<1000);
i=i+1;
if Robot.Connection.BytesAvailable>0
Line=fscanf(Robot.Connection);
Find=strfind(Line ,'{Type GroundTruth}');
if ~isempty(Find)
EndInds=strfind(Line ,'}');
StrInd=strfind(Line ,'{Name');
if ~isempty(StrInd)
EndInd=EndInds(find(EndInds>StrInd,1));
GroundTruth.Name=Line(StrInd+6:EndInd-1);
end
StrInd=strfind(Line ,'{Location');
if ~isempty(StrInd)
EndInd=EndInds(find(EndInds>StrInd,1));
GroundTruth.Location=Line(StrInd+10:EndInd-1);
Index=strfind(GroundTruth.Location ,',');
Location(1)=str2num(GroundTruth.Location(1:Index(1)-1)); %#ok<ST2NM>
Location(2)=str2num(GroundTruth.Location(Index(1)+1:Index(2)-1)); %#ok<ST2NM>
Location(3)=str2num(GroundTruth.Location(Index(2)+1:end)); %#ok<ST2NM>
else
Location='Erorr';
end
StrInd=strfind(Line ,'{Orientation');
if ~isempty(StrInd)
EndInd=EndInds(find(EndInds>StrInd,1));
GroundTruth.Orientation=Line(StrInd+13:EndInd-1);
Index=strfind(GroundTruth.Orientation ,',');
Orientation(1)=str2num(GroundTruth.Orientation(1:Index(1)-1)); %#ok<ST2NM>
Orientation(2)=str2num(GroundTruth.Orientation(Index(1)+1:Index(2)-1)); %#ok<ST2NM>
Orientation(3)=str2num(GroundTruth.Orientation(Index(2)+1:end)); %#ok<ST2NM>
else
Orientation='Erorr';
end
StrInd=strfind(Line ,'{Time');
if ~isempty(StrInd)
EndInd=EndInds(find(EndInds>StrInd,1));
GroundTruth.Time=Line(StrInd+6:EndInd-1);
Time=str2num(GroundTruth.Time); %#ok<ST2NM>
else
Time=-1;
end
Flag=0;
end
else
pause(0.5);
if Robot.Connection.BytesAvailable<=0
Flag=0;
set(Robot.Connection,'ReadAsyncMode','manual');
error('Timeout in GroundTruth Sens Check if USARSim Run and Robot is initialized')
end
end
end
if i>1000
set(Robot.Connection,'ReadAsyncMode','manual');
error('Not GroundTruth sensor response');
end
set(Robot.Connection,'ReadAsyncMode','manual');
end
end