%% Insert Laser Scans Into Occupancy Grid
% Take the laser scan data and insert into an occupancy grid.
% Create an empty occupancy grid map.

map = robotics.OccupancyGrid(10,10,20);

%
% Input pose of the robot, ranges and angles and the max range of the laser scan.

pose = [5,5,0];
ranges = 3*ones(100, 1);
angles = linspace(-pi/2, pi/2, 100);
maxrange = 20;

%
% Create a lidarScan object by specifying the ranges and angles.

scan = lidarScan(ranges,angles);

%
% Insert the laser scan data into the occupancy grid.

insertRay(map,pose,scan,maxrange);

%
% Show the map to see the results of inserting the laser scan. Check the occupancy of the spot directly in front of the robot.

show(map)
getOccupancy(map,[8 5])

%
% Add a second reading and view the update to the occupancy values. The additional reading increases the confidence in the readings. The free and occupied values become more distinct.

insertRay(map,pose,scan,maxrange);
show(map)
getOccupancy(map,[8 5])

%
% Copyright 2012 The MathWorks, Inc.