Get occupancy value of locations
returns an array of probability occupancy values at the
occVal = getOccupancy(
locations in the world frame. Values close to 1 represent a high probability
that the cell contains an obstacle. Values close to 0 represent a high
probability that the cell is not occupied and obstacle free. Unknown locations,
including outside the map, return
Create an empty occupancy grid map.
map = occupancyMap(10,10,20);
Input pose of the vehicle, ranges, angles, and the maximum range of the laser scan.
pose = [5,5,0]; ranges = 3*ones(100,1); angles = linspace(-pi/2,pi/2,100); maxrange = 20;
lidarScan object with the specified ranges and angles.
scan = lidarScan(ranges,angles);
Insert the laser scan data into the occupancy map.
Show the map to see the results of inserting the laser scan.
Check the occupancy of the spot directly in front of the vehicle.
ans = 0.7000
Add a second reading and view the update to the occupancy values. The additional reading increases the confidence in the readings. The free and occupied values become more distinct.
ans = 0.8448
Access occupancy values and check their occupancy status based on the occupied and free thresholds of the
Create a matrix and populate it with values. Use this matrix to create an occupancy map.
p = 0.5*ones(20,20); p(11:20,11:20) = 0.75*ones(10,10); map = occupancyMap(p,10);
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])
pocc = 0.7500
occupied = checkOccupancy(map,[1.5 1])
occupied = 1
pocc2 = getOccupancy(map,[5 5],'grid')
pocc2 = 0.5000
occupied2 = checkOccupancy(map,[5 5],'grid')
occupied2 = -1
map— Map representation
Map representation, specified as a
occupancyMap object. This object
represents the environment of the vehicle. The object contains a matrix grid
with values representing the probability of the occupancy of that cell.
Values close to 1 represent a high probability that the cell contains an
obstacle. Values close to 0 represent a high probability that the cell is
not occupied and obstacle free.
xy— World coordinates
World coordinates, specified as an n-by-2 matrix of
y] pairs, where n is the
number of world coordinates.
ij— Grid positions
Grid positions, specified as an n-by-2 matrix of
j] pairs in
cols] format, where n is
the number of grid positions.
bottomLeft— Location of output matrix in world or local
Location of bottom left corner of output matrix in world or local
coordinates, specified as a two-element vector,
yCoord]. Location is in world or local coordinates based on
matSize— Output matrix size
Output matrix size, specified as a two-element vector,
[gridRow gridCol]. Size is in
world, local, or grid coordinates based on syntax.
topLeft— Location of grid
Location of top left corner of grid, specified as a two-element vector,
Occupancy values have a limited resolution of ±0.001. The values are stored as
int16 using a log-odds representation. This data type limits
resolution, but saves memory when storing large maps in MATLAB®. When calling
setOccupancy and then
getOccupancy, the value returned might not equal the value you
set. For more information, see the log-odds representations section in Occupancy Grids.