Skip to content

Commit 00cffb9

Browse files
author
maoyifei
committed
add other two metrics
1 parent 1693a77 commit 00cffb9

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

GEMstack/onboard/planning/parking_route_planner.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,24 @@ def __init__(self):
447447
os.makedirs(self.logs_dir, exist_ok=True)
448448
self.success_file = os.path.join(self.logs_dir, 'parking_success.txt')
449449

450-
def save_parking_message(self, success: bool, planning_time: float = None):
450+
def save_parking_message(self, success: bool, planning_time: float = None, position_error: float = None, orientation_error: float = None):
451451
"""Save a parking status message to a text file.
452452
453453
Args:
454454
success (bool): Whether parking was successful
455455
planning_time (float): Time taken by A* planner in seconds
456+
position_error (float): Euclidean distance between final and goal positions
457+
orientation_error (float): Absolute difference between final and goal orientations in degrees
456458
"""
457459
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
458460
status = "successful" if success else "unsuccessful"
459461
message = f"Parking {status} at {timestamp}"
460462
if planning_time is not None:
461463
message += f" (Planning time: {planning_time:.2f} seconds)"
464+
if position_error is not None:
465+
message += f" (Position error: {position_error:.3f} m)"
466+
if orientation_error is not None:
467+
message += f" (Orientation error: {orientation_error:.1f} degrees)"
462468
message += "\n"
463469

464470
try:
@@ -652,13 +658,7 @@ def update(self, state : AllState) -> Route:
652658
obstacles = state.obstacles # type: Dict[str, Obstacle]
653659
agents = state.agents # type: Dict[str, AgentState]
654660
all_obstacles = {**agents, **obstacles}
655-
# print(f"Obstacles {obstacles}")
656661
print(f"Agents {agents}")
657-
# goal= state.goal
658-
# print(goal.frame)
659-
# assert goal.frame == ObjectFrameEnum.ABSOLUTE_CARTESIAN
660-
# assert goal.v == 0
661-
# print(f"Goal {goal}")
662662
goal_pose = ObjectPose(frame=ObjectFrameEnum.ABSOLUTE_CARTESIAN, t=0.0, x=state.mission_plan.goal_x,y=state.mission_plan.goal_y,z=0.0,yaw=state.mission_plan.goal_orientation)
663663
goal = VehicleState.zero()
664664
goal.pose = goal_pose
@@ -694,14 +694,27 @@ def update(self, state : AllState) -> Route:
694694
# Check if final position in trajectory is within parking spot
695695
if len(res) > 0:
696696
final_state = res[-1] # Get the last state from the trajectory
697+
try:
698+
with open(self.success_file, 'a') as f:
699+
f.write("Final State")
700+
f.write(str(final_state))
701+
f.write("Final State End")
702+
print(f"Parking status saved to {self.success_file}")
703+
except Exception as e:
704+
print(f"Error saving parking status: {e}")
705+
# Calculate position and orientation errors
706+
final_x, final_y, final_theta = final_state[0], final_state[1], final_state[2]
707+
position_error = math.sqrt((final_x - goal_pose.x)**2 + (final_y - goal_pose.y)**2)
708+
orientation_error = math.degrees(abs(normalize_yaw(final_theta - goal_pose.yaw)))
709+
697710
self.parking_success = self.is_successfully_parked(final_state, goal_pose, agents)
698711
if self.parking_success:
699712
print("Final position is within parking spot!")
700713
else:
701714
print("Final position is not within parking spot")
702715

703-
# Save parking status with planning time
704-
self.save_parking_message(self.parking_success, planning_time)
716+
# Save parking status with planning time and errors
717+
self.save_parking_message(self.parking_success, planning_time, position_error, orientation_error)
705718
else:
706719
print("No trajectory generated")
707720

0 commit comments

Comments
 (0)