@@ -99,17 +99,7 @@ def detect_collision(curr_x: float, curr_y: float, curr_v: float, obj: AgentStat
9999
100100 distance_to_move = pedestrian_back - vehicle_front - vehicle_buffer_x + time_to_pass * obj_v_y
101101
102- #======replace this part with actual algorithm====
103-
104- deceleration = relative_v ** 2 / (2 * distance )
105- if deceleration > max_deceleration :
106- return True , max_deceleration
107- if deceleration < min_deceleration :
108- return False , 0.0
109-
110- return True , deceleration
111-
112- # ================================================
102+ return True , [distance_to_move , time_to_pass ]
113103
114104 else :
115105 deceleration = relative_v ** 2 / (2 * distance )
@@ -266,9 +256,6 @@ def update(self, state : AllState):
266256 print ("Lookahead distance:" , lookahead_distance )
267257
268258 route_to_end = route .trim (closest_parameter , len (route .points ) - 1 )
269-
270- #extract out a 10m segment of the route
271- # route_with_lookahead = route.trim(closest_parameter,closest_parameter+10.0)
272259
273260 should_yield = False
274261 yield_deceleration = 0.0
@@ -277,19 +264,21 @@ def update(self, state : AllState):
277264
278265 for r in state .relations :
279266 if r .type == EntityRelationEnum .YIELDING and r .obj1 == '' :
280- #yielding to something, brake
281-
282- #=========================
283- # print("#### YIELDING PLANNING ####")
284-
285267 #get the object we are yielding to
286268 obj = state .agents [r .obj2 ]
287269
288270 detected , deceleration = detect_collision (abs_x , abs_y , curr_v , obj , self .min_deceleration , self .max_deceleration )
289-
290- if detected and deceleration > 0 :
291- yield_deceleration = max (deceleration , yield_deceleration )
292- should_yield = True
271+ if isinstance (deceleration , list ):
272+ time_collision = deceleration [1 ]
273+ distance_collision = deceleration [0 ]
274+ b = 3 * time_collision - 2 * curr_v
275+ c = curr_v ** 2 - 3 * distance_collision
276+ self .desired_speed = (- b + (b ** 2 - 4 * c )** 0.5 )/ 2
277+ self .deceleration = 1.5
278+ else :
279+ if detected and deceleration > 0 :
280+ yield_deceleration = max (deceleration , yield_deceleration )
281+ should_yield = True
293282
294283 print ("should yield: " , should_yield )
295284
@@ -298,5 +287,4 @@ def update(self, state : AllState):
298287 traj = longitudinal_brake (route_with_lookahead , yield_deceleration , curr_v )
299288 else :
300289 traj = longitudinal_plan (route_to_end , self .acceleration , self .deceleration , self .desired_speed , curr_v )
301-
302290 return traj
0 commit comments