-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_angle.m
50 lines (44 loc) · 1012 Bytes
/
fix_angle.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
function aout = fix_angle(ain,aref, varargin)
options = opt_parser(varargin);
deg=false;
if options.isKey('deg')
deg= options('deg');
end
if deg
ain =ain * pi/180;
aref=aref* pi/180;
end
% Fix robot angle
aout=ain;
for i=1:3
ai=ain(i);
if abs(ai-aref(i))<pi/2
continue;
end
ai=ain(i)+2*pi;
if abs(ai-aref(i))<pi/2
aout(i)=ai;
continue;
end
ai=ain(i)-2*pi;
if abs(ai-aref(i))<pi/2
aout(i)=ai;
continue;
end
ai=ain(i)+pi;
if abs(ai-aref(i))<pi/2
aout(i)=ai;
continue;
end
ai=ain(i)-pi;
if abs(ai-aref(i))<pi/2
aout(i)=ai;
continue;
end
end
if deg
%ain =ain * pi/180;
%aref=aref* pi/180;
aout = aout*180/pi;
end
end