MATLAB Examples

# Inflate Obstacles in a Binary Occupancy Grid

This example shows how to create the map, set the obstacle locations and inflate it by a radius of 1m. Extra plots on the figure help illustrate the inflation and shifting due to conversion to grid locations.

Create binary occupancy grid. Set occupancy of position [5,5].

```map = robotics.BinaryOccupancyGrid(10,10,5); setOccupancy(map,[5 5], 1); ```

Inflate occupied spaces on map by 1m.

```inflate(map,1); show(map) ```

Plot original location, converted grid position and draw the original circle. You can see from this plot, that the grid center is [4.9 4.9], which is shifted from the [5 5] lcoation. A 1m circle is drawn from there and notice that any cells that touch this circle are marked as occupied. Figure is zoomed in to relevant area.

```hold on theta = linspace(0,2*pi); x = 4.9+cos(theta); % x circle coordinates y = 4.9+sin(theta); % y circle coordinates plot(5,5,'*b','MarkerSize',10) % Original location plot(4.9,4.9,'xr','MarkerSize',10) % Grid location center plot(x,y,'-r','LineWidth',2); % Circle of radius 1m. axis([3.6 6 3.6 6]) ax = gca; ax.XTick = [3.6:0.2:6]; ax.YTick = [3.6:0.2:6]; grid on legend('Original Location','Grid Center','Inflation') ```

As you can see from the above figure, even cells that barely overlap with the inflation radius are labeled as occupied.