Skip to content

Commit bf9396c

Browse files
author
maoyifei
committed
change where success function is being called
1 parent 27e64c7 commit bf9396c

1 file changed

Lines changed: 51 additions & 41 deletions

File tree

GEMstack/onboard/planning/parking_route_planner.py

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -459,30 +459,40 @@ def save_parking_message(self, success: bool):
459459
try:
460460
with open(self.success_file, 'a') as f:
461461
f.write(message)
462+
f.write(success)
463+
f.write("End")
462464
print(f"Parking status saved to {self.success_file}")
463465
except Exception as e:
464466
print(f"Error saving parking status: {e}")
465467

466-
def is_successfully_parked(self, vehicle_state: VehicleState, goal_pose: ObjectPose, obstacles: Dict[str, Obstacle]) -> bool:
467-
"""Check if the vehicle is successfully parked in the parking spot.
468+
def is_successfully_parked(self, final_state: List[float], goal_pose: ObjectPose, obstacles: Dict[str, Obstacle]) -> bool:
469+
"""Check if the final position in the trajectory is within the parking spot.
468470
469471
Args:
470-
vehicle_state (VehicleState): Current state of the vehicle
472+
final_state (List[float]): Final state from trajectory (x, y, theta, t)
471473
goal_pose (ObjectPose): Goal parking pose
472474
obstacles (Dict[str, Obstacle]): Dictionary of obstacles including parking cones
473475
474476
Returns:
475-
bool: True if vehicle is successfully parked, False otherwise
477+
bool: True if final position is within parking spot, False otherwise
476478
"""
477-
# Check if vehicle is stopped
478-
if abs(vehicle_state.v) > self.velocity_threshold:
479-
return False
480-
481-
# Get vehicle polygon
479+
# Get final position from trajectory
480+
x, y, theta, t = final_state
481+
482+
# Create vehicle object at final position
483+
final_pose = ObjectPose(
484+
frame=ObjectFrameEnum.ABSOLUTE_CARTESIAN,
485+
t=t,
486+
x=x,
487+
y=y,
488+
z=0.0,
489+
yaw=theta
490+
)
491+
482492
vehicle_object = PhysicalObject(
483-
pose=vehicle_state.pose,
484-
dimensions=vehicle_state.dimensions,
485-
outline=vehicle_state.outline
493+
pose=final_pose,
494+
dimensions=self.planner.vehicle.to_object().dimensions,
495+
outline=self.planner.vehicle.to_object().outline
486496
)
487497
vehicle_polygon = vehicle_object.polygon_parent()
488498

@@ -496,16 +506,10 @@ def is_successfully_parked(self, vehicle_state: VehicleState, goal_pose: ObjectP
496506

497507
# Need exactly 4 cones to form a parking spot
498508
if len(parking_spot_vertices) != 4:
499-
try:
500-
with open(self.success_file, 'a') as f:
501-
f.write("not enough cones")
502-
except Exception as e:
503-
print(f"Error saving parking status: {e}")
504509
print("Warning: Not exactly 4 cones found for parking spot")
505510
return False
506511

507512
# Create a polygon from the parking spot vertices
508-
# We'll use the collision detection utilities to check if the vehicle is inside
509513
parking_spot_object = PhysicalObject(
510514
pose=ObjectPose(frame=ObjectFrameEnum.ABSOLUTE_CARTESIAN, t=0.0, x=0.0, y=0.0, z=0.0, yaw=0.0),
511515
dimensions=[max(abs(x) for x, _ in parking_spot_vertices) * 2,
@@ -515,21 +519,14 @@ def is_successfully_parked(self, vehicle_state: VehicleState, goal_pose: ObjectP
515519
)
516520
parking_spot_polygon = parking_spot_object.polygon_parent()
517521

518-
# Check if vehicle is inside parking spot
519-
# We'll consider the vehicle parked if its polygon is completely inside the parking spot
520-
# and not intersecting with any of the cone obstacles
522+
# Check if final position is inside parking spot
521523
if not collisions.polygon_contains_polygon_2d(parking_spot_polygon, vehicle_polygon):
522-
try:
523-
with open(self.success_file, 'a') as f:
524-
f.write("collision detected")
525-
except Exception as e:
526-
print(f"Error saving parking status: {e}")
527524
return False
528525

529-
# # Check if vehicle orientation is close enough to goal orientation
530-
# orientation_error = abs(normalize_yaw(vehicle_state.pose.yaw - goal_pose.yaw))
531-
# if orientation_error > self.orientation_threshold:
532-
# return False
526+
# Check if final orientation is close enough to goal orientation
527+
orientation_error = abs(normalize_yaw(theta - goal_pose.yaw))
528+
if orientation_error > self.orientation_threshold:
529+
return False
533530

534531
return True
535532

@@ -604,16 +601,6 @@ def update(self, state : AllState) -> Route:
604601
goal.pose = goal_pose
605602
goal.v = 0
606603

607-
# Check if vehicle is successfully parked
608-
self.parking_success = self.is_successfully_parked(vehicle, goal_pose, agents)
609-
if self.parking_success:
610-
print("Successfully parked!")
611-
else:
612-
print("Not yet successfully parked")
613-
614-
# Save parking status
615-
self.save_parking_message(self.parking_success)
616-
617604
# Need to parse and create second order dubin car states
618605
start_state = self.vehicle_state_to_first_order(vehicle)
619606
goal_state = self.vehicle_state_to_first_order(goal)
@@ -637,7 +624,30 @@ def update(self, state : AllState) -> Route:
637624
route = Path(frame=vehicle.pose.frame, points=points)
638625
# traj = longitudinal_plan(route, 2, -2, 10, vehicle.v, "milestone")
639626
print(traj)
640-
return route
627+
628+
# Check if final position in trajectory is within parking spot
629+
if len(res) > 0:
630+
final_state = res[-1] # Get the last state from the trajectory
631+
try:
632+
with open(self.success_file, 'a') as f:
633+
f.write("Final State")
634+
f.write(final_state)
635+
f.write("Final State End")
636+
print(f"Parking status saved to {self.success_file}")
637+
except Exception as e:
638+
print(f"Error saving parking status: {e}")
639+
self.parking_success = self.is_successfully_parked(final_state, goal_pose, agents)
640+
if self.parking_success:
641+
print("Final position is within parking spot!")
642+
else:
643+
print("Final position is not within parking spot")
644+
645+
# Save parking status
646+
self.save_parking_message(self.parking_success)
647+
else:
648+
print("No trajectory generated")
649+
650+
return route
641651

642652

643653
from rospy.exceptions import ROSInitException

0 commit comments

Comments
 (0)