Map classes
Occupancy grid classes
Binary Occupancy grid
- class roboticstoolbox.mobile.BinaryOccupancyGrid(grid=None, **kwargs)[source]
Bases:
BaseOccupancyGrid
- __init__(grid=None, **kwargs)[source]
Create a binary occupancy grid instance
- Parameters:
grid (ndarray(N,M)) – occupancy grid as a NumPy array
size (float, optional) – cell size, defaults to 1
origin (array_like(2), optional) – world coordinates of the grid element [0,0], defaults to (0, 0)
kwargs – options passed to
BaseMap
The array is kept internally as a bool array. Cells are set to True (occupied) corresponding to input values > 0.
This object supports a user-defined coordinate system and grid size. World coordinates are converted to grid coordinates to lookup the occupancy status.
Example:
>>> from roboticstoolbox import BinaryOccupancyGrid >>> import numpy as np >>> og = BinaryOccupancyGrid(np.zeros((5,5))) >>> print(og) BinaryOccupancyGrid: 5 x 5, cell size=1, x = [0.0, 4.0], y = [0.0, 4.0], 0.0% occupied >>> og = BinaryOccupancyGrid(workspace=[-5,5], cellsize=0.1, value=0) >>> print(og) BinaryOccupancyGrid: 101 x 101, cell size=0.1, x = [-5.0, 5.0], y = [-5.0, 5.0], 0.0% occupied
- Seealso:
- isoccupied(p)[source]
Test if coordinate is occupied
- Parameters:
p (array_like(2)) – world coordinate (x, y)
- Returns:
occupancy status of corresponding grid cell
- Return type:
The grid cell size and offset are used to convert
p
to an occupancy grid coordinate. The grid coordinate is rounded and cast to integer value. If the coordinate is outside the bounds of the occupancy grid it is considered to be occupied.- Seealso:
- inflate(radius)[source]
Inflate obstales
- Parameters:
radius (float) – radius of circular structuring element in world units
A circular structuring element is created and used to dilate the stored occupancy grid.
Successive calls to
inflate
will compound the inflation.- Seealso:
- copy()
Copy an occupancy grid (superclass)
- Returns:
copy of the ocupancy grid
- Return type:
OccGrid
- g2w(p)
Convert grid coordinate to world coordinate (superclass)
- Parameters:
p (array_like(2)) – grid coordinate (column, row)
- Returns:
world coordinate (x, y)
- Return type:
ndarray(2)
The grid cell size and offset are used to convert occupancy grid coordinate
p
to a world coordinate.
- property grid
Occupancy grid as a NumPy array (superclass)
- Returns:
binary occupancy grid
- Return type:
ndarray(N,M) of bool
If
inflate()
has been called, this will return the inflated occupancy grid.
- line_w(p1, p2)
Get index of cells along a line segment (superclass)
- Parameters:
p1 (array_like(2)) – start
p2 (array_like(2)) – end
- Returns:
index into grid
- Return type:
ndarray(N)
Get the indices of cells along a line segment defined by the end points given in world coordinates.
The returned indices can be applied to a raveled view of the grid.
- property maxdim
Maximum dimension of grid in world coordinates (superclass)
- Returns:
maximum side length of the occupancy grid
- Return type:
- property name
Occupancy grid name (superclass)
- Returns:
name of the occupancy grid
- Return type:
- plot(map=None, ax=None, block=None, **kwargs)
Plot the occupancy grid (superclass)
- Parameters:
map (ndarray(N,M), optional) – array which is plotted instead of the grid, must be same size as the occupancy grid,defaults to None
ax (Axes2D, optional) – matplotlib axes to plot into, defaults to None
block (bool, optional) – block until plot is dismissed, defaults to None
kwargs – arguments passed to
imshow
The grid is plotted as an image but with axes in world coordinates.
The grid is a NumPy boolean array which has values 0 (false=unoccupied) and 1 (true=occupied). Passing a
cmap
option to imshow can be used to control the displayed color of free space and obstacles.
- property ravel
Ravel the grid (superclass)
- Returns:
1D view of the occupancy grid
- Return type:
ndarray(N)
- set(region, value)
Set region of map (superclass)
- property shape
Shape of the occupancy grid array (superclass)
- Returns:
shape of the occupancy grid array
- Return type:
2-tuple
This is the shape of the NumPy array that holds the occupancy grid.
- w2g(p)
Convert world coordinate to grid coordinate (superclass)
- Parameters:
p (array_like(2)) – world coordinate (x, y)
- Returns:
grid coordinate (column, row)
- Return type:
ndarray(2)
The grid cell size and offset are used to convert
p
to an occupancy grid coordinate. The grid coordinate is rounded and cast to integer value. No check is made on the validity of the coordinate.
- property workspace
Bounds of the occupancy grid in world coordinates (superclass)
- Returns:
workspace bounds [xmin, xmax, ymin, ymax]
- Return type:
ndarray(4)
Returns the bounds of the occupancy grid in world coordinates.
- property xmax
Maximum x-coordinate of this grid (superclass)
- Returns:
maximum world x-coordinate
- Return type:
- property xmin
Minimum x-coordinate of this grid (superclass)
- Returns:
minimum world x-coordinate
- Return type:
- property ymax
Maximum y-coordinate of this grid (superclass)
- Returns:
maximum world y-coordinate
- Return type:
Occupancy grid
- class roboticstoolbox.mobile.OccupancyGrid(grid=None, origin=(0, 0), value=0, cellsize=1, **kwargs)[source]
Bases:
BaseOccupancyGrid
General occupancy grid
The elements of the array are floats and can represent occupancy probability or traversal cost.
Example:
>>> from roboticstoolbox import OccupancyGrid >>> import numpy as np >>> og = OccupancyGrid(np.zeros((5,5))) >>> print(og) OccupancyGrid: 5 x 5, cell size=1, x = [0.0, 4.0], y = [0.0, 4.0], dtype float64, min 0.0, max 0.0, mean 0.0 >>> og = OccupancyGrid(workspace=[-5,5], cellsize=0.1, value=0.5) >>> print(og) OccupancyGrid: 101 x 101, cell size=0.1, x = [-5.0, 5.0], y = [-5.0, 5.0], dtype float64, min 0.5, max 0.5, mean 0.5
- Seealso:
- __init__(grid=None, origin=(0, 0), value=0, cellsize=1, **kwargs)
Occupancy grid (superclass)
- Parameters:
This object supports a user-defined coordinate system and grid size. World coordinates are converted to grid coordinates to lookup the occupancy status.
The grid can be initialized by:
a 2D NumPy array
specifying
workspace
andvalue
arguments
- copy()
Copy an occupancy grid (superclass)
- Returns:
copy of the ocupancy grid
- Return type:
OccGrid
- g2w(p)
Convert grid coordinate to world coordinate (superclass)
- Parameters:
p (array_like(2)) – grid coordinate (column, row)
- Returns:
world coordinate (x, y)
- Return type:
ndarray(2)
The grid cell size and offset are used to convert occupancy grid coordinate
p
to a world coordinate.
- property grid
Occupancy grid as a NumPy array (superclass)
- Returns:
binary occupancy grid
- Return type:
ndarray(N,M) of bool
If
inflate()
has been called, this will return the inflated occupancy grid.
- line_w(p1, p2)
Get index of cells along a line segment (superclass)
- Parameters:
p1 (array_like(2)) – start
p2 (array_like(2)) – end
- Returns:
index into grid
- Return type:
ndarray(N)
Get the indices of cells along a line segment defined by the end points given in world coordinates.
The returned indices can be applied to a raveled view of the grid.
- property maxdim
Maximum dimension of grid in world coordinates (superclass)
- Returns:
maximum side length of the occupancy grid
- Return type:
- property name
Occupancy grid name (superclass)
- Returns:
name of the occupancy grid
- Return type:
- plot(map=None, ax=None, block=None, **kwargs)
Plot the occupancy grid (superclass)
- Parameters:
map (ndarray(N,M), optional) – array which is plotted instead of the grid, must be same size as the occupancy grid,defaults to None
ax (Axes2D, optional) – matplotlib axes to plot into, defaults to None
block (bool, optional) – block until plot is dismissed, defaults to None
kwargs – arguments passed to
imshow
The grid is plotted as an image but with axes in world coordinates.
The grid is a NumPy boolean array which has values 0 (false=unoccupied) and 1 (true=occupied). Passing a
cmap
option to imshow can be used to control the displayed color of free space and obstacles.
- property ravel
Ravel the grid (superclass)
- Returns:
1D view of the occupancy grid
- Return type:
ndarray(N)
- set(region, value)
Set region of map (superclass)
- property shape
Shape of the occupancy grid array (superclass)
- Returns:
shape of the occupancy grid array
- Return type:
2-tuple
This is the shape of the NumPy array that holds the occupancy grid.
- w2g(p)
Convert world coordinate to grid coordinate (superclass)
- Parameters:
p (array_like(2)) – world coordinate (x, y)
- Returns:
grid coordinate (column, row)
- Return type:
ndarray(2)
The grid cell size and offset are used to convert
p
to an occupancy grid coordinate. The grid coordinate is rounded and cast to integer value. No check is made on the validity of the coordinate.
- property workspace
Bounds of the occupancy grid in world coordinates (superclass)
- Returns:
workspace bounds [xmin, xmax, ymin, ymax]
- Return type:
ndarray(4)
Returns the bounds of the occupancy grid in world coordinates.
- property xmax
Maximum x-coordinate of this grid (superclass)
- Returns:
maximum world x-coordinate
- Return type:
- property xmin
Minimum x-coordinate of this grid (superclass)
- Returns:
minimum world x-coordinate
- Return type:
- property ymax
Maximum y-coordinate of this grid (superclass)
- Returns:
maximum world y-coordinate
- Return type:
Polygon map
- class roboticstoolbox.mobile.PolygonMap(workspace=None, polygons=[])[source]
Bases:
BaseMap
- __init__(workspace=None, polygons=[])[source]
Polygonal obstacle map
- Parameters:
The obstacle polygons are specified as instances of
Polygon2
or ndarray(2,N).The workspace can be specified in several ways:
workspace
x-range
y-range
A (scalar)
-A:A
-A:A
[A, B]
A:B
A:B
[A, B, C, D]
A:B
C:D
Workspace is used only to set plot bounds.
- add(polygon)[source]
Add a polygon to map
- Parameters:
polygon (
Polygon2
or ndarray(2,N)) – a polygon
- iscollision(polygon)[source]
Test for collision
- Parameters:
polygon (
Polygon2
or ndarray(2,N)) – a polygon- Returns:
collision
- Return type:
The
polygon
is tested against polygons in the map, and returns True on the first collision.- Seealso:
add()
Polygon2
- isoccupied(p)[source]
Test if point lies inside an obstacle
- Parameters:
p (array_like(2)) – a 2D point
- Returns:
enclosure
- Return type:
The point is tested for enclosure by polygons in the map, and returns True on the first enclosure.
- property workspace
Bounds of the occupancy grid
- Returns:
workspace bounds [xmin, xmax, ymin, ymax]
- Return type:
ndarray(4)
Returns the bounds of the occupancy grid.