Skip to content

Commit 92ea63b

Browse files
author
maoyifei
committed
change from agent states to obstacles
1 parent 86078e5 commit 92ea63b

1 file changed

Lines changed: 16 additions & 22 deletions

File tree

GEMstack/onboard/planning/parking_route_planner.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,20 @@ def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose
306306
parking_spot_vertices = []
307307
cone_objects = []
308308
for obstacle in obstacles.values():
309-
if isinstance(obstacle, AgentState):
310-
# Get cone position
309+
if obstacle.material == ObstacleMaterialEnum.TRAFFIC_CONE:
310+
# Get cone position and dimensions
311311
x, y = obstacle.pose.x, obstacle.pose.y
312+
w, h = obstacle.dimensions[0], obstacle.dimensions[1]
313+
314+
# Create a rectangle for the cone's base
315+
half_w = w / 2
316+
half_h = h / 2
317+
cone_vertices = [
318+
(x - half_w, y - half_h), # bottom-left
319+
(x + half_w, y - half_h), # bottom-right
320+
(x + half_w, y + half_h), # top-right
321+
(x - half_w, y + half_h) # top-left
322+
]
312323
parking_spot_vertices.append((x, y))
313324

314325
# Create cone object for collision checking
@@ -322,19 +333,14 @@ def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose
322333
)
323334
cone_object = PhysicalObject(
324335
pose=cone_pose,
325-
dimensions=[0.1, 0.1, 1.0], # Small dimensions for cone
326-
outline=[(-0.05, -0.05), (0.05, -0.05), (0.05, 0.05), (-0.05, 0.05)]
336+
dimensions=[w, h, 1.0], # Use actual cone dimensions
337+
outline=cone_vertices
327338
)
328339
cone_objects.append(cone_object)
329340

330341
# Need exactly 4 cones to form a parking spot
331342
if len(parking_spot_vertices) != 4:
332343
print("Warning: Not exactly 4 cones found for parking spot")
333-
# try:
334-
# with open(self.success_file, 'a') as f:
335-
# f.write("No Four Cones")
336-
# except Exception as e:
337-
# print(f"Error saving parking status: {e}")
338344
return False
339345

340346
# Order the vertices to form a proper polygon
@@ -355,23 +361,11 @@ def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose
355361
for cone_object in cone_objects:
356362
if collisions.polygon_intersects_polygon_2d(vehicle_polygon, cone_object.polygon_parent()):
357363
print("Vehicle collides with a cone")
358-
# try:
359-
# with open(self.success_file, 'a') as f:
360-
# f.write("Collides with Cone")
361-
# except Exception as e:
362-
# print(f"Error saving parking status: {e}")
363364
return False
364365

365366
# Then check if vehicle is contained within parking spot
366367
if not collisions.polygon_contains_polygon_2d(ordered_vertices, vehicle_polygon):
367368
print("Vehicle is not contained within parking spot")
368-
# try:
369-
# with open(self.success_file, 'a') as f:
370-
# f.write(f"\nOrdered Vertices{ordered_vertices}")
371-
# f.write(f"\nVehicle_Polygon{vehicle_polygon}")
372-
# f.write("\nNot Contained with parking spot")
373-
# except Exception as e:
374-
# print(f"Error saving parking status: {e}")
375369
return False
376370

377371
return True
@@ -551,7 +545,7 @@ def update(self, state : AllState) -> Route:
551545
position_error = math.sqrt((final_x - goal_pose.x)**2 + (final_y - goal_pose.y)**2)
552546
orientation_error = math.degrees(abs(normalize_yaw(final_theta - goal_pose.yaw)))
553547

554-
self.parking_success = self.is_successfully_parked(final_state, goal_pose, agents)
548+
self.parking_success = self.is_successfully_parked(final_state, goal_pose, obstacles)
555549
self.final_pos_inside = self.is_final_pose_inside(final_state, agents)
556550
if self.parking_success:
557551
print("Final position is within parking spot!")

0 commit comments

Comments
 (0)