88# from GEMstack.state.physical_object import ObjectFrameEnum
99# from GEMstack.state.route import PlannerEnum, Route
1010from .rrt_star import RRTStar
11-
11+ from .. interface . gem import GEMInterface
1212from ..component import Component
1313from ...state import AllState , Roadgraph , Route , PlannerEnum , ObjectFrameEnum , Path , VehicleState , AgentState , AgentEnum
1414from .RRT import BiRRT
@@ -93,32 +93,35 @@ def __init__(self, roadgraphfn : str = None, map_frame : str = None):
9393 else :
9494 raise ValueError ("Unknown roadgraph file extension" , ext )
9595
96- # TODO: Transform global map to start frame
96+ # TODO: Transform global map to start frame?
9797 if self .map_frame == ObjectFrameEnum .GLOBAL :
98- self .start_pose_global = None # Read from GNSS
98+ self .start_pose_global = None # Read from GNSS?
9999 self .roadgraph = self .roadgraph .to_frame (ObjectFrameEnum .START , start_pose_abs = self .start_pose_global )
100100
101101 # If parking route existed, not search anymore. For simulation testing only. TODO: Delete after integration
102102 self .parking_route_existed = False
103103
104+ # Used as route searchers' time limit as well as the update rate of the component
105+ self .update_rate = 10.0
106+
104107 def state_inputs (self ):
105108 return ["all" ]
106109
107110 def state_outputs (self ) -> List [str ]:
108111 return ['route' ]
109112
110113 def rate (self ):
111- return 10.0
114+ return self . update_rate
112115
113116 def update (self , state : AllState ):
114117 print ("Route Planner's mission:" , state .mission_plan .planner_type )
115118 # print("type of mission plan:", type(PlannerEnum.RRT_STAR))
116119 # print("Route Planner's mission:", state.mission_plan.planner_type.value == PlannerEnum.RRT_STAR.value)
117120 # print("Route Planner's mission:", state.mission_plan.planner_type.value == PlannerEnum.PARKING.value)
118121 # print("Mission plan:", state.mission_plan)
119- # print("Vehicle x:", state.vehicle.pose.x)
120- # print("Vehicle y:", state.vehicle.pose.y)
121- # print("Vehicle yaw:", state.vehicle.pose.yaw)
122+ print ("Vehicle x:" , state .vehicle .pose .x )
123+ print ("Vehicle y:" , state .vehicle .pose .y )
124+ print ("Vehicle yaw:" , state .vehicle .pose .yaw )
122125
123126 if state .mission_plan .planner_type .value == PlannerEnum .PARKING .value :
124127 print ("I am in PARKING mode" )
@@ -180,7 +183,8 @@ def update(self, state: AllState):
180183 current_pose = plan_available_pose_on_lane ([state .vehicle .pose .x , state .vehicle .pose .y ],
181184 self .roadgraph , current_yaw = state .vehicle .pose .yaw )
182185 goal_pose = plan_available_pose_on_lane ([goal_pose_ .x , goal_pose_ .y ], self .roadgraph )
183- searcher = BiRRT (current_pose , goal_pose , self .lane_points , map_size , OFFSET = 0.8 )
186+ searcher = BiRRT (current_pose , goal_pose , self .lane_points , map_size , OFFSET = 0.8 , time_limit = 0.1 ,
187+ heading_limit = math .pi / 6 , step_size = 0.5 , search_r = 1.4 , MAX_Iteration = 20000 )
184188 waypoints = searcher .search ()
185189
186190 # For now, waypoints of [x, y, heading] is not working in longitudinal_planning. Use [x, y] instead.
@@ -200,57 +204,25 @@ def update(self, state: AllState):
200204 print ("I am in PARALLEL_PARKING mode" )
201205 # TODO: Get cones information from perception, should have a AgentEnum for cones, for example AgentEnum.CONE
202206 # cones = []
203- # for obj in state.agents.values():
204- # if obj .type == AgentEnum.CONE:
205- # cones.append(obj )
207+ # for agent in state.agents.values():
208+ # if agent .type == AgentEnum.CONE:
209+ # cones.append(agent )
206210
207211 """ BEGIN: For simulation test only. Delete after integration """ """""" """"""
208- def generate_turn (pose , turn_angle = 45 , turn_radius = 3.0 , turn_direction = "right" ,
209- acceleration = 5.0 , deceleration = 2.0 , max_speed = 1.0 , num_points = 10 ):
210- theta = np .deg2rad (turn_angle )
212+ def generate_turn (pose , step = 1.0 , num_points = 10 ):
211213 x , y , yaw = pose
212- R = turn_radius
213- if turn_direction == "left" :
214- cx = x + R * np .cos (yaw - np .pi / 2 )
215- cy = y + R * np .sin (yaw - np .pi / 2 )
216- start_angle = yaw - np .pi / 2
217- angles = np .linspace (start_angle , start_angle - theta , num_points )
218- end_yaw = start_angle - theta
219- elif turn_direction == "right" :
220- cx = x + R * np .cos (yaw + np .pi / 2 )
221- cy = y + R * np .sin (yaw + np .pi / 2 )
222- start_angle = yaw + np .pi / 2
223- angles = np .linspace (start_angle , start_angle + theta , num_points )
224- end_yaw = start_angle + theta
225- else :
226- raise ValueError ('Invalid turn direction' )
227- end_yaw = (end_yaw + np .pi ) % (2 * np .pi ) - np .pi # normalize angle
214+ yaw_left = yaw + math .pi / 4 # 左前方偏 45°
228215 waypoints = []
229- for angle in angles :
230- xi = cx + R * np .cos (angle )
231- yi = cy + R * np .sin (angle )
232- waypoints .append ([xi , yi ])
233- end_pose = waypoints [- 1 ][0 ], waypoints [- 1 ][1 ], end_yaw
234- return waypoints , end_pose
235-
236- ### FOR SIMULATION TEST ONLY ###
237- def generate_pull_over_route (pose , turn_angle = 45 , turn_radius = 3.0 , turn_direction = "right" ):
238- waypoints1 , end_pose = generate_turn (pose , turn_angle = turn_angle , turn_radius = turn_radius ,
239- turn_direction = turn_direction )
240- if turn_direction == "right" :
241- waypoints2 , _ = generate_turn (end_pose , turn_angle = turn_angle , turn_radius = turn_radius ,
242- turn_direction = "left" )
243- else :
244- waypoints2 , _ = generate_turn (end_pose , turn_angle = turn_angle , turn_radius = turn_radius ,
245- turn_direction = "right" )
246- waypoints = waypoints1 + waypoints2
216+ for i in range (1 , num_points + 1 ):
217+ dx = step * i * math .cos (yaw_left )
218+ dy = step * i * math .sin (yaw_left )
219+ waypoints .append ([x + dx , y + dy ])
247220 return waypoints
248221
249222 if not self .parking_route_existed :
250223 current_pose = [state .vehicle .pose .x , state .vehicle .pose .y , state .vehicle .pose .yaw ]
251- waypoints = generate_pull_over_route (current_pose , turn_angle = 45 , turn_radius = 2.0 , turn_direction = "right" )
224+ waypoints = generate_turn (current_pose )
252225 self .route = Route (frame = ObjectFrameEnum .START , points = waypoints )
253-
254226 self .parking_route_existed = True
255227 else :
256228 self .route = state .route
0 commit comments