Take only a part of a binaryOccupancyMap
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey, is it possible to take only a part of a binaryOccupancyMap i've already created before?
댓글 수: 0
답변 (1개)
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
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:
- bottomLeft - The bottom-left corner of the rectangular sub-region, in XY world coordinates
- 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
참고 항목
카테고리
Help Center 및 File Exchange에서 Multibody Dynamics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!