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.
35 Costmap Python3 API for Costmaps to populate from published messages
44 occupancy_map (Costmap): 2D OccupancyGrid Map
51 self.
size_xsize_x = occupancy_map.metadata.size_x
52 self.
size_ysize_y = occupancy_map.metadata.size_y
53 self.
resolutionresolution = occupancy_map.metadata.resolution
54 self.
origin_xorigin_x = occupancy_map.metadata.origin.position.x
55 self.
origin_yorigin_y = occupancy_map.metadata.origin.position.y
58 self.
costmapcostmap = np.array(occupancy_map.data, dtype=np.uint8)
61 """Get map width in cells."""
65 """Get map height in cells."""
69 """Get x axis map size in meters."""
73 """Get y axis map size in meters."""
77 """Get the origin x axis of the map [m]."""
81 """Get the origin y axis of the map [m]."""
85 """Get map resolution [m/cell]."""
89 """Get global frame_id."""
93 """Get costmap timestamp."""
98 Get the cost of a cell in the costmap using map coordinate XY.
102 mx (int): map coordinate X to get cost
103 my (int): map coordinate Y to get cost
107 np.uint8: cost of a cell
114 Get the cost of a cell in the costmap using Index.
118 index (int): index of cell to get cost
122 np.uint8: cost of a cell
125 return np.uint8(self.
costmapcostmap[index])
127 def setCost(self, mx: int, my: int, cost: np.uint8):
129 Set the cost of a cell in the costmap using map coordinate XY.
133 mx (int): map coordinate X to get cost
134 my (int): map coordinate Y to get cost
135 cost (np.uint8): The cost to set the cell
146 Get the world coordinate XY using map coordinate XY.
150 mx (int): map coordinate X to get world coordinate
151 my (int): map coordinate Y to get world coordinate
155 tuple of float: wx, wy
156 wx (float) [m]: world coordinate X
157 wy (float) [m]: world coordinate Y
166 Get the map coordinate XY using world coordinate XY.
170 wx (float) [m]: world coordinate X to get map coordinate
171 wy (float) [m]: world coordinate Y to get map coordinate
175 (None, None): if coordinates are invalid
176 tuple of int: mx, my (if coordinates are valid)
177 mx (int): map coordinate X
178 my (int): map coordinate Y
191 Get the index of the cell using map coordinate XY.
195 mx (int): map coordinate X to get Index
196 my (int): map coordinate Y to get Index
200 int: The index of the cell
203 return my * self.
size_xsize_x + mx
def getIndex(self, int mx, int my)
def getCostmapTimestamp(self)
def getSizeInMetersX(self)
def getSizeInCellsX(self)
def setCost(self, int mx, int my, np.uint8 cost)
def getCostXY(self, int mx, int my)
def worldToMapValidated(self, float wx, float wy)
def getGlobalFrameID(self)
def getCostIdx(self, int index)
def getSizeInCellsY(self)
def getSizeInMetersY(self)
def mapToWorld(self, int mx, int my)
def __init__(self, Costmap occupancy_map)