20 This is a Python3 API for costmap 2d messages from the stack.
22 It provides the basic conversion, get/set,
23 and handling semantics found in the costmap 2d C++ API.
33 Costmap Python3 API for OccupancyGrids to populate from published messages
42 occupancy_map (OccupancyGrid): 2D OccupancyGrid Map
49 self.
size_xsize_x = occupancy_map.info.width
50 self.
size_ysize_y = occupancy_map.info.height
51 self.
resolutionresolution = occupancy_map.info.resolution
52 self.
origin_xorigin_x = occupancy_map.info.origin.position.x
53 self.
origin_yorigin_y = occupancy_map.info.origin.position.y
57 self.
costmapcostmap = np.array(occupancy_map.data, dtype=np.uint8)
60 """Get map width in cells."""
64 """Get map height in cells."""
68 """Get x axis map size in meters."""
72 """Get y axis map size in meters."""
76 """Get the origin x axis of the map [m]."""
80 """Get the origin y axis of the map [m]."""
84 """Get map resolution [m/cell]."""
88 """Get global frame_id."""
92 """Get costmap timestamp."""
97 Get the cost of a cell in the costmap using map coordinate XY.
101 mx (int): map coordinate X to get cost
102 my (int): map coordinate Y to get cost
106 np.uint8: cost of a cell
113 Get the cost of a cell in the costmap using Index.
117 index (int): index of cell to get cost
121 np.uint8: cost of a cell
124 return self.
costmapcostmap[index]
126 def setCost(self, mx: int, my: int, cost: np.uint8) ->
None:
128 Set the cost of a cell in the costmap using map coordinate XY.
132 mx (int): map coordinate X to get cost
133 my (int): map coordinate Y to get cost
134 cost (np.uint8): The cost to set the cell
143 def mapToWorld(self, mx: int, my: int) -> tuple[float, float]:
145 Get the world coordinate XY using map coordinate XY.
149 mx (int): map coordinate X to get world coordinate
150 my (int): map coordinate Y to get world coordinate
154 tuple of float: wx, wy
155 wx (float) [m]: world coordinate X
156 wy (float) [m]: world coordinate Y
165 Get the map coordinate XY using world coordinate XY.
169 wx (float) [m]: world coordinate X to get map coordinate
170 wy (float) [m]: world coordinate Y to get map coordinate
174 (None, None): if coordinates are invalid
175 tuple of int: mx, my (if coordinates are valid)
176 mx (int): map coordinate X
177 my (int): map coordinate Y
190 Get the index of the cell using map coordinate XY.
194 mx (int): map coordinate X to get Index
195 my (int): map coordinate Y to get Index
199 int: The index of the cell
202 return my * self.
size_xsize_x + mx
def getCostmapTimestamp(self)
def getSizeInMetersX(self)
def getSizeInCellsX(self)
tuple[float, float] mapToWorld(self, int mx, int my)
None setCost(self, int mx, int my, np.uint8 cost)
def worldToMapValidated(self, float wx, float wy)
def getGlobalFrameID(self)
int getIndex(self, int mx, int my)
def getSizeInCellsY(self)
def getSizeInMetersY(self)
def __init__(self, occupancy_map)
np.uint8 getCostXY(self, int mx, int my)
np.uint8 getCostIdx(self, int index)