@ -219,19 +219,20 @@ class LongitudinalMpc:
self . x0 = np . zeros ( X_DIM )
self . set_weights ( )
def set_weights ( self ) :
def set_weights ( self , prev_accel_constraint = True ) :
if self . e2e :
self . set_weights_for_xva_policy ( )
self . params [ : , 0 ] = - 10.
self . params [ : , 1 ] = 10.
self . params [ : , 2 ] = 1e5
else :
self . set_weights_for_lead_policy ( )
self . set_weights_for_lead_policy ( prev_accel_constraint )
def set_weights_for_lead_policy ( self ) :
W = np . asfortranarray ( np . diag ( [ X_EGO_OBSTACLE_COST , X_EGO_COST , V_EGO_COST , A_EGO_COST , A_CHANGE_COST , J_EGO_COST ] ) )
def set_weights_for_lead_policy ( self , prev_accel_constraint = True ) :
a_change_cost = A_CHANGE_COST if prev_accel_constraint else 0
W = np . asfortranarray ( np . diag ( [ X_EGO_OBSTACLE_COST , X_EGO_COST , V_EGO_COST , A_EGO_COST , a_change_cost , J_EGO_COST ] ) )
for i in range ( N ) :
W [ 4 , 4 ] = A_CHANGE_COST * np . interp ( T_IDXS [ i ] , [ 0.0 , 1.0 , 2.0 ] , [ 1.0 , 1.0 , 0.0 ] )
W [ 4 , 4 ] = a_change_cost * np . interp ( T_IDXS [ i ] , [ 0.0 , 1.0 , 2.0 ] , [ 1.0 , 1.0 , 0.0 ] )
self . solver . cost_set ( i , ' W ' , W )
# Setting the slice without the copy make the array not contiguous,
# causing issues with the C interface.
@ -300,9 +301,8 @@ class LongitudinalMpc:
self . cruise_min_a = min_a
self . cruise_max_a = max_a
def update ( self , carstate , radarstate , v_cruise , prev_accel_constraint = False ) :
def update ( self , carstate , radarstate , v_cruise ) :
v_ego = self . x0 [ 1 ]
a_ego = self . x0 [ 2 ]
self . status = radarstate . leadOne . status or radarstate . leadTwo . status
lead_xv_0 = self . process_lead ( radarstate . leadOne )
@ -330,10 +330,7 @@ class LongitudinalMpc:
x_obstacles = np . column_stack ( [ lead_0_obstacle , lead_1_obstacle , cruise_obstacle ] )
self . source = SOURCES [ np . argmin ( x_obstacles [ 0 ] ) ]
self . params [ : , 2 ] = np . min ( x_obstacles , axis = 1 )
if prev_accel_constraint :
self . params [ : , 3 ] = np . copy ( self . prev_a )
else :
self . params [ : , 3 ] = a_ego
self . params [ : , 3 ] = np . copy ( self . prev_a )
self . run ( )
if ( np . any ( lead_xv_0 [ : , 0 ] - self . x_sol [ : , 0 ] < CRASH_DISTANCE ) and