Main Content

checkOccupancy

Check if locations are free or occupied

Since R2019b

Description

example

occStatus = checkOccupancy(map,xy) returns an array of occupancy statuses 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

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

example

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

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

occStatusMatrix = 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.

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

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

occStatusMatrix = checkOccupancy(map,topLeft,matSize,"grid") returns a matrix of occupancy statuses 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)

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.

xy are world coordinates by default. If you specify "local", then xy are local coordinates. For example, checkOccupancy(map,[x1 y1],"local") checks the occupancy status at the specified xy local coordinates.

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].

bottomLeft is a world coordinate by default. If you specify "local", then bottomLeft is a local coordinate.

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 status, returned as an n-by-1 column vector. n is equal to the length of the xy or ij input. Occupancy status 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 status, returned as matrix with a size corresponding 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

See Also

| | (Navigation Toolbox)