Skip to content

Commit

Permalink
long MPC: comments, simplify set_cur_state
Browse files Browse the repository at this point in the history
  • Loading branch information
FreyJo authored and haraschax committed Feb 25, 2022
1 parent a198254 commit d83e3bc
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions selfdrive/controls/lib/longitudinal_mpc_lib/long_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

X_DIM = 3
U_DIM = 1
PARAM_DIM= 4
PARAM_DIM = 4
COST_E_DIM = 5
COST_DIM = COST_E_DIM + 1
CONSTR_DIM = 4
Expand Down Expand Up @@ -236,6 +236,7 @@ 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):
# reduce the cost on (a-a_prev) later in the horizon.
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,
Expand All @@ -261,14 +262,12 @@ def set_weights_for_xva_policy(self):
self.solver.cost_set(i, 'Zl', Zl)

def set_cur_state(self, v, a):
if abs(self.x0[1] - v) > 2.:
self.x0[1] = v
self.x0[2] = a
v_prev = self.x0[1]
self.x0[1] = v
self.x0[2] = a
if abs(v_prev - v) > 2.: # probably only helps if v < v_prev
for i in range(0, N+1):
self.solver.set(i, 'x', self.x0)
else:
self.x0[1] = v
self.x0[2] = a

@staticmethod
def extrapolate_lead(x_lead, v_lead, a_lead, a_lead_tau):
Expand Down

0 comments on commit d83e3bc

Please sign in to comment.