@ -16,12 +16,12 @@ CAMERA_OFFSET = 0.04
PATH_COST = 1.0
LATERAL_MOTION_COST = 0.11
LATERAL_ACCEL_COST = 0.0
LATERAL_JERK_COST = 0.05
LATERAL_JERK_COST = 0.04
# Extreme steering rate is unpleasant, even
# when it does not cause bad jerk.
# TODO this cost should be lowered when low
# speed lateral control is stable on all cars
STEERING_RATE_COST = 8 00.0
STEERING_RATE_COST = 7 00.0
class LateralPlanner :
@ -35,6 +35,7 @@ class LateralPlanner:
self . solution_invalid_cnt = 0
self . path_xyz = np . zeros ( ( TRAJECTORY_SIZE , 3 ) )
self . velocity_xyz = np . zeros ( ( TRAJECTORY_SIZE , 3 ) )
self . plan_yaw = np . zeros ( ( TRAJECTORY_SIZE , ) )
self . plan_yaw_rate = np . zeros ( ( TRAJECTORY_SIZE , ) )
self . t_idxs = np . arange ( TRAJECTORY_SIZE )
@ -49,7 +50,6 @@ class LateralPlanner:
def update ( self , sm ) :
# clip speed , lateral planning is not possible at 0 speed
self . v_ego = max ( MIN_SPEED , sm [ ' carState ' ] . vEgo )
measured_curvature = sm [ ' controlsState ' ] . curvature
# Parse model predictions
@ -59,6 +59,10 @@ class LateralPlanner:
self . t_idxs = np . array ( md . position . t )
self . plan_yaw = np . array ( md . orientation . z )
self . plan_yaw_rate = np . array ( md . orientationRate . z )
self . velocity_xyz = np . column_stack ( [ md . velocity . x , md . velocity . y , md . velocity . z ] )
car_speed = np . linalg . norm ( self . velocity_xyz , axis = 1 )
self . v_plan = np . clip ( car_speed , MIN_SPEED , np . inf )
self . v_ego = self . v_plan [ 0 ]
# Lane change logic
desire_state = md . meta . desireState
@ -68,21 +72,20 @@ class LateralPlanner:
lane_change_prob = self . l_lane_change_prob + self . r_lane_change_prob
self . DH . update ( sm [ ' carState ' ] , sm [ ' carControl ' ] . latActive , lane_change_prob )
d_path_xyz = self . path_xyz
self . lat_mpc . set_weights ( PATH_COST , LATERAL_MOTION_COST ,
LATERAL_ACCEL_COST , LATERAL_JERK_COST ,
STEERING_RATE_COST )
y_pts = np . interp ( self . v_ego * self . t_idxs [ : LAT_MPC_N + 1 ] , np . linalg . norm ( d_path_xyz , axis = 1 ) , d_path_xyz [ : , 1 ] )
heading_pts = np . interp ( self . v_ego * self . t_idxs [ : LAT_MPC_N + 1 ] , np . linalg . norm ( self . path_xyz , axis = 1 ) , self . plan_yaw )
yaw_rate_pts = np . interp ( self . v_ego * self . t_idxs [ : LAT_MPC_N + 1 ] , np . linalg . norm ( self . path_xyz , axis = 1 ) , self . plan_yaw_rate )
y_pts = self . path_xyz [ : LAT_MPC_N + 1 , 1 ]
heading_pts = self . plan_yaw [ : LAT_MPC_N + 1 ]
yaw_rate_pts = self . plan_yaw_rate [ : LAT_MPC_N + 1 ]
self . y_pts = y_pts
assert len ( y_pts ) == LAT_MPC_N + 1
assert len ( heading_pts ) == LAT_MPC_N + 1
assert len ( yaw_rate_pts ) == LAT_MPC_N + 1
lateral_factor = max ( 0 , self . factor1 - ( self . factor2 * self . v_ego * * 2 ) )
p = np . array ( [ self . v_ego , lateral_factor ] )
lateral_factor = np . clip ( self . factor1 - ( self . factor2 * self . v_plan * * 2 ) , 0.0 , np . inf )
p = np . column_stack ( [ self . v_plan , lateral_factor ] )
self . lat_mpc . run ( self . x0 ,
p ,
y_pts ,