-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplot_EKF.m
More file actions
114 lines (98 loc) · 3.52 KB
/
plot_EKF.m
File metadata and controls
114 lines (98 loc) · 3.52 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
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
106
107
108
109
110
111
112
113
114
%% Clean up console and variables
clc; close all; clear all;
addpath('classes');
addpath('utilities');
%% Load saved SLATS data
load('cache/temp.mat');
node_ids = nm.getNodeIds();
node_names = nm.getNodeNames();
%% Plot Path
handles = [];
t_history = nm.getAllMeasurementTimes();
p_errors = [];
rb = 1;
rb_id = 'ntb-mobile';
rb_idx = nm.getNodeIdx(rb_id);
xyzm_all = [];
xyze_all = [];
errors_all = [];
time_all = [];
downsample = 50;
for i=1:length(t_history);
if i > length(p_history)
break;
end
t = t_history(i);
[xyz_mocap, lat] = nm.dataparser.getMocapPos( rb, t );
if lat < 0.050
xyz_est = p_history{i}(rb_idx,:);
xyz_err = xyz_mocap - xyz_est;
xyzm_all = [xyzm_all; xyz_mocap];
xyze_all = [xyze_all; xyz_est];
time_all = [time_all; t];
xyz_err = xyz_mocap - xyz_est;
errors_all = [errors_all; norm(xyz_err)];
p_errors = [p_errors; t xyz_err];
end
end
% a little bit of filtering for plotting
xyze_all(:,1) = medfilt1(xyze_all(:,1), 3);
xyze_all(:,2) = medfilt1(xyze_all(:,2), 3);
xyze_all(:,3) = medfilt1(xyze_all(:,3), 3);
%% Plot
cfigure(35,11);
% ----- path -----
subplot(2,4,[1 2 5 6]);
plot3(xyzm_all(1:downsample:end,1), xyzm_all(1:downsample:end,2), xyzm_all(1:downsample:end,3), 'bo');
hold on;
plot3(xyze_all(1:downsample:end,1), xyze_all(1:downsample:end,2), xyze_all(1:downsample:end,3), 's', 'MarkerFaceColor', [0 0.75 0], 'Color', [0 0.5 0]);
xlabel('X Position (m)');
%ylabel('Y Position (m)');
zlabel('Z Position (m)');
grid on;
leg_str = sprintf('Estimated Position, RMSE: %.3f', sqrt( mean( errors_all ).^2 ) );
set(gca, 'View', [-173.5 12]);
hl = legend('True Position', leg_str);
lpos = get(hl,'Position');
set(hl,'Position', [0.15 0.75 lpos([3 4])]);
xlabpos = get(get(gca,'XLabel'), 'Position');
set(get(gca, 'XLabel'), 'Position', xlabpos + [0 -1.2 0]);
% ----- x y z errors -----
subplot(2,4,[3 4]);
tstart = p_errors(1,1);
plot(p_errors(:,1) - tstart, p_errors(:,2), 's', 'MarkerSize', 3, 'Color', [0 0.5 0]);
hold on;
plot(p_errors(:,1) - tstart, p_errors(:,3), 'bo', 'MarkerSize', 3);
plot(p_errors(:,1) - tstart, p_errors(:,4), 'm^', 'MarkerSize', 3);
plot(p_errors(:,1) - tstart, zeros( size(p_errors(:,1)) ), '--k', 'LineWidth',2);
ylabel('Error (m)');
xlabel('Time (sec)');
grid on;
ylim([-2 2]);
% legends
xstr = sprintf('X (mean %.2fm, RMSE %.2f)', mean(p_errors(:,2)), sqrt( mean( p_errors(:,2).^2 ) ) );
ystr = sprintf('Y (mean %.2fm, RMSE %.2f)', mean(p_errors(:,3)), sqrt( mean( p_errors(:,3).^2 ) ) );
zstr = sprintf('Z (mean %.2fm, RMSE %.2f)', mean(p_errors(:,4)), sqrt( mean( p_errors(:,4).^2 ) ) );
[hleg, hobj, hout, mout] = legend({xstr, ystr, zstr});
set(hobj(5), 'MarkerSize', 8);
set(hobj(7), 'MarkerSize', 8);
set(hobj(9), 'MarkerSize', 8);
% ----- norm error vs. pos -----
subplot(2,4,[7 8]);
ds = 50;
tstart = time_all(1);
% dist from centroid
xyz_static = nm.getTrueStaticPositions();
xyz_centroid = mean(xyz_static(:,2:4));
xyz_dist = sqrt( sum( (xyzm_all - repmat(xyz_centroid, size(xyzm_all,1), 1)).^2, 2) );
[hax, hl1, hl2] = plotyy(time_all(1:ds:end) -tstart, medfilt1(errors_all(1:ds:end),2), time_all(1:ds:end) -tstart, xyz_dist(1:ds:end));
set(hl1,'Marker', 's');
set(hl2,'Marker', 'o');
set(hax(1),'YTick',[0:0.5:2])
set(hax(2),'YTick',[0:1:4])
xlabel('Time (sec)');
ylabel(hax(1), 'Estimate error (m)');
ylabel(hax(2), 'Distance from centroid (m)');
ylim(hax(1), [0 2]);
grid on;
%saveplot('output/ped01_R_path');