Skip to content

Commit da7ae7f

Browse files
committed
Print time metrics
1 parent 0ec665a commit da7ae7f

1 file changed

Lines changed: 15 additions & 24 deletions

File tree

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
from typing import Dict, List
3-
43
import numpy as np
54
from GEMstack.onboard.component import Component
65
from GEMstack.state.agent import AgentState
@@ -12,9 +11,7 @@
1211
from .parking_route_planner import ParkingPlanner
1312
from .parking_scanning import StraightLineMotion
1413
from .longitudinal_planning import longitudinal_plan
15-
16-
17-
14+
import time
1815
class RoutePlanningComponent(Component):
1916
"""Reads a route from disk and returns it as the desired route."""
2017
def __init__(self):
@@ -24,16 +21,14 @@ def __init__(self):
2421
self.compute_parking_route = False
2522
self.done_computing = False
2623
self.already_computed = False
27-
24+
self.planning_time = 0.0
25+
self.last_planning_time = 0.0
2826
def state_inputs(self):
2927
return ["all"]
30-
3128
def state_outputs(self) -> List[str]:
3229
return ['route']
33-
3430
def rate(self):
3531
return 10.0 # very high for our computation ability
36-
3732
def update(self, state: AllState):
3833
# print("Route Planner's mission:", state.mission_plan.planner_type.value)
3934
# print("type of mission plan:", type(PlannerEnum.RRT_STAR))
@@ -43,39 +38,42 @@ def update(self, state: AllState):
4338
# print("Vehicle x:", state.vehicle.pose.x)
4439
# print("Vehicle y:", state.vehicle.pose.y)
4540
# print("Vehicle yaw:", state.vehicle.pose.yaw)
46-
4741
if state.mission_plan.planner_type.name == "PARKING" and not self.compute_parking_route:
4842
print("I am in PARKING mode")
4943
# Not sure where I should construct this object
5044
# if isinstance(self.planner, StraightLineMotion): # we are transitioning from scanning to parking
51-
5245
# Check if the car is still in motion from scanning behavior
5346
# if it is, we need to stop it before parking
5447
# self.planner.brake() # get car totally stopped before parking
5548
# state.vehicle.pose.yaw = 0 # needed this to avoid a weird error in the parking planner
56-
5749
# self.planner = ParkingPlanner()
58-
5950
# self.computed_parking_route = True
6051
# # Return a route after doing some processing based on mission plan REMOVE ONCE OTHER PLANNERS ARE IMPLEMENTED
6152
# traj = self.planner.update(state)
6253
# self.planner.visualize_trajectory(traj)
6354
# self.planner.visualize_trajectory_animated(traj)
64-
6555
desired_points = [(state.vehicle.pose.x, state.vehicle.pose.y),
6656
(state.vehicle.pose.x, state.vehicle.pose.y)]
6757
desired_path = Path(state.vehicle.pose.frame, desired_points)
68-
6958
self.compute_parking_route = True
70-
7159
return desired_path
7260
elif state.mission_plan.planner_type.name == "PARKING" and self.compute_parking_route and not self.done_computing:
7361
state.vehicle.pose.yaw = 0 # needed this to avoid a weird error in the parking planner
74-
7562
if not self.already_computed:
63+
print("\n=== Starting Parking Route Planning ===")
64+
start_time = time.time()
7665
self.planner = ParkingPlanner()
7766
self.done_computing = True
7867
self.route = self.planner.update(state)
68+
# Calculate planning time
69+
self.planning_time = time.time() - start_time
70+
print(f"\n=== Planning Metrics ===")
71+
print(f"Total Planning Time: {self.planning_time:.3f} seconds")
72+
if self.last_planning_time > 0:
73+
print(f"Previous Planning Time: {self.last_planning_time:.3f} seconds")
74+
print(f"Time Difference: {self.planning_time - self.last_planning_time:.3f} seconds")
75+
self.last_planning_time = self.planning_time
76+
print("=== Planning Complete ===\n")
7977
self.planner.visualize_trajectory(self.route)
8078
self.already_computed = True
8179
return self.route
@@ -85,7 +83,6 @@ def update(self, state: AllState):
8583
# Run brute force straight line motion
8684
# if (self.planner is None) or (not isinstance(self.planner, StraightLineMotion)):
8785
# self.planner = StraightLineMotion()
88-
8986
# print("Mission plan:", state.mission_plan)
9087
# print("Vehicle x:", state.vehicle.pose.x)
9188
# print("Vehicle y:", state.vehicle.pose.y)
@@ -94,16 +91,10 @@ def update(self, state: AllState):
9491
desired_points = [(state.vehicle.pose.x, state.vehicle.pose.y),
9592
(state.vehicle.pose.x + 1, state.vehicle.pose.y)]
9693
desired_path = Path(state.vehicle.pose.frame, desired_points)
97-
9894
# @TODO these are constants we need to get from settings
9995
return desired_path
10096
# self.planner.update_speed()
101-
10297
# We want to just go straight
10398
# Use longitudinal planner to go in a straight line
104-
105-
# Get current
106-
107-
108-
99+
# Get current
109100
return None

0 commit comments

Comments
 (0)