Main Content

multiLayerMap

Manage multiple map layers

Description

The multiLayerMap object groups and stores multiple map layers as mapLayer, occupancyMap, or binaryOccupancyMap objects.

Once added to this object, map layers can be modified by either using the multiLayerMap object functions or by performing actions on individual map layers using their object functions or the layer name as input. Any modification to common properties on the multiLayerMap object are reflected across all associated layers.

Creation

Description

map = multiLayerMap creates an empty map object occupying 10-by-10 meters of space with a resolution of 1 cell per meter.

example

map = multiLayerMap(maps) creates a multilayer map from a cell array of mapLayer, occupancyMap, or binaryOccupancyMap objects. Objects combined into a multilayer map must be defined with the same resolution and cover the same region in space, but can represent different categories of information over the shared region.

map = multiLayerMap(names,mapData) creates a multilayer map from the cell array of layer names and associated cell array of map matrices. Matrices must have the same first two dimensions to cover the same shared region. Default resolution is 1 cell per meter.

map = multiLayerMap(names,width,height) creates a multilayer map with the cell array of layer names covering the specified width and height as scalars in meters.

map = multiLayerMap(names,width,height,cellDims) creates a multilayer map where the size of the data stored in each cell of the map is defined by the array of integers, cellDims. For multiple layers, cellDims is a cell array of integer arrays.

map = multiLayerMap(names,rows,cols,'grid') specifies the map width and height as a grid size specified in the rows and cols inputs.

map = multiLayerMap(names,rows,cols,cellDims,'grid') creates a map with a specified grid size and the size of the data stored in each cell is defined by the array of integers or cell array of integer arrays cellDims.

map = multiLayerMap(sourceMap) creates a new object using the layers copied from another multiLayerMap object.

map = multiLayerMap(___,Name,Value) specifies property values using name-value pairs.

For example, multiLayerMap(__,'LocalOriginInWorld',[15 20]) sets the local origin to a specific world location.

Properties

expand all

Size of the data in each map layer data array, specified as a cell array of integer vectors. In each vector, the first two dimensions define the footprint of the map layer, and all subsequent dimensions dictate the size and layout of the data stored in each cell.

If the map stores an n-element vector of values in each cell, this property would be [width height n].

If the map stores a 10-by-10 grid with each cell containing a 3-by-3-by-3 matrix array, the data size would be [10 10 3 3 3].

After you create the object, this property is read-only.

Data Types: cell | double

Data type of the values stored in each layer, specified as a cell array of character vectors.

When you create this object, the specified map layers determine each data type. After you create the object, this property is read-only.

Data Types: cell | char

Default value for unspecified map locations for each layer, specified as a cell array of numeric scalars. This default value is returned for areas outside the map as well.

Data Types: cell | double

Location of the bottom-left corner of the grid in world coordinates, specified as a two-element vector, [xWorld yWorld].

You can set this property when you create the object.

Data Types: double

Location of the bottom-left corner of the grid in local coordinates, specified as a two-element vector, [xLocal yLocal].

You can set this property when you create the object.

Data Types: double

This property is read-only.

Number of rows and columns in grid, stored as a 1-by-2 real-valued vector representing the number of rows and columns, in that order.

Data Types: double

Name of each layer, specified as a cell array of string scalars. The order of these names are associated with the order of other properties that are cell arrays.

You can set this property when you create the object. After you create the object, this property is read-only.

Data Types: cell | string

Location of the origin of the local frame in world coordinates, specified as a two-element vector, [xLocal yLocal]. Use the move function to shift the local frame as your vehicle moves.

You can set this property when you create the object.

Data Types: double

This property is read-only.

Number of map layers, stored as a positive integer.

Data Types: double

This property is read-only.

Grid resolution, stored as a scalar in cells per meter representing the number and size of grid locations.

You can set this property when you create the object. After you create the object, this property is read-only.

Data Types: double

This property is read-only.

Minimum and maximum values of x-coordinates in local frame, stored as a two-element horizontal vector of the form [min max]. Local frame is defined by LocalOriginInWorld property.

Data Types: double

This property is read-only.

Minimum and maximum values of y-coordinates in local frame, stored as a two-element horizontal vector of the form [min max]. Local frame is defined by LocalOriginInWorld property.

Data Types: double

This property is read-only.

Minimum and maximum world range values of x-coordinates, stored as a 1-by-2 vector representing the minimum and maximum values, in that order.

Data Types: double

This property is read-only.

Minimum and maximum world range values of y-coordinates, stored as a 1-by-2 vector representing the minimum and maximum values, in that order.

Data Types: double

Object Functions

getLayerReturn individual layers from multilayer map
getMapDataRetrieve data from map layers
grid2localConvert grid indices to local coordinates
grid2worldConvert grid indices to world coordinates
local2gridConvert local coordinates to grid indices
local2worldConvert local coordinates to world coordinates
moveMove map in world frame
setMapDataAssign data to map layers
syncWithSync map with overlapping map
world2gridConvert world coordinates to grid indices
world2localConvert world coordinates to local coordinates

