@@ -293,6 +293,7 @@ def longitudinal_brake(path : Path, deceleration : float, current_speed : float)
293293
294294 print ("=====LONGITUDINAL BRAKE=====" )
295295 print ("path length: " , path .length ())
296+ print ("deceleration: " , deceleration )
296297 length = path .length ()
297298
298299 x0 = points [0 ][0 ]
@@ -362,7 +363,7 @@ def update(self, state : AllState):
362363 closest_dist ,closest_parameter = state .route .closest_point_local ((curr_x ,curr_y ),[self .route_progress - 5.0 ,self .route_progress + 5.0 ])
363364 self .route_progress = closest_parameter
364365
365- lookahead_distance = max (5 , curr_v ** 2 / (2 * self .deceleration ))
366+ lookahead_distance = max (10 , curr_v ** 2 / (2 * self .deceleration ))
366367 route_with_lookahead = route .trim (closest_parameter ,closest_parameter + lookahead_distance )
367368 print ("Lookahead distance:" , lookahead_distance )
368369 #extract out a 10m segment of the route
@@ -404,6 +405,7 @@ def update(self, state : AllState):
404405 # Pedestrian parameters.
405406 x2 , y2 = a .pose .x , a .pose .y
406407 v2 = [a .velocity [0 ], a .velocity [1 ]] # Pedestrian speed vector
408+
407409 # Total simulation time
408410 if curr_v > 0.1 :
409411 total_time = min (10 , lookahead_distance / curr_v )
@@ -421,11 +423,18 @@ def update(self, state : AllState):
421423 print (f"Deceleration: { decel :.2f} m/s^2" )
422424
423425 # Update the lookahead distance based on the deceleration
424- if collision_distance > 0 :
426+ if collision_distance >= 0 :
425427 route_with_lookahead = route .trim (closest_parameter ,closest_parameter + collision_distance )
426428
427429 # relation: None, Yielding, Stopping
428- # Stopping => None
430+ # None: No need to speed down
431+ # Yielding: Speed down but not to 0 m/s
432+ # Stopping: Speed down to 0 m/s
433+ # State transition:
434+ # None => Yielding or Stopping
435+ # Yielding => Stopping
436+ # Stopping => nan
437+
429438 if prev_relation == "Stopping" and self .relation == "Yielding" :
430439 self .relation = "Stopping"
431440
@@ -452,8 +461,10 @@ def update(self, state : AllState):
452461 if should_accelerate :
453462 traj = longitudinal_plan (route_with_lookahead , self .acceleration , self .deceleration , self .desired_speed , curr_v )
454463 elif should_brake and not should_yield :
455- traj = longitudinal_brake (route_with_lookahead , self .deceleration , curr_v )
464+ # Stopping: 2.0 < Decel < 8.0
465+ traj = longitudinal_brake (route_with_lookahead , decel , curr_v )
456466 elif should_brake and should_yield :
467+ # Yielding: 0.0 < Decel < 2.0
457468 traj = longitudinal_brake (route_with_lookahead , decel , curr_v )
458469 else :
459470 traj = longitudinal_plan (route_with_lookahead , 0.0 , self .deceleration , self .desired_speed , curr_v )
0 commit comments