17 This is a Python3 API for costmap 2d messages from the stack.
19 It provides the basic conversion, get/set,
20 and handling semantics found in the costmap 2d C++ API.
32 Occupancy grid Python3 API for OccupancyGrids to populate from published messages
35 def __init__(self, occupancy_map: OccupancyGrid):
41 occupancy_map (OccupancyGrid): 2D OccupancyGrid Map
48 self.
size_xsize_x = occupancy_map.info.width
49 self.
size_ysize_y = occupancy_map.info.height
50 self.
resolutionresolution = occupancy_map.info.resolution
51 self.
origin_xorigin_x = occupancy_map.info.origin.position.x
52 self.
origin_yorigin_y = occupancy_map.info.origin.position.y
56 self.
costmapcostmap = np.array(occupancy_map.data, dtype=np.int8)
59 """Get map width in cells."""
63 """Get map height in cells."""
67 """Get x axis map size in meters."""
71 """Get y axis map size in meters."""
75 """Get the origin x axis of the map [m]."""
79 """Get the origin y axis of the map [m]."""
83 """Get map resolution [m/cell]."""
87 """Get global frame_id."""
91 """Get costmap timestamp."""
96 Get the cost of a cell in the costmap using map coordinate XY.
100 mx (int): map coordinate X to get cost
101 my (int): map coordinate Y to get cost
105 np.int8: cost of a cell
112 Get the cost of a cell in the costmap using Index.
116 index (int): index of cell to get cost
120 np.int8: cost of a cell
123 return np.int8(self.
costmapcostmap[index])
125 def setCost(self, mx: int, my: int, cost: np.int8):
127 Set the cost of a cell in the costmap using map coordinate XY.
131 mx (int): map coordinate X to get cost
132 my (int): map coordinate Y to get cost
133 cost (np.int8): The cost to set the cell
144 Get the world coordinate XY using map coordinate XY.
148 mx (int): map coordinate X to get world coordinate
149 my (int): map coordinate Y to get world coordinate
153 tuple of float: wx, wy
154 wx (float) [m]: world coordinate X
155 wy (float) [m]: world coordinate Y
164 Get the map coordinate XY using world coordinate XY.
168 wx (float) [m]: world coordinate X to get map coordinate
169 wy (float) [m]: world coordinate Y to get map coordinate
173 (None, None): if coordinates are invalid
174 tuple of int: mx, my (if coordinates are valid)
175 mx (int): map coordinate X
176 my (int): map coordinate Y
189 Get the index of the cell using map coordinate XY.
193 mx (int): map coordinate X to get Index
194 my (int): map coordinate Y to get Index
198 int: The index of the cell
201 return my * self.
size_xsize_x + mx
def __init__(self, OccupancyGrid occupancy_map)
def getCostIdx(self, int index)
def getSizeInCellsY(self)
def mapToWorld(self, int mx, int my)
def getSizeInMetersX(self)
def getIndex(self, int mx, int my)
def getSizeInCellsX(self)
def getSizeInMetersY(self)
def worldToMapValidated(self, float wx, float wy)
def setCost(self, int mx, int my, np.int8 cost)
def getCostmapTimestamp(self)
def getCostXY(self, int mx, int my)
def getGlobalFrameID(self)