Examples

collapse all

The multiLayerMap object enables you to group multiple map layers and define behavior for those layers when setting and getting data. Using separate map layers, you can store various map data and specify different behaviors for each. You can also define the SetTransformFcn and GetTransformFcn function handles for a map layer so that dependencies are created between layers. This example shows how to store data in a map layer and implement event listeners which update other maps. These maps store how many times the data is updated or accessed.

Dependent Layers

Create two independent map layers.

mapAccessed = mapLayer(zeros(10,10),'LayerName','GetListener');
mapModified = mapLayer(zeros(10,10),'LayerName','SetListener');

Specify function handles for the get and set transform functions used in the main map layer. These functions increment the value of a grid location when you get or set map data in the input map mainMap. See Listener Function Handles for the function implementation.

setHookFcn = @(mainMap,values,varargin)exampleHelperSetHookFcn(mapModified,mainMap,values,varargin{:});
getHookFcn = @(mainMap,values,varargin)exampleHelperGetHookFcn(mapAccessed,mainMap,values,varargin{:});

Create the main map layer with default values of 0.5. Specify the function handles to create the layer depencies.

map = mapLayer(repmat(0.5,10,10),...
                'GetTransformFcn',getHookFcn,...
                'SetTransformFcn',setHookFcn);

Add all maps to the same multiLayerMap object.

mapLayers = multiLayerMap({map,mapAccessed,mapModified});

Set the (0,0) map location with a value of zero using the setMapData object function of map.

setMapData(map,[0 0],0)

Check that mapModified incremented their value.

getMapData(mapModified,[0 0])
ans = 1

Get the data you just set to the main map layer. The expected value of zero is returned.

getMapData(map,[0 0])
ans = 0

Check that mapAccessed incremented their value.

getMapData(mapAccessed,[0 0])
ans = 1

Update the entire map with a matrix of values. Access the data as well.

setMapData(map,rand(10,10))
getMapData(map)
ans = 10×10

    0.6443    0.2077    0.3111    0.5949    0.0855    0.9631    0.0377    0.1068    0.0305    0.1829
    0.3786    0.3012    0.9234    0.2622    0.2625    0.5468    0.8852    0.6538    0.7441    0.2399
    0.8116    0.4709    0.4302    0.6028    0.8010    0.5211    0.9133    0.4942    0.5000    0.8865
    0.5328    0.2305    0.1848    0.7112    0.0292    0.2316    0.7962    0.7791    0.4799    0.0287
    0.3507    0.8443    0.9049    0.2217    0.9289    0.4889    0.0987    0.7150    0.9047    0.4899
    0.9390    0.1948    0.9797    0.1174    0.7303    0.6241    0.2619    0.9037    0.6099    0.1679
    0.8759    0.2259    0.4389    0.2967    0.4886    0.6791    0.3354    0.8909    0.6177    0.9787
    0.5502    0.1707    0.1111    0.3188    0.5785    0.3955    0.6797    0.3342    0.8594    0.7127
    0.6225    0.2277    0.2581    0.4242    0.2373    0.3674    0.1366    0.6987    0.8055    0.5005
    0.5870    0.4357    0.4087    0.5079    0.4588    0.9880    0.7212    0.1978    0.5767    0.4711

Check that mapModified and mapAccessed incremented their values.

getMapData(mapModified)
ans = 10×10

     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     2     1     1     1     1     1     1     1     1     1

getMapData(mapAccessed)
ans = 10×10

     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1     1
     2     1     1     1     1     1     1     1     1     1

The bottom-left location returns two and all other values are one. This confirms the listener functions are working as intended.

Listener Function Handles

These functions implement the get and set example helper functions that update the other map layers.

function valuesOut = exampleHelperSetHookFcn(modifiedMap,sourceLayer,valueIn,varargin)
    % Pass output through
    valuesOut = valueIn;
    
    % If no additional inputs are passed, return immediately.
    if numel(varargin) == 0
        return;
    else
        % Otherwise, increment the value in the modifiedMap.
        if numel(varargin) == 1
            currentValue = getMapData(modifiedMap);
            setMapData(modifiedMap,currentValue+1);
        else        
            currentValue = getMapData(modifiedMap,varargin{1},varargin{3:end});
            % setMapData syntax <<<<>>>>
            setMapData(modifiedMap,varargin{1},currentValue+1,varargin{3:end});
        end
    end
end

function data = exampleHelperGetHookFcn(accessedMap,sourceLayer,valuesIn,varargin)
    
    data = valuesIn;

    % If no additional inputs are passed, check if the values in
    if numel(varargin) == 0
        if isequal(size(valuesIn),sourceLayer.DataSize)
            % Increment the depedent map.
            currentValue = getMapData(accessedMap);
            setMapData(accessedMap,currentValue+1);
        end
    else
        currentValue = getMapData(accessedMap,varargin{:});
        setMapData(accessedMap,varargin{1},currentValue+1,varargin{3:end});
    end
end

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2021a