Take only a part of a binaryOccupancyMap

2 ビュー (過去 30 日間)
simone esposito
simone esposito 2021 年 4 月 18 日
コメント済み: simone esposito 2021 年 4 月 19 日
Hey, is it possible to take only a part of a binaryOccupancyMap i've already created before?

回答 (1 件)

Cameron Stabile
Cameron Stabile 2021 年 4 月 19 日
Hi Simone,
If you are using R2019b or newer you should be able to create submaps using the block syntax of getOccupancy:
% Create your original map
load exampleMaps
originalMap = binaryOccupancyMap(simpleMap);
% Extract the bottom-left quadrant of original map
botLeft = originalMap.GridLocationInWorld;
qSize = ceil([diff(originalMap.XWorldLimits) diff(originalMap.YWorldLimits)]/2);
mapData = getOccupancy(originalMap, botLeft, qSize);
% Construct your new occupancyMap
subMap = binaryOccupancyMap(mapData);
show(originalMap);
figure;
show(subMap);
Hope this helps,
Cameron
  5 件のコメント
Cameron Stabile
Cameron Stabile 2021 年 4 月 19 日
編集済み: Cameron Stabile 2021 年 4 月 19 日
No problem Simone, thanks for the clarification.
Rather than skipping straight to the workflow, let's first outline the purpose of block syntax. As shown in the doc, the syntax used requires the following:
occMatrix = getOccupancy(map,bottomLeft,matSize)
This syntax returns a matrix of occupancy values corresponding to a rectangular region defined by two inputs:
  1. bottomLeft - The bottom-left corner of the rectangular sub-region, in XY world coordinates
  2. matSize - The size of the rectangle, in [width, height]
Moving on to your question - maps are always rectangular themselves, so you can't quite get a 3-quadrant map. That said, we can try to assemble a map which contains information from the quadrants that interest you and assign occupied values to the other regions.
Using what we know from the syntax described above, we can populate the new map in several ways:
1) Copy the original map directly and overwrite the quadrant we don't want with some default value:
% Create your original map
load exampleMaps
originalMap = binaryOccupancyMap(simpleMap);
% Create copy
newMap = copy(originalMap);
% Overwrite one quadrant that we don't care about (let's assume we
% don't care about the top-left quadrant this time)
% Calculate the approximate size of a quadrant
qSize = ceil([diff(originalMap.XWorldLimits) diff(originalMap.YWorldLimits)]/2);
% Define bottom-left corner as the bottom-left corner of the top-left
% quadrant.
botLeft = newMap.GridLocationInWorld + [0 qSize(2)];
% Overwrite the quadrant with a matrix of "occupied" values.
setOccupancy(newMap, botLeft, repmat(1,qSize));
show(originalMap);
figure;
show(newMap);
2) Alternatively, we can construct a map object from scratch, extracting and overwriting regions as needed:
% Create your original map
load exampleMaps
originalMap = binaryOccupancyMap(simpleMap);
show(originalMap);
% Create an occupied map of the same size.
newMap = binaryOccupancyMap(repmat(1,originalMap.GridSize));
figure;
show(newMap);
% Copy over the top "half" of the map.
width = diff(originalMap.XWorldLimits);
height = diff(originalMap.YWorldLimits);
topSize = ceil([width height/2]);
botLeft_Top = newMap.GridLocationInWorld + [0 topSize(2)];
mapData = getOccupancy(originalMap,botLeft_Top,topSize);
setOccupancy(newMap,botLeft_Top,mapData);
figure;
show(newMap);
% Copy over the bottom-right quadrant
quadSize = ceil([width/2 height/2]);
botLeft_Quad = newMap.GridLocationInWorld + [quadSize(1) 0];
mapData = getOccupancy(originalMap,botLeft_Quad,quadSize);
setOccupancy(newMap,botLeft_Quad,mapData);
figure;
show(newMap);
Keep in mind that the map in this example is 27x26 cells in size, so it's up to you to decide how rounding and partial regions should be handled. You can learn more about the map API in our documentation. Some syntaxes may be easier to use in different situations, such as using "local" or "grid" coordinates to define your rectangular regions, but the examples above should hopefully get you started.
Best,
Cameron
simone esposito
simone esposito 2021 年 4 月 19 日
Thank you very much for helping me, now it's more clear!!!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMultibody Dynamics についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by