|
|
|
@ -200,9 +200,8 @@ class LongitudinalMpc(): |
|
|
|
|
self.a_solution = [0.0 for i in range(N+1)] |
|
|
|
|
self.j_solution = [0.0 for i in range(N)] |
|
|
|
|
self.yref = np.zeros((N+1, COST_DIM)) |
|
|
|
|
for i in range(N): |
|
|
|
|
self.solver.cost_set(i, "yref", self.yref[i]) |
|
|
|
|
self.solver.cost_set(N, "yref", self.yref[N][:COST_E_DIM]) |
|
|
|
|
self.solver.cost_set_slice(0, N, b"yref", self.yref) |
|
|
|
|
self.solver.cost_set(N, b"yref", self.yref[N][:COST_E_DIM]) |
|
|
|
|
self.x_sol = np.zeros((N+1, X_DIM)) |
|
|
|
|
self.u_sol = np.zeros((N,1)) |
|
|
|
|
self.params = np.zeros((N+1,3)) |
|
|
|
@ -223,29 +222,25 @@ class LongitudinalMpc(): |
|
|
|
|
|
|
|
|
|
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, J_EGO_COST])) |
|
|
|
|
for i in range(N): |
|
|
|
|
self.solver.cost_set(i, 'W', W) |
|
|
|
|
self.solver.cost_set_slice(0, N, b'W', W[None,:,:], const=True) |
|
|
|
|
# Setting the slice without the copy make the array not contiguous, |
|
|
|
|
# causing issues with the C interface. |
|
|
|
|
self.solver.cost_set(N, 'W', np.copy(W[:COST_E_DIM, :COST_E_DIM])) |
|
|
|
|
self.solver.cost_set(N, b'W', np.copy(W[:COST_E_DIM, :COST_E_DIM])) |
|
|
|
|
|
|
|
|
|
# Set L2 slack cost on lower bound constraints |
|
|
|
|
Zl = np.array([LIMIT_COST, LIMIT_COST, LIMIT_COST, DANGER_ZONE_COST]) |
|
|
|
|
for i in range(N): |
|
|
|
|
self.solver.cost_set(i, 'Zl', Zl) |
|
|
|
|
self.solver.cost_set_slice(0, N, b'Zl', Zl[None,:], const=True) |
|
|
|
|
|
|
|
|
|
def set_weights_for_xva_policy(self): |
|
|
|
|
W = np.asfortranarray(np.diag([0., 10., 1., 10., 1.])) |
|
|
|
|
for i in range(N): |
|
|
|
|
self.solver.cost_set(i, 'W', W) |
|
|
|
|
self.solver.cost_set_slice(0, N, b'W', W[None,:,:], const=True) |
|
|
|
|
# Setting the slice without the copy make the array not contiguous, |
|
|
|
|
# causing issues with the C interface. |
|
|
|
|
self.solver.cost_set(N, 'W', np.copy(W[:COST_E_DIM, :COST_E_DIM])) |
|
|
|
|
self.solver.cost_set(N, b'W', np.copy(W[:COST_E_DIM, :COST_E_DIM])) |
|
|
|
|
|
|
|
|
|
# Set L2 slack cost on lower bound constraints |
|
|
|
|
Zl = np.array([LIMIT_COST, LIMIT_COST, LIMIT_COST, 0.0]) |
|
|
|
|
for i in range(N): |
|
|
|
|
self.solver.cost_set(i, 'Zl', Zl) |
|
|
|
|
self.solver.cost_set_slice(0, N, b'Zl', Zl[None,:], const=True) |
|
|
|
|
|
|
|
|
|
def set_cur_state(self, v, a): |
|
|
|
|
if abs(self.x0[1] - v) > 1.: |
|
|
|
@ -332,9 +327,8 @@ class LongitudinalMpc(): |
|
|
|
|
self.yref[:,1] = x |
|
|
|
|
self.yref[:,2] = v |
|
|
|
|
self.yref[:,3] = a |
|
|
|
|
for i in range(N): |
|
|
|
|
self.solver.cost_set(i, "yref", self.yref[i]) |
|
|
|
|
self.solver.cost_set(N, "yref", self.yref[N][:COST_E_DIM]) |
|
|
|
|
self.solver.cost_set_slice(0, N, b"yref", self.yref) |
|
|
|
|
self.solver.cost_set(N, b"yref", self.yref[N][:COST_E_DIM]) |
|
|
|
|
self.accel_limit_arr[:,0] = -10. |
|
|
|
|
self.accel_limit_arr[:,1] = 10. |
|
|
|
|
x_obstacle = 1e5*np.ones((N+1)) |
|
|
|
|