Skip to content

Commit 8212d49

Browse files
author
maoyifei
committed
fix constructing vehicle polygon
1 parent 49f3b8e commit 8212d49

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

GEMstack/onboard/planning/parking_route_planner.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,22 @@ def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose
480480
# Get final position from trajectory
481481
x, y, theta, t = final_state
482482

483-
# Create vehicle object at final position
483+
# Calculate the offset from rear to centroid
484+
# The vehicle's length is in the x direction of the vehicle frame
485+
vehicle_length = self.planner.vehicle.to_object().dimensions[0] # Length of vehicle
486+
centroid_offset = vehicle_length / 2.0 # Distance from rear to centroid
487+
488+
# Calculate the centroid position by moving forward from the rear position
489+
# Using basic trigonometry to move in the direction the vehicle is facing
490+
centroid_x = x + centroid_offset * math.cos(theta)
491+
centroid_y = y + centroid_offset * math.sin(theta)
492+
493+
# Create vehicle object at centroid position
484494
final_pose = ObjectPose(
485495
frame=ObjectFrameEnum.ABSOLUTE_CARTESIAN,
486496
t=t,
487-
x=x,
488-
y=y,
497+
x=centroid_x,
498+
y=centroid_y,
489499
z=0.0,
490500
yaw=theta
491501
)
@@ -546,9 +556,6 @@ def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose
546556
parking_spot_vertices[1], # bottom-right
547557
]
548558

549-
# Create a polygon from the ordered vertices
550-
#parking_spot_polygon = shapely.Polygon(ordered_vertices)
551-
552559
# First check if vehicle collides with any cone
553560
for cone_object in cone_objects:
554561
if collisions.polygon_intersects_polygon_2d(vehicle_polygon, cone_object.polygon_parent()):
@@ -557,23 +564,28 @@ def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose
557564
with open(self.success_file, 'a') as f:
558565
f.write("Collides with Cone")
559566
except Exception as e:
560-
print(f"Error saving parking status: {e}")
567+
print(f"Error saving parking status: {e}")
561568
return False
562569

563570
# Then check if vehicle is contained within parking spot
564571
if not collisions.polygon_contains_polygon_2d(ordered_vertices, vehicle_polygon):
565572
print("Vehicle is not contained within parking spot")
566573
try:
567574
with open(self.success_file, 'a') as f:
568-
f.write("Not Contained with praking spot")
575+
f.write("Not Contained with parking spot")
569576
except Exception as e:
570-
print(f"Error saving parking status: {e}")
577+
print(f"Error saving parking status: {e}")
571578
return False
572579

573580
# Finally check if final orientation is close enough to goal orientation
574581
orientation_error = abs(normalize_yaw(theta - goal_pose.yaw))
575582
if orientation_error > self.orientation_threshold:
576583
print("Vehicle orientation is not within threshold")
584+
try:
585+
with open(self.success_file, 'a') as f:
586+
f.write("Orientation not within threshold")
587+
except Exception as e:
588+
print(f"Error saving parking status: {e}")
577589
return False
578590

579591
return True
@@ -679,7 +691,7 @@ def update(self, state : AllState) -> Route:
679691
try:
680692
with open(self.success_file, 'a') as f:
681693
f.write("Final State")
682-
f.write(final_state)
694+
f.write(str(final_state))
683695
f.write("Final State End")
684696
print(f"Parking status saved to {self.success_file}")
685697
except Exception as e:

0 commit comments

Comments
 (0)