Move map in world frame
This example shows how to move a local egocentric map and sync it with a larger world map. This process emulates a vehicle driving in an environment and getting updates on obstacles in the new areas.
Load example maps. Create an occupancy map from the
load exampleMaps.mat map = occupancyMap(ternaryMap); show(map)
Create a smaller local map.
mapLocal = occupancyMap(ternaryMap(end-200:end,1:200)); show(mapLocal)
Follow a path planned in the world map and update the local map as you move your local frame.
Specify path locations and plot on the map.
path = [100 100 100 250 200 250 300 250]; show(map) hold on plot(path(:,1),path(:,2)) hold off
Create a loop for moving between points by the map resolution. Divide the difference between points by the map resolution to see how many incremental moves you can make.
for i = 1:length(path)-1 moveAmount = (path(i+1,:)-path(i,:))/map.Resolution; for j = 1:abs(moveAmount(1)+moveAmount(2)) moveValue = sign(moveAmount).*map.Resolution; move(mapLocal,moveValue, ... "MoveType","relative","SyncWith",map) show(mapLocal) drawnow limitrate end end
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.
moveValue— Local map origin move value
Local map origin move value, specified as an
vector. By default, the value is an absolute location to move the local
origin to in the world frame. Use the
MoveType name-value pair to specify a relative move.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'MoveType'— Type of move
Type of move, specified as
'relative'. For relative moves, specify a
[x y] vector for
moveValue based on your current local
'FillValue'— Fill value for revealed locations
Fill value for revealed locations because of the shifted map limits,
'SyncWith'— Secondary map to sync with
Secondary map to sync with, specified as a
occupancyMap object. Any
revealed locations based on the move are updated with values in this map
using the world coordinates.