data_gps =load('GPS_meta.csv');
[filename, directory_name] = uigetfile('*.csv','GPS_meta.csv');
fullname = fullfile(directory_name, filename);
data_gps = load(fullname);
latitudine = data_gps(:,1);
longitudine = data_gps(:,2);
altitudine = repmat(55.0, 1, length(latitudine))';
data_imu = load('DATALOG_meta.csv');
[filename1, directory_name1] = uigetfile('*.csv','DATALOG_meta.csv');
fullname = fullfile(directory_name1, filename1);
data_imu = load(fullname);
acc_tot = [accx accy accz];
gyro_tot = [gyrox gyroy gyroz];
max_lat = max(latitudine);
min_lat = min(latitudine);
max_long = max(longitudine);
min_long = min(longitudine);
geoplot(latitudine,longitudine,"-",LineWidth=1.5);
geolimits([min_lat max_lat],[min_long max_long])
localOrigin = [44.76483 10.30858 55];
gyro_tot_rad = deg2rad(gyro_tot);
filt = insfilterNonholonomic('ReferenceFrame', 'ENU');
filt.IMUSampleRate = imuFs;
filt.ReferenceLocation = localOrigin;
filt.StateCovariance = 1e-9*eye(16);
fuse = imufilter('SampleRate',imuFs, 'GyroscopeDriftNoise', 1e-6);
[orientazione ,angVelBodyRecovered] = fuse(acc_tot, gyro_tot_rad);
numIMUSamples = length(latitudine);
estOrient = quaternion.ones(numIMUSamples,1);
estPos = zeros(numIMUSamples,3);
for idx = 1:numIMUSamples
predict(filt,acc_tot(idx,:),gyro_tot_rad(idx,:));
[res, resCov] = fusegps(filt, [latitudine(gpsIdx,:) longitudine(gpsIdx,:) altitudine(gpsIdx,:)], Rpos);
[estPos(idx,:),estOrient(idx,:)] = pose(filt);