-
Notifications
You must be signed in to change notification settings - Fork 5
/
IGPOM.m
80 lines (63 loc) · 2.81 KB
/
IGPOM.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 output = IGPOM(robotPose, laserScan, Parameters, gpom_store)
% Incremental Gaussian processes occupancy mapping using range-finder sensors:
% Ghaffari Jadidi, M., Valls Miro, J. & Dissanayake, G. Auton Robot (2017). https://doi.org/10.1007/s10514-017-9668-3
% Pre-print available on: https://arxiv.org/abs/1605.00335
%{
Copyright (C) 2018 Maani Ghaffari Jadidi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 General Public License for more details.
%}
% test data is a grid centred at the sensor
x = -Parameters.gp.param.testAreaSize:Parameters.gp.param.testPointDist:Parameters.gp.param.testAreaSize;
[X,Y] = meshgrid(x,x);
tdata = [];
tdata.t = [X(:), Y(:)];
tdata.size = size(X);
% sample free area points along each beam
[fp, yp] = beamSampling(laserScan);
meanfunc = Parameters.gp.meanfunc;
covfunc = Parameters.gp.covfunc;
likfunc = Parameters.gp.likfunc;
inffunc = Parameters.gp.inffunc;
% Computing GPOM
x_free = cell(size(laserScan));
x_occupied = cell(size(laserScan));
numSteps = length(laserScan); % number of steps/scans
fusedMaps = gpom_store.maps;
if Parameters.plot
figure; hold on
end
for i = 1:numSteps
currentPose = [robotPose.x(i), robotPose.y(i), robotPose.h(i)];
% training data
x_occupied{i} = [laserScan{i}(1,:)', laserScan{i}(2,:)']; % occupied points returned by laser
x_free{i} = [fp{i}(1,:)', fp{i}(2,:)']; % sampled points from free area along each laser beam
X_training = [x_free{i}; x_occupied{i}]; % design matrix
y_training = [-yp{i}(:); ones(size(x_occupied{i},1),1)]; % target values
% GP regression
if i == 1 && Parameters.gp.opthp
gpom_store.hyp = minimize(gpom_store.hyp, @gp, Parameters.gp.iterMaxf, inffunc, meanfunc, covfunc, likfunc, X_training, y_training);
end
[mu, s2] = gp(gpom_store.hyp, inffunc, meanfunc, covfunc, likfunc, X_training, y_training, tdata.t);
% Updating the maps
[fmu, fcov, fmap, ids] = mapUpdateKDT(mu, s2, fusedMaps, tdata, currentPose);
fusedMaps.P = fmap;
fusedMaps.C = fcov;
fusedMaps.Mu = fmu;
fusedMaps.ids = ids;
if Parameters.plot
pcolor(Parameters.gp.testPoint.X, Parameters.gp.testPoint.Y, reshape(fusedMaps.P,fusedMaps.size)), caxis([0, 1])
colormap jet; colorbar, shading interp, grid off
axis equal, axis(Parameters.plotArea)
drawnow
end
end
output = gpom_store;
output.maps = fusedMaps;
end