-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnavego_example.m
584 lines (452 loc) · 19.5 KB
/
navego_example.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
% Example of use of NaveGo.
%
% Main goal: to compare two INS/GPS systems performances, one using a
% simulated ADIS16405 IMU and simulated GPS, and another using a
% simulated ADIS16488 IMU and the same simulated GPS.
%
% Copyright (C) 2014, Rodrigo Gonzalez, all rights reserved.
%
% This file is part of NaveGo, an open-source MATLAB toolbox for
% simulation of integrated navigation systems.
%
% NaveGo is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License (LGPL)
% version 3 as published by the Free Software Foundation.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this program. If not, see
% <http://www.gnu.org/licenses/>.
%
% References:
% R. Gonzalez, J. Giribet, and H. Patiño. NaveGo: a
% simulation framework for low-cost integrated navigation systems,
% Journal of Control Engineering and Applied Informatics, vol. 17,
% issue 2, pp. 110-120, 2015.
%
% Analog Devices. ADIS16400/ADIS16405 datasheet. High Precision
% Tri-Axis Gyroscope, Accelerometer, Magnetometer. Rev. B.
% http://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16400_16405.pdf
%
% Analog Devices. ADIS16488 datasheet. Tactical Grade Ten Degrees
% of Freedom Inertial Sensor. Rev. G.
% http://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16488.pdf
%
% Garmin International, Inc. GPS 18x TECHNICAL SPECIFICATIONS.
% Revision D. October 2011.
% http://static.garmin.com/pumac/GPS_18x_Tech_Specs.pdf
%
% Version: 008
% Date: 2016/11/17
% Author: Rodrigo Gonzalez <[email protected]>
% URL: https://github.com/rodralez/navego
clc
close all
clear
matlabrc
versionstr = 'NaveGo, release v0.8.0-alpha';
fprintf('\n%s.\n', versionstr)
fprintf('\nNaveGo: starting simulation ... \n')
%% CODE EXECUTION PARAMETERS
% Comment any of the following parameters in order to NOT execute a particular portion of code
GPS_DATA = 'ON'; % Simulate GPS data
IMU1_DATA = 'ON'; % Simulate ADIS16405 IMU data
IMU2_DATA = 'ON'; % Simulate ADIS16488 IMU data
IMU1_INS = 'ON'; % Execute INS/GPS integration for ADIS16405 IMU
IMU2_INS = 'ON'; % Execute INS/GPS integration for ADIS16488 IMU
PLOT = 'ON'; % Plot results.
% If a particular parameter is commented above, it is set by default to 'OFF'.
if (~exist('GPS_DATA','var')), GPS_DATA = 'OFF'; end
if (~exist('IMU1_DATA','var')), IMU1_DATA = 'OFF'; end
if (~exist('IMU2_DATA','var')), IMU2_DATA = 'OFF'; end
if (~exist('IMU1_INS','var')), IMU1_INS = 'OFF'; end
if (~exist('IMU2_INS','var')), IMU2_INS = 'OFF'; end
if (~exist('PLOT','var')), PLOT = 'OFF'; end
%% CONVERSION CONSTANTS
G = 9.81; % Gravity constant, m/s^2
G2MSS = G; % g to m/s^2
MSS2G = (1/G); % m/s^2 to g
D2R = (pi/180); % degrees to radians
R2D = (180/pi); % radians to degrees
KT2MS = 0.514444; % knot to m/s
MS2KMH = 3.6; % m/s to km/h
%% LOAD REFERENCE DATA
fprintf('NaveGo: loading reference dataset from a trajectory generator... \n')
load ref.mat
% ref.mat contains the reference data structure from which inertial
% sensors and GPS wil be simulated. It must contain the following fields:
% t: Nx1 time vector (seconds).
% lat: Nx1 latitude (radians).
% lon: Nx1 longitude (radians).
% h: Nx1 altitude (m).
% vel: Nx3 NED velocities (m/s).
% roll: Nx1 roll angles (radians).
% pitch: Nx1 pitch angles (radians).
% yaw: Nx1 yaw angle vector (radians).
% kn: 1x1 number of elements of time vector.
% DCMnb: Nx9 Direct Cosine Matrix nav-to-body. Each row contains
% the elements of one matrix ordered by columns as
% [a11 a21 a31 a12 a22 a32 a13 a23 a33].
% freq: sampling frequency (Hz).
%% ADIS16405 IMU error profile
% IMU data structure:
% t: Ix1 time vector (seconds).
% fb: Ix3 accelerations vector in body frame XYZ (m/s^2).
% wb: Ix3 turn rates vector in body frame XYZ (radians/s).
% arw: 1x3 angle random walks (rad/s/root-Hz).
% vrw: 1x3 angle velocity walks (m/s^2/root-Hz).
% gstd: 1x3 gyros standard deviations (radians/s).
% astd: 1x3 accrs standard deviations (m/s^2).
% gb_fix: 1x3 gyros static biases or turn-on biases (radians/s).
% ab_fix: 1x3 accrs static biases or turn-on biases (m/s^2).
% gb_drift: 1x3 gyros dynamic biases or bias instabilities (radians/s).
% ab_drift: 1x3 accrs dynamic biases or bias instabilities (m/s^2).
% gb_corr: 1x3 gyros correlation times (seconds).
% ab_corr: 1x3 accrs correlation times (seconds).
% gpsd : 1x3 gyros dynamic biases PSD (rad/s/root-Hz).
% apsd : 1x3 accrs dynamic biases PSD (m/s^2/root-Hz);
% freq: 1x1 sampling frequency (Hz).
% ini_align: 1x3 initial attitude at t(1).
% ini_align_err: 1x3 initial attitude errors at t(1).
% ref dataset will be used to simulate IMU sensors.
ADIS16405.arw = 2 .* ones(1,3); % Angle random walks [X Y Z] (deg/root-hour)
ADIS16405.vrw = 0.2 .* ones(1,3); % Velocity random walks [X Y Z] (m/s/root-hour)
ADIS16405.gb_fix = 3 .* ones(1,3); % Gyro static biases [X Y Z] (deg/s)
ADIS16405.ab_fix = 50 .* ones(1,3); % Acc static biases [X Y Z] (mg)
ADIS16405.gb_drift = 0.007 .* ones(1,3); % Gyro dynamic biases [X Y Z] (deg/s)
ADIS16405.ab_drift = 0.2 .* ones(1,3); % Acc dynamic biases [X Y Z] (mg)
ADIS16405.gb_corr = 100 .* ones(1,3); % Gyro correlation times [X Y Z] (seconds)
ADIS16405.ab_corr = 100 .* ones(1,3); % Acc correlation times [X Y Z] (seconds)
ADIS16405.freq = ref.freq; % IMU operation frequency [X Y Z] (Hz)
% ADIS16405.m_psd = 0.066 .* ones(1,3); % Magnetometer noise density [X Y Z] (mgauss/root-Hz)
ADIS16405.t = ref.t; % IMU time vector
dt = mean(diff(ADIS16405.t)); % IMU mean period
imu1 = imu_err_profile(ADIS16405, dt); % Transform IMU manufacturer error units to SI units.
imu1.ini_align_err = [1 1 5] .* D2R; % Initial attitude align errors for matrix P in Kalman filter, [roll pitch yaw] (radians)
imu1.ini_align = [ref.roll(1) ref.pitch(1) ref.yaw(1)]; % Initial attitude align at t(1) (radians).
%% ADIS16488 IMU error profile
% ref dataset will be used to simulate IMU sensors.
ADIS16488.arw = 0.3 .* ones(1,3); % Angle random walks [X Y Z] (deg/root-hour)
ADIS16488.vrw = 0.029.* ones(1,3); % Velocity random walks [X Y Z] (m/s/root-hour)
ADIS16488.gb_fix = 0.2 .* ones(1,3); % Gyro static biases [X Y Z] (deg/s)
ADIS16488.ab_fix = 16 .* ones(1,3); % Acc static biases [X Y Z] (mg)
ADIS16488.gb_drift = 6.5/3600 .* ones(1,3);% Gyro dynamic biases [X Y Z] (deg/s)
ADIS16488.ab_drift = 0.1 .* ones(1,3); % Acc dynamic biases [X Y Z] (mg)
ADIS16488.gb_corr = 100 .* ones(1,3); % Gyro correlation times [X Y Z] (seconds)
ADIS16488.ab_corr = 100 .* ones(1,3); % Acc correlation times [X Y Z] (seconds)
ADIS16488.freq = ref.freq; % IMU operation frequency [X Y Z] (Hz)
% ADIS16488.m_psd = 0.054 .* ones(1,3); % Magnetometer noise density [X Y Z] (mgauss/root-Hz)
ADIS16488.t = ref.t; % IMU time vector
dt = mean(diff(ADIS16488.t)); % IMU mean period
imu2 = imu_err_profile(ADIS16488, dt); % Transform IMU manufacturer error units to SI units.
imu2.ini_align_err = [1 1 5] .* D2R; % Initial attitude align errors for matrix P in Kalman filter, [roll pitch yaw] (radians)
imu2.ini_align = [ref.roll(1) ref.pitch(1) ref.yaw(1)]; % Initial attitude align at t(1) (radians).
%% Garmin 5-18 Hz GPS error profile
% GPS data structure:
% t: Mx1 time vector (seconds).
% lat: Mx1 latitude (radians).
% lon: Mx1 longitude (radians).
% h: Mx1 altitude (m).
% vel: Mx3 NED velocities (m/s).
% std: 1x3 position standard deviations (rad, rad, m).
% stdm: 1x3 position standard deviations (m, m, m).
% stdv: 1x3 velocity standard deviations (m/s).
% larm: 3x1 lever arm (x-right, y-fwd, z-down) (m).
% freq: 1x1 sampling frequency (Hz).
gps.stdm = [5, 5, 10]; % GPS positions standard deviations [lat lon h] (meters)
gps.stdv = 0.1 * KT2MS .* ones(1,3); % GPS velocities standard deviations [Vn Ve Vd] (meters/s)
gps.larm = zeros(3,1); % GPS lever arm [X Y Z] (meters)
gps.freq = 5; % GPS operation frequency (Hz)
%% SIMULATE GPS
rng('shuffle') % Reset pseudo-random seed
if strcmp(GPS_DATA, 'ON') % If simulation of GPS data is required ...
fprintf('NaveGo: simulating GPS data... \n')
gps = gps_err_profile(ref.lat(1), ref.h(1), gps); % Transform GPS manufacturer error units to SI units.
[gps] = gps_gen(ref, gps); % Generate GPS dataset from reference dataset.
save gps.mat gps
else
fprintf('NaveGo: loading GPS data... \n')
load gps.mat
end
%% SIMULATE IMU1
rng('shuffle') % Reset pseudo-random seed
if strcmp(IMU1_DATA, 'ON') % If simulation of IMU1 data is required ...
fprintf('NaveGo: generating IMU1 ACCR data... \n')
fb = acc_gen (ref, imu1); % Generate acc in the body frame
imu1.fb = fb;
fprintf('NaveGo: generating IMU1 GYRO data... \n')
wb = gyro_gen (ref, imu1);% Generate gyro in the body frame
imu1.wb = wb;
save imu1.mat imu1
clear wb fb;
else
fprintf('NaveGo: loading IMU1 data... \n')
load imu1.mat
end
%% SIMULATE IMU2
rng('shuffle') % Reset pseudo-random seed
if strcmp(IMU2_DATA, 'ON') % If simulation of IMU2 data is required ...
fprintf('NaveGo: generating IMU2 ACCR data... \n')
fb = acc_gen (ref, imu2); % Generate acc in the body frame
imu2.fb = fb;
fprintf('NaveGo: generating IMU2 GYRO data... \n')
wb = gyro_gen (ref, imu2);% Generate gyro in the body frame
imu2.wb = wb;
save imu2.mat imu2
clear wb fb;
else
fprintf('NaveGo: loading IMU2 data... \n')
load imu2.mat
end
%% INS/GPS integration using IMU1
if strcmp(IMU1_INS, 'ON')
fprintf('NaveGo: INS/GPS integration for IMU1... \n')
% Sincronize GPS data with IMU data.
% Guarantee that gps.t(1) < imu1.t(1) < gps.t(2)
if (imu1.t(1) < gps.t(1)),
igx = find(imu1.t > gps.t(1), 1, 'first' );
imu1.t = imu1.t (igx:end, :);
imu1.fb = imu1.fb (igx:end, :);
imu1.wb = imu1.wb (igx:end, :);
end
% Guarantee that imu1.t(end-1) < gps.t(end) < imu1.t(end)
if (imu1.t(end) <= gps.t(end)),
fgx = find(gps.t < imu1.t(end), 1, 'last' );
gps.t = gps.t (1:fgx, :);
gps.lat = gps.lat(1:fgx, :);
gps.lon = gps.lon(1:fgx, :);
gps.h = gps.h (1:fgx, :);
gps.vel = gps.vel(1:fgx, :);
end
% Execute INS/GPS integration
% ---------------------------------------------------------------------
[imu1_e] = ins_gps(imu1, gps, 'quaternion', 'double');
% ---------------------------------------------------------------------
save imu1_e.mat imu1_e
else
fprintf('NaveGo: loading INS/GPS integration for IMU1... \n')
load imu1_e.mat
end
%% INS/GPS integration using IMU2
if strcmp(IMU2_INS, 'ON')
fprintf('\nNaveGo: INS/GPS integration for IMU2... \n')
% Sincronize GPS data and IMU data.
% Guarantee that gps.t(1) < imu2.t(1) < gps.t(2)
if (imu2.t(1) < gps.t(1)),
igx = find(imu2.t > gps.t(1), 1, 'first' );
imu2.t = imu2.t (igx:end, :);
imu2.fb = imu2.fb (igx:end, :);
imu2.wb = imu2.wb (igx:end, :);
end
% Guarantee that imu2.t(end-1) < gps.t(end) < imu2.t(end)
if (imu2.t(end) <= gps.t(end)),
fgx = find(gps.t < imu2.t(end), 1, 'last' );
gps.t = gps.t (1:fgx, :);
gps.lat = gps.lat(1:fgx, :);
gps.lon = gps.lon(1:fgx, :);
gps.h = gps.h (1:fgx, :);
gps.vel = gps.vel(1:fgx, :);
end
% Execute INS/GPS integration
% ---------------------------------------------------------------------
[imu2_e] = ins_gps(imu2, gps, 'quaternion', 'double');
% ---------------------------------------------------------------------
save imu2_e.mat imu2_e
else
fprintf('NaveGo: loading INS/GPS integration for IMU2... \n')
load imu2_e.mat
end
%% Interpolate reference dataset
ref_1 = navego_interpolation (imu1_e, ref);
ref_2 = navego_interpolation (imu2_e, ref);
ref_g = navego_interpolation (gps, ref);
%% Print navigation time
to = (ref.t(end) - ref.t(1));
fprintf('\nNaveGo: navigation time of %4.2f minutes or %4.2f seconds. \n', (to/60), to)
%% Print RMSE from IMU1
print_rmse (imu1_e, gps, ref_1, ref_g, 'INS/GPS IMU1');
%% Print RMSE from IMU2
print_rmse (imu2_e, gps, ref_2, ref_g, 'INS/GPS IMU2');
%% PLOT
if (strcmp(PLOT,'ON'))
sig3_rr = abs(imu1_e.P_d.^(0.5)).*3;
% TRAJECTORY
figure;
plot3(ref.lon.*R2D, ref.lat.*R2D, ref.h)
hold on
plot3(ref.lon(1).*R2D, ref.lat(1).*R2D, ref.h(1), 'or', 'MarkerSize', 10, 'LineWidth', 2)
axis tight
title('TRAJECTORY')
xlabel('Longitude [deg.]')
ylabel('Latitude [deg.]')
zlabel('Altitude [m]')
grid
% ATTITUDE
figure;
subplot(311)
plot(ref_1.t, R2D.*ref_1.roll, '--k', imu1_e.t, R2D.*imu1_e.roll,'-b', imu2_e.t, R2D.*imu2_e.roll,'-r');
ylabel('[deg]')
xlabel('Time [s]')
legend('REF', 'IMU1', 'IMU2');
title('ROLL');
subplot(312)
plot(ref_1.t, R2D.*ref_1.pitch, '--k', imu1_e.t, R2D.*imu1_e.pitch,'-b', imu2_e.t, R2D.*imu2_e.pitch,'-r');
ylabel('[deg]')
xlabel('Time [s]')
legend('REF', 'IMU1', 'IMU2');
title('PITCH');
subplot(313)
plot(ref_1.t, R2D.* ref_1.yaw, '--k', imu1_e.t, R2D.*imu1_e.yaw,'-b', imu2_e.t, R2D.*imu2_e.yaw,'-r');
ylabel('[deg]')
xlabel('Time [s]')
legend('REF', 'IMU1', 'IMU2');
title('YAW');
% ATTITUDE ERRORS
figure;
subplot(311)
plot(imu1_e.t, (imu1_e.roll-ref_1.roll).*R2D, '-b', imu2_e.t, (imu2_e.roll-ref_2.roll).*R2D, '-r');
hold on
plot (gps.t, R2D.*sig3_rr(:,1), '--k', gps.t, -R2D.*sig3_rr(:,1), '--k' )
ylabel('[deg]')
xlabel('Time [s]')
legend('IMU1', 'IMU2', '3\sigma');
title('ROLL ERROR');
subplot(312)
plot(imu1_e.t, (imu1_e.pitch-ref_1.pitch).*R2D, '-b', imu2_e.t, (imu2_e.pitch-ref_2.pitch).*R2D, '-r');
hold on
plot (gps.t, R2D.*sig3_rr(:,2), '--k', gps.t, -R2D.*sig3_rr(:,2), '--k' )
ylabel('[deg]')
xlabel('Time [s]')
legend('IMU1', 'IMU2', '3\sigma');
title('PITCH ERROR');
subplot(313)
plot(imu1_e.t, (imu1_e.yaw-ref_1.yaw).*R2D, '-b', imu2_e.t, (imu2_e.yaw-ref_2.yaw).*R2D, '-r');
hold on
plot (gps.t, R2D.*sig3_rr(:,3), '--k', gps.t, -R2D.*sig3_rr(:,3), '--k' )
ylabel('[deg]')
xlabel('Time [s]')
legend('IMU1', 'IMU2', '3\sigma');
title('YAW ERROR');
% VELOCITIES
figure;
subplot(311)
plot(ref.t, ref.vel(:,1), '--k', gps.t, gps.vel(:,1),'-c', imu1_e.t, imu1_e.vel(:,1),'-b', imu2_e.t, imu2_e.vel(:,1),'-r');
xlabel('Time [s]')
ylabel('[m/s]')
legend('REF', 'GPS', 'IMU1', 'IMU2');
title('NORTH VELOCITY');
subplot(312)
plot(ref.t, ref.vel(:,2), '--k', gps.t, gps.vel(:,2),'-c', imu1_e.t, imu1_e.vel(:,2),'-b', imu2_e.t, imu2_e.vel(:,2),'-r');
xlabel('Time [s]')
ylabel('[m/s]')
legend('REF', 'GPS', 'IMU1', 'IMU2');
title('EAST VELOCITY');
subplot(313)
plot(ref.t, ref.vel(:,3), '--k', gps.t, gps.vel(:,3),'-c', imu1_e.t, imu1_e.vel(:,3),'-b', imu2_e.t, imu2_e.vel(:,3),'-r');
xlabel('Time [s]')
ylabel('[m/s]')
legend('REF', 'GPS', 'IMU1', 'IMU2');
title('DOWN VELOCITY');
% VELOCITIES ERRORS
figure;
subplot(311)
plot(gps.t, (gps.vel(:,1)-ref_g.vel(:,1)), '-c');
hold on
plot(imu1_e.t, (imu1_e.vel(:,1)-ref_1.vel(:,1)), '-b', imu2_e.t, (imu2_e.vel(:,1)-ref_2.vel(:,1)), '-r');
hold on
plot (gps.t, sig3_rr(:,4), '--k', gps.t, -sig3_rr(:,4), '--k' )
xlabel('Time [s]')
ylabel('[m/s]')
legend('GPS', 'IMU1', 'IMU2', '3\sigma');
title('VELOCITY NORTH ERROR');
subplot(312)
plot(gps.t, (gps.vel(:,2)-ref_g.vel(:,2)), '-c');
hold on
plot(imu1_e.t, (imu1_e.vel(:,2)-ref_1.vel(:,2)), '-b', imu2_e.t, (imu2_e.vel(:,2)-ref_2.vel(:,2)), '-r');
hold on
plot (gps.t, sig3_rr(:,5), '--k', gps.t, -sig3_rr(:,5), '--k' )
xlabel('Time [s]')
ylabel('[m/s]')
legend('GPS', 'IMU1', 'IMU2', '3\sigma');
title('VELOCITY EAST ERROR');
subplot(313)
plot(gps.t, (gps.vel(:,3)-ref_g.vel(:,3)), '-c');
hold on
plot(imu1_e.t, (imu1_e.vel(:,3)-ref_1.vel(:,3)), '-b', imu2_e.t, (imu2_e.vel(:,3)-ref_2.vel(:,3)), '-r');
hold on
plot (gps.t, sig3_rr(:,6), '--k', gps.t, -sig3_rr(:,6), '--k' )
xlabel('Time [s]')
ylabel('[m/s]')
legend('GPS', 'IMU1', 'IMU2', '3\sigma');
title('VELOCITY DOWN ERROR');
% POSITION
figure;
subplot(311)
plot(ref.t, ref.lat .*R2D, '--k', gps.t, gps.lat.*R2D, '-c', imu1_e.t, imu1_e.lat.*R2D, '-b', imu2_e.t, imu2_e.lat.*R2D, '-r');
xlabel('Time [s]')
ylabel('[deg]')
legend('REF', 'GPS', 'IMU1', 'IMU2');
title('LATITUDE');
subplot(312)
plot(ref.t, ref.lon .*R2D, '--k', gps.t, gps.lon.*R2D, '-c', imu1_e.t, imu1_e.lon.*R2D, '-b', imu2_e.t, imu2_e.lon.*R2D, '-r');
xlabel('Time [s]')
ylabel('[deg]')
legend('REF', 'GPS', 'IMU1', 'IMU2');
title('LONGITUDE');
subplot(313)
plot(ref.t, ref.h, '--k', gps.t, gps.h, '-c', imu1_e.t, imu1_e.h, '-b', imu2_e.t, imu2_e.h, '-r');
xlabel('Time [s]')
ylabel('[m]')
legend('REF', 'GPS', 'IMU1', 'IMU2');
title('ALTITUDE');
% POSITION ERRORS
% fh = @radicurv;
% [RNs,REs] = arrayfun(fh, lat_rs);
[RN,RE] = radius(imu1_e.lat, 'double');
LAT2M = RN + imu1_e.h;
LON2M = (RE + imu1_e.h).*cos(imu1_e.lat);
[RN,RE] = radius(gps.lat, 'double');
lat2m_g = RN + gps.h;
lon2m_g = (RE + gps.h).*cos(gps.lat);
figure;
subplot(311)
plot(gps.t, lat2m_g.*(gps.lat - ref_g.lat), '-c')
hold on
plot(imu1_e.t, LAT2M.*(imu1_e.lat - ref_1.lat), '-b')
hold on
plot(imu2_e.t, LAT2M.*(imu2_e.lat - ref_2.lat), '-r')
hold on
plot (gps.t, lat2m_g.*sig3_rr(:,7), '--k', gps.t, -lat2m_g.*sig3_rr(:,7), '--k' )
xlabel('Time [s]')
ylabel('[m]')
legend('GPS', 'IMU1', 'IMU2', '3\sigma');
title('LATITUDE ERROR');
subplot(312)
plot(gps.t, lon2m_g.*(gps.lon - ref_g.lon), '-c')
hold on
plot(imu1_e.t, LON2M.*(imu1_e.lon - ref_1.lon), '-b')
hold on
plot(imu2_e.t, LON2M.*(imu2_e.lon - ref_2.lon), '-r')
hold on
plot(gps.t, lon2m_g.*sig3_rr(:,8), '--k', gps.t, -lon2m_g.*sig3_rr(:,8), '--k' )
xlabel('Time [s]')
ylabel('[m]')
legend('GPS', 'IMU1', 'IMU2', '3\sigma');
title('LONGITUDE ERROR');
subplot(313)
plot(gps.t, (gps.h - ref_g.h), '-c')
hold on
plot(imu1_e.t, (imu1_e.h - ref_1.h), '-b')
hold on
plot(imu2_e.t, (imu2_e.h - ref_2.h), '-r')
hold on
plot(gps.t, sig3_rr(:,9), '--k', gps.t, -sig3_rr(:,9), '--k' )
xlabel('Time [s]')
ylabel('[m]')
legend('GPS', 'IMU1', 'IMU2', '3\sigma');
title('ALTITUDE ERROR');
end