-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARPOD_Sensing.m
105 lines (96 loc) · 3.51 KB
/
ARPOD_Sensing.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%3DOF ARPOD sensing model
%assumes the trajectories are size 6 with position and their derivatives.
classdef ARPOD_Sensing
methods (Static)
function sense_data = convertTrajs(trajs)
[n_traj, dim_traj] = size(trajs);
e = zeros(3,n_traj);
for i = 1:n_traj
traj = trajs(i,:);
x = traj(1);
y = traj(2);
z = traj(3);
norm = sqrt(x*x+y*y+z*z);
e1 = atan(y/x);
e2 = asin(z/norm);
e3 = norm;
e(:,i) = [e1;e2;e3];
end
sense_data = e;
end
function noisy_data = noisifyData(sense_data, noise_model)
[dim_traj, n_traj] = size(sense_data);
noisy_data = sense_data;
for i = 1:n_traj
noisy_data(:,i) = sense_data(:,i) + noise_model();
end
%noisy_trajs is returned
end
function z_t = measure(state) %add flags for measurement
x = state(1);
y = state(2);
z = state(3);
norm = sqrt(x*x+y*y+z*z);
e1 = atan(y/x);
e2 = asin(z/norm);
e3 = norm;
z_t = [e1;e2;e3];
end
function jacobian = jacobianMeasurement(x,y,z)
jacobian = zeros(3,6);
%dArctan
partialX = -y/(x*x+y*y);
partialY = x/(x*x+y*y);
jacobian(1,1) = partialX;
jacobian(1,2) = partialY;
%rest of the partials are zero so it doesn't matter anyways.
%dArcsin
norm = sqrt( (x*x+y*y)/(x*x+y*y+z*z) ) * (x*x+y*y+z*z).^(3/2);
partialX = -x*z/norm;
partialY = -y*z/norm;
partialZ = sqrt( (x*x+y*y)/(x*x+y*y+z*z) ) / sqrt(x*x+y*y+z*z);
jacobian(2,1) = partialX;
jacobian(2,2) = partialY;
jacobian(2,3) = partialZ;
%drho
norm = sqrt(x*x+y*y+z*z);
partialX = x/norm;
partialY = y/norm;
partialZ = z/norm;
jacobian(3,1) = partialX;
jacobian(3,2) = partialY;
jacobian(3,3) = partialZ;
%return jacobian
end
function jacobian = jacobianPartner(x,y,z,r)
rx = r(1);
ry = r(2);
rz = r(3);
jacobian = zeros(3,6);
%dArctan
partialX = (ry-y)/(ry*ry - 2*ry*y + rx*rx - 2*rx*x + x*x + y*y);
partialY = (x-rx)/(ry*ry - 2*ry*y + rx*rx - 2*rx*x + x*x + y*y);
jacobian(1,1) = partialX;
jacobian(1,2) = partialY;
%rest of the partials are zero so it doesn't matter anyways.
%dArcsin
bignorm = sqrt(1 - (rz-z).^2 / (rx-x).^2 + (ry-y).^2 + (rz-z).^2);
norm = ((rx-x).^2 + (ry-y).^2 + (rz-z).^2).^(3/2) * bignorm;
partialX = (rx-x)*(rz-z)/norm;
partialY = (ry-y)*(rz-z)/norm;
partialZ = (-rx*rx + 2*rx*x - ry*ry + 2*ry*y - rx*rx - ry*ry) / sqrt(x*x+y*y+z*z);
jacobian(2,1) = partialX;
jacobian(2,2) = partialY;
jacobian(2,3) = partialZ;
%drho
norm = sqrt((rx-x).^2 + (ry-y).^2 + (rz-z).^2);
partialX = -(rx-x)/norm;
partialY = -(ry-y)/norm;
partialZ = -(rz-z)/norm;
jacobian(3,1) = partialX;
jacobian(3,2) = partialY;
jacobian(3,3) = partialZ;
%return jacobian
end
end
end