18 This is a Python3 API for a Footprint Collision Checker.
20 It provides the needed methods to manipulate the coordinates
21 and calculate the cost of a Footprint
24 from math
import cos, sin
32 INSCRIBED_INFLATED_OBSTACLE = 253
33 MAX_NON_OBSTACLE = 252
39 FootprintCollisionChecker.
41 FootprintCollisionChecker Class for getting the cost
42 and checking the collisions of a Footprint
46 """Initialize the FootprintCollisionChecker Object."""
52 Iterate over all the points in a footprint and check for collision.
56 footprint (Polygon): The footprint to calculate the collision cost for
60 LETHAL_OBSTACLE (int): If collision was found, 254 will be returned
61 footprint_cost (float): The maximum cost found in the footprint points
68 x0, y0 = self.
worldToMapValidatedworldToMapValidated(footprint.points[0].x, footprint.points[0].y)
70 if x0
is None or y0
is None:
71 return LETHAL_OBSTACLE
76 for i
in range(len(footprint.points) - 1):
78 footprint.points[i + 1].x, footprint.points[i + 1].y
81 if x1
is None or y1
is None:
82 return LETHAL_OBSTACLE
84 footprint_cost = max(float(self.
lineCostlineCost(x0, x1, y0, y1)), footprint_cost)
88 if footprint_cost == LETHAL_OBSTACLE:
91 return max(float(self.
lineCostlineCost(xstart, x1, ystart, y1)), footprint_cost)
94 y0: float, y1: float, step_size: float = 0.5):
96 Iterate over all the points along a line and check for collision.
100 x0 (float): Abscissa of the initial point in map coordinates
101 y0 (float): Ordinate of the initial point in map coordinates
102 x1 (float): Abscissa of the final point in map coordinates
103 y1 (float): Ordinate of the final point in map coordinates
104 step_size (float): Optional, Increments' resolution, defaults to 0.5
108 LETHAL_OBSTACLE (int): If collision was found, 254 will be returned
109 line_cost (float): The maximum cost found in the line points
116 while line_iterator.isValid():
117 point_cost = float(self.
pointCostpointCost(
118 int(line_iterator.getX()), int(line_iterator.getY())
121 if point_cost == LETHAL_OBSTACLE:
124 if line_cost < point_cost:
125 line_cost = point_cost
127 line_iterator.advance()
133 Get the map coordinate XY using world coordinate XY.
137 wx (float): world coordinate X
138 wy (float): world coordinate Y
142 None: if coordinates are invalid
143 tuple of int: mx, my (if coordinates are valid)
144 mx (int): map coordinate X
145 my (int): map coordinate Y
150 'Costmap not specified, use setCostmap to specify the costmap first'
156 Get the cost of a point in the costmap using map coordinates XY.
160 mx (int): map coordinate X
161 my (int): map coordinate Y
165 np.uint8: cost of a point
170 'Costmap not specified, use setCostmap to specify the costmap first'
172 return self.
costmap_costmap_.getCostXY(x, y)
176 Specify which costmap to use.
180 costmap (PyCostmap2D): costmap to use in the object's methods
191 theta: float, footprint: Polygon):
193 Get the cost of a footprint at a specific Pose in map coordinates.
197 x (float): map coordinate X
198 y (float): map coordinate Y
199 theta (float): absolute rotation angle of the footprint
200 footprint (Polygon): the footprint to calculate its cost at the given Pose
204 LETHAL_OBSTACLE (int): If collision was found, 254 will be returned
205 footprint_cost (float): The maximum cost found in the footprint points
210 oriented_footprint = Polygon()
212 for i
in range(len(footprint.points)):
215 footprint.points[i].x * cos_th - footprint.points[i].y * sin_th
218 footprint.points[i].x * sin_th + footprint.points[i].y * cos_th
220 oriented_footprint.points.append(new_pt)