occupancy_grid.py
Go to the documentation of this file.
1 import sys
2 
3 from .registry import converts_from_numpy, converts_to_numpy
4 from nav_msgs.msg import OccupancyGrid, MapMetaData
5 
6 import numpy as np
7 from numpy.lib.stride_tricks import as_strided
8 
9 @converts_to_numpy(OccupancyGrid)
11  data = np.asarray(msg.data, dtype=np.int8).reshape(msg.info.height, msg.info.width)
12 
13  return np.ma.array(data, mask=data==-1, fill_value=-1)
14 
15 
16 @converts_from_numpy(OccupancyGrid)
17 def numpy_to_occupancy_grid(arr, info=None):
18  if not len(arr.shape) == 2:
19  raise TypeError('Array must be 2D')
20  if not arr.dtype == np.int8:
21  raise TypeError('Array must be of int8s')
22 
23  grid = OccupancyGrid()
24  if isinstance(arr, np.ma.MaskedArray):
25  # We assume that the masked value are already -1, for speed
26  arr = arr.data
27  grid.data = arr.ravel()
28  grid.info = info or MapMetaData()
29  grid.info.height = arr.shape[0]
30  grid.info.width = arr.shape[1]
31 
32  return grid
def converts_from_numpy(msgtype, plural=False)
Definition: registry.py:17
def converts_to_numpy(msgtype, plural=False)
Definition: registry.py:9
def numpy_to_occupancy_grid(arr, info=None)


ros_numpy
Author(s): Eric Wieser
autogenerated on Sat Oct 3 2020 03:25:57