%% Match Scans Using Grid-Based Search
% Perform scan matching using a grid-based search to estimate the pose between two laser scans. Generate a probabilistic grid from the scans and estimate the pose difference from those grids.
%
% Load the laser scan data. These two scans are from an actual lidar sensor with changes in the robot pose and are stored as lidarScan objects.

load laserScans.mat scan scan2
plot(scan)
hold on
plot(scan2)
hold off

%
% Use matchScansGrid to estimate the pose between the two scans.

relPose = matchScansGrid(scan2,scan);

%
% Using the estimated pose, transform the current scan back to the reference scan. The scans overlap closely when you plot them together.

scan2Tformed = transformScan(scan2,relPose);

plot(scan)
hold on
plot(scan2Tformed)
hold off

%
% Copyright 2019 The MathWorks, Inc.