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

load exampleMaps.mat
whos *Map*

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

bogMap = binaryOccupancyMap(double(simpleMap));
mapMsg = rosmessage('nav_msgs/OccupancyGrid');
writeBinaryOccupancyGrid(mapMsg,bogMap)
mapMsg

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

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

% Copyright 2019 The MathWorks, Inc.