Main Content

OccupancyGrid

(To be removed) Create occupancy grid message

Since R2019b

OccupancyGrid object will be removed in a future release. Use message structure format when you create ROS messages using the rosmessage function, by specifying the Dataformat name-value argument as "struct". You can use rosReadBinaryOccupancyGrid, rosReadOccupancyGrid, rosWriteBinaryOccupancyGrid, and rosWriteOccupancyGrid functions to work with occupancy grid messages. For more information, see ROS Message Structure Functions.

Description

The OccupancyGrid object is an implementation of the nav_msgs/OccupancyGrid message type in ROS. The object contains meta-information about the message and the occupancy grid data.

To create a binaryOccupancyMap (Robotics System Toolbox) object from a ROS message, use the readBinaryOccupancyGrid function.

To create an occupancyMap (Navigation Toolbox) object , use the readOccupancyGrid function.

Creation

Description

example

msg = rosmessage('nav_msgs/OccupancyGrid'); creates an empty OccupancyGrid object. To specify map information and data, use the map.Info and msg.Data properties. You can also get the occupancy grid messages off the ROS network using rossubscriber.

Properties

expand all

This property is read-only.

Message type of ROS message, returned as a character vector.

Data Types: char

This property is read-only.

ROS Header message, returned as a Header object. This header message contains the MessageType, sequence (Seq), timestamp (Stamp), and FrameId.

Information about the map, specified as a MapMetaData object. It contains the width, height, resolution, and origin of the map.

Map data, specified as a vector. The vector is all the occupancy data from each grid location in a single 1-D array.

Object Functions

readOccupancyGrid(To be removed) Read occupancy grid message
readBinaryOccupancyGrid(To be removed) Read binary occupancy grid
writeBinaryOccupancyGrid(To be removed) Write values from grid to ROS message
writeOccupancyGrid(To be removed) Write values from grid to ROS message

Examples

collapse all

Load two maps, simpleMap and complexMap, as logical matrices. Use whos to display the map.

load exampleMaps.mat
whos *Map*
  Name              Size               Bytes  Class      Attributes

  complexMap       41x52                2132  logical              
  emptyMap         26x27                 702  logical              
  simpleMap        26x27                 702  logical              
  ternaryMap      501x501            2008008  double               

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
mapMsg = 
  ROS OccupancyGrid message with properties:

    MessageType: 'nav_msgs/OccupancyGrid'
         Header: [1x1 Header]
           Info: [1x1 MapMetaData]
           Data: [702x1 int8]

  Use showdetails to show the contents of the message

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);

Version History

Introduced in R2019b

collapse all

R2021a: ROS Message Structure Functions

You can now create messages as structures with fields matching the message object properties. Using structures typically improves performance of creating, updating, and using ROS messages, but message fields are no longer validated when set. Message types and corresponding field values from the structures are validated when sent across the network.

To support message structures as inputs, new functions that operate on specialized ROS messages have been provided. These new functions are based on the existing object functions of message objects, but support ROS and ROS 2 message structures as inputs instead of message objects.

The object functions will be removed in a future release.

Message TypesObject Function NameNew Function Name

Image

CompressedImage

readImage

writeImage

rosReadImage

rosWriteImage

LaserScan

readCartesian

readScanAngles

lidarScan

plot

rosReadCartesian

rosReadScanAngles

rosReadLidarScan

rosPlot

PointCloud2

apply

readXYZ

readRGB

readAllFieldNames

readField

scatter3

rosApplyTransform

rosReadXYZ

rosReadRGB

rosReadAllFieldNames

rosReadField

rosPlot

QuaternionreadQuaternion

rosReadQuaternion

OccupancyGrid

readBinaryOccupanyGrid

readOccupancyGrid

writeBinaryOccupanyGrid

writeOccupanyGrid

rosReadOccupancyGrid

rosReadBinaryOccupancyGrid

rosReadOccupancyGrid

rosWriteBinaryOccupancyGrid

rosWriteOccupancyGrid

OctomapreadOccupancyMap3D

rosReadOccupancyMap3D

PointStamped

PoseStamped

QuaternionStamped

Vector3Stamped

TransformStamped

apply

rosApplyTransform

All messagesshowdetails

rosShowDetails