Main Content

checkOccupancy

Check if locations are free or occupied

Since R2019b

Description

example

occVal = checkOccupancy(map,xy) returns an array of occupancy values at the xy locations in the world frame. Obstacle-free cells return 0, occupied cells return 1. Unknown locations, including outside the map, return -1.

example

occVal = checkOccupancy(map,xy,"local") returns an array of occupancy values at the xy locations in the local frame. The local frame is based on the LocalOriginInWorld property of the map.

example

occVal = checkOccupancy(map,ij,"grid") specifies ij grid cell indices instead of xy locations. Grid indices start at (1,1) from the top left corner.

[occVal,validPts] = checkOccupancy(___) also outputs an n-element vector of logical values indicating whether input coordinates are within the map limits.

occMatrix = checkOccupancy(map) returns a matrix that contains the occupancy status of each location. Obstacle-free cells return 0, occupied cells return 1. Unknown locations, including outside the map, return -1.

occMatrix = checkOccupancy(map,bottomLeft,matSize) returns a matrix of occupancy values by specifying the bottom-left corner location in world coordinates and the matrix size in meters.

occMatrix = checkOccupancy(map,bottomLeft,matSize,"local") returns a matrix of occupancy values by specifying the bottom-left corner location in local coordinates and the matrix size in meters.

occMatrix = checkOccupancy(map,topLeft,matSize,"grid") returns a matrix of occupancy values by specifying the top-left cell index in grid coordinates and the matrix size.

Examples

collapse all

Access occupancy values and check their occupancy status based on the occupied and free thresholds of the occupancyMap object.

Create a matrix and populate it with values. Use this matrix to create an occupancy map.

p = zeros(20,20);
p(11:20,11:20) = ones(10,10);
map = binaryOccupancyMap(p,10);
show(map)

Figure contains an axes object. The axes object with title Binary Occupancy Grid, xlabel X [meters], ylabel Y [meters] contains an object of type image.

Get the occupancy of different locations and check their occupancy statuses. The occupancy status returns 0 for free space and 1 for occupied space. Unknown values return –1.

pocc = getOccupancy(map,[1.5 1]);
occupied = checkOccupancy(map,[1.5 1]);
pocc2 = getOccupancy(map,[5 5],'grid');

Input Arguments

collapse all

Map representation, specified as a binaryOccupancyMap object.

Coordinates in the map, specified as an n-by-2 matrix of [x y] pairs, where n is the number of coordinates. Coordinates can be world or local coordinates depending on the syntax.

Data Types: double

Grid locations in the map, specified as an n-by-2 matrix of [i j] pairs, where n is the number of locations. Grid locations are given as [row col].

Data Types: double

Location of bottom left corner of output matrix in world or local coordinates, specified as a two-element vector, [xCoord yCoord]. Location is in world or local coordinates based on syntax.

Data Types: double

Output matrix size, specified as a two-element vector, [xLength yLength], or [gridRow gridCol]. Size is in world, local, or grid coordinates based on syntax.

Data Types: double

Location of top left corner of grid, specified as a two-element vector, [iCoord jCoord].

Data Types: double

Output Arguments

collapse all

Occupancy values, returned as an n-by-1 column vector equal in length to xy or ij input. Occupancy values can be obstacle free (0), occupied (1), or unknown (-1).

Valid map locations, returned as an n-by-1 column vector equal in length to xy or ij. Locations inside the map return a value of 1. Locations outside the map limits return a value of 0.

Matrix of occupancy values, returned as matrix with size equal to matSize or the size of your map. Occupancy values can be obstacle free (0), occupied (1), or unknown (-1).

Extended Capabilities

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

Version History

Introduced in R2019b