-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFusedOrientation.m
81 lines (61 loc) · 2.72 KB
/
getFusedOrientation.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
80
function [ fusedOrientation ] = getFusedOrientation( orientation, gyroOrientation )
FILTER_COEFFICIENT = 0.98;
oneMinusCoeff = (1.0 - FILTER_COEFFICIENT);
% azimuth
if (gyroOrientation(1) < -0.5 * pi && orientation(1) > 0.0)
fusedOrientation(1) = (FILTER_COEFFICIENT ...
* (gyroOrientation(1) + 2.0 * pi) + oneMinusCoeff ...
* orientation(1));
if fusedOrientation(1) > pi
fusedOrientation(1) = fusedOrientation(1) - 2.0 * pi;
end
elseif (orientation(1) < -0.5 * pi && gyroOrientation(1) > 0.0)
fusedOrientation(1) = (FILTER_COEFFICIENT ...
* gyroOrientation(1) + oneMinusCoeff ...
* (orientation(1) + 2.0 * pi));
if fusedOrientation(1) > pi
fusedOrientation(1) = fusedOrientation(1) - 2.0 * pi;
end
else
fusedOrientation(1) = FILTER_COEFFICIENT * gyroOrientation(1) ...
+ oneMinusCoeff * orientation(1);
end
% pitch
if (gyroOrientation(2) < -0.5 * pi && orientation(2) > 0.0)
fusedOrientation(2) = (FILTER_COEFFICIENT ...
* (gyroOrientation(2) + 2.0 * pi) + oneMinusCoeff ...
* orientation(2));
if fusedOrientation(2) > pi
fusedOrientation(2) = fusedOrientation(2) - 2.0 * pi;
end
elseif (orientation(2) < -0.5 * pi && gyroOrientation(2) > 0.0)
fusedOrientation(2) = (FILTER_COEFFICIENT ...
* gyroOrientation(2) + oneMinusCoeff ...
* (orientation(2) + 2.0 * pi));
if fusedOrientation(2) > pi
fusedOrientation(2) = fusedOrientation(2) - 2.0 * pi;
end
else
fusedOrientation(2) = FILTER_COEFFICIENT * gyroOrientation(2) ...
+ oneMinusCoeff * orientation(2);
end
% roll
if (gyroOrientation(3) < -0.5 * pi && orientation(3) > 0.0)
fusedOrientation(3) = (FILTER_COEFFICIENT ...
* (gyroOrientation(3) + 2.0 * pi) + oneMinusCoeff ...
* orientation(3));
if fusedOrientation(3) > pi
fusedOrientation(3) = fusedOrientation(3) - 2.0 * pi;
end
elseif (orientation(3) < -0.5 * pi && gyroOrientation(3) > 0.0)
fusedOrientation(3) = (FILTER_COEFFICIENT ...
* gyroOrientation(3) + oneMinusCoeff ...
* (orientation(3) + 2.0 * pi));
if fusedOrientation(3) > pi
fusedOrientation(3) = fusedOrientation(3) - 2.0 * pi;
end
else
fusedOrientation(3) = FILTER_COEFFICIENT * gyroOrientation(3)...
+ oneMinusCoeff * orientation(3);
end
end