%% Create Occupancy Grid from 2-D Map
% Load two maps, simpleMap and complexMap, as logical matrices. Use  whos to show the map.

load exampleMaps.mat
whos *Map*

%
% Create a ROS message from simpleMap using a BinaryOccupancyGrid object. Write the OccupancyGrid message using writeBinaryOccupancyGrid.

bogMap = robotics.BinaryOccupancyGrid(double(simpleMap));
mapMsg = rosmessage('nav_msgs/OccupancyGrid');
writeBinaryOccupancyGrid(mapMsg,bogMap)
mapMsg

%
% Use readBinaryOccupancyGrid to convert the ROS message to a  BinaryOccupancyGrid object. Use the object function show to display the map.

bogMap2 = readBinaryOccupancyGrid(mapMsg);
show(bogMap2);

% Copyright 2012 The MathWorks, Inc.