19 This is a Python3 API for costmap 2d messages from the stack.
21 It provides the basic conversion, get/set,
22 and handling semantics found in the costmap 2d C++ API.
32 Costmap Python3 API for OccupancyGrids to populate from published messages
41 occupancy_map (OccupancyGrid): 2D OccupancyGrid Map
44 self.
size_xsize_x = occupancy_map.info.width
45 self.
size_ysize_y = occupancy_map.info.height
46 self.
resolutionresolution = occupancy_map.info.resolution
47 self.
origin_xorigin_x = occupancy_map.info.origin.position.x
48 self.
origin_yorigin_y = occupancy_map.info.origin.position.y
52 self.
costmapcostmap = np.array(occupancy_map.data, dtype=np.uint8)
55 """Get map width in cells."""
59 """Get map height in cells."""
63 """Get x axis map size in meters."""
67 """Get y axis map size in meters."""
71 """Get the origin x axis of the map [m]."""
75 """Get the origin y axis of the map [m]."""
79 """Get map resolution [m/cell]."""
83 """Get global frame_id."""
87 """Get costmap timestamp."""
92 Get the cost of a cell in the costmap using map coordinate XY.
96 mx (int): map coordinate X to get cost
97 my (int): map coordinate Y to get cost
101 np.uint8: cost of a cell
108 Get the cost of a cell in the costmap using Index.
112 index (int): index of cell to get cost
116 np.uint8: cost of a cell
119 return self.
costmapcostmap[index]
121 def setCost(self, mx: int, my: int, cost: np.uint8) ->
None:
123 Set the cost of a cell in the costmap using map coordinate XY.
127 mx (int): map coordinate X to get cost
128 my (int): map coordinate Y to get cost
129 cost (np.uint8): The cost to set the cell
138 def mapToWorld(self, mx: int, my: int) -> tuple[float, float]:
140 Get the world coordinate XY using map coordinate XY.
144 mx (int): map coordinate X to get world coordinate
145 my (int): map coordinate Y to get world coordinate
149 tuple of float: wx, wy
150 wx (float) [m]: world coordinate X
151 wy (float) [m]: world coordinate Y
158 def worldToMap(self, wx: float, wy: float) -> tuple[int, int]:
160 Get the map coordinate XY using world coordinate XY.
164 wx (float) [m]: world coordinate X to get map coordinate
165 wy (float) [m]: world coordinate Y to get map coordinate
170 mx (int): map coordinate X
171 my (int): map coordinate Y
180 Get the index of the cell using map coordinate XY.
184 mx (int): map coordinate X to get Index
185 my (int): map coordinate Y to get Index
189 int: The index of the cell
192 return my * self.
size_xsize_x + mx
def getCostmapTimestamp(self)
def getSizeInMetersX(self)
def getSizeInCellsX(self)
tuple[int, int] worldToMap(self, float wx, float wy)
tuple[float, float] mapToWorld(self, int mx, int my)
None setCost(self, int mx, int my, np.uint8 cost)
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)