Classes | |
class | Animation |
class | MPCController |
Variables | |
float | Ts = 0.05 |
int | N = 6 |
int | dim = 2 |
model = HangingChain(N, dim) | |
f_d = model.dynamics(Ts) | |
y_null | |
u_null | |
list | param = [0.03, 1.6, 0.033 / N] |
int | N_dist = 3 |
list | u_dist = 3 else [-0.5, 0.5] |
y_dist = model.simulate(N_dist, y_null, u_dist, param) | |
int | N_sim = 180 |
y_sim = model.simulate(N_sim, y_dist[:, -1], u_null, param) | |
int | N_horiz = 12 |
L_cost = model.generate_cost_fun() | |
y_init = cs.SX.sym("y_init", *y_null.shape) | |
U = cs.SX.sym("U", dim * N_horiz) | |
constr_param = cs.SX.sym("c", 3) | |
mpc_param = cs.vertcat(y_init, model.params, constr_param) | |
U_mat = model.input_to_matrix(U) | |
mpc_sim = model.simulate(N_horiz, y_init, U_mat, model.params) | |
int | mpc_cost = 0 |
y_n = mpc_sim[:, n] | |
u_n = U_mat[:, n] | |
mpc_cost_fun = cs.Function('f_mpc', [U, mpc_param], [mpc_cost]) | |
int | g_constr = lambda c, x: c[0] * x**3 + c[1] * x**2 + c[2] * x |
list | constr = [] |
yx_n = y_n[dim * i] | |
yy_n = y_n[dim * i + dim - 1] | |
mpc_constr_fun = cs.Function("g", [U, mpc_param], [cs.vertcat(*constr)]) | |
a | |
b | |
c | |
d | |
list | constr_coeff = [c, -3 * a * c, 3 * a * a * c + d] |
int | constr_lb = b - c * a**3 - d * a |
prob = pa.generate_and_compile_casadi_problem(mpc_cost_fun, mpc_constr_fun) | |
lowerbound | |
upperbound | |
solver | |
n_state = y_n.shape[0] | |
y_mpc = np.empty((n_state, N_sim)) | |
controller = MPCController(model, prob) | |
fig | |
ax | |
x = np.linspace(-0.25, 1.25, 256) | |
y = np.linspace(-2.5, 1, 256) | |
z | |
label | |
X | |
Y | |
int | Z = g_constr(constr_coeff, X) + constr_lb - Y |
list | fx = [patheffects.withTickedStroke(spacing=7, linewidth=0.8)] |
cgc = plt.contour(X, Y, Z, [0], colors='tab:green', linewidths=0.8) | |
collections | |
path_effects | |
ani | |
out | |
exist_ok | |
float Ts = 0.05 |
Definition at line 18 of file hanging-chain-mpc.py.
int N = 6 |
Definition at line 19 of file hanging-chain-mpc.py.
int dim = 2 |
Definition at line 20 of file hanging-chain-mpc.py.
model = HangingChain(N, dim) |
Definition at line 22 of file hanging-chain-mpc.py.
f_d = model.dynamics(Ts) |
Definition at line 23 of file hanging-chain-mpc.py.
y_null |
Definition at line 24 of file hanging-chain-mpc.py.
u_null |
Definition at line 24 of file hanging-chain-mpc.py.
param = [0.03, 1.6, 0.033 / N] |
Definition at line 26 of file hanging-chain-mpc.py.
int N_dist = 3 |
Definition at line 30 of file hanging-chain-mpc.py.
list u_dist = 3 else [-0.5, 0.5] |
Definition at line 31 of file hanging-chain-mpc.py.
Definition at line 32 of file hanging-chain-mpc.py.
int N_sim = 180 |
Definition at line 37 of file hanging-chain-mpc.py.
Definition at line 38 of file hanging-chain-mpc.py.
int N_horiz = 12 |
Definition at line 43 of file hanging-chain-mpc.py.
L_cost = model.generate_cost_fun() |
Definition at line 45 of file hanging-chain-mpc.py.
y_init = cs.SX.sym("y_init", *y_null.shape) |
Definition at line 46 of file hanging-chain-mpc.py.
U = cs.SX.sym("U", dim * N_horiz) |
Definition at line 47 of file hanging-chain-mpc.py.
constr_param = cs.SX.sym("c", 3) |
Definition at line 48 of file hanging-chain-mpc.py.
mpc_param = cs.vertcat(y_init, model.params, constr_param) |
Definition at line 49 of file hanging-chain-mpc.py.
U_mat = model.input_to_matrix(U) |
Definition at line 50 of file hanging-chain-mpc.py.
Definition at line 53 of file hanging-chain-mpc.py.
int mpc_cost = 0 |
Definition at line 54 of file hanging-chain-mpc.py.
y_n = mpc_sim[:, n] |
Definition at line 56 of file hanging-chain-mpc.py.
u_n = U_mat[:, n] |
Definition at line 57 of file hanging-chain-mpc.py.
Definition at line 59 of file hanging-chain-mpc.py.
Definition at line 62 of file hanging-chain-mpc.py.
list constr = [] |
Definition at line 63 of file hanging-chain-mpc.py.
Definition at line 67 of file hanging-chain-mpc.py.
Definition at line 68 of file hanging-chain-mpc.py.
Definition at line 71 of file hanging-chain-mpc.py.
a |
Definition at line 74 of file hanging-chain-mpc.py.
b |
Definition at line 74 of file hanging-chain-mpc.py.
c |
Definition at line 74 of file hanging-chain-mpc.py.
d |
Definition at line 74 of file hanging-chain-mpc.py.
Definition at line 75 of file hanging-chain-mpc.py.
prob = pa.generate_and_compile_casadi_problem(mpc_cost_fun, mpc_constr_fun) |
Definition at line 81 of file hanging-chain-mpc.py.
lowerbound |
Definition at line 82 of file hanging-chain-mpc.py.
upperbound |
Definition at line 83 of file hanging-chain-mpc.py.
solver |
Definition at line 89 of file hanging-chain-mpc.py.
n_state = y_n.shape[0] |
Definition at line 141 of file hanging-chain-mpc.py.
Definition at line 144 of file hanging-chain-mpc.py.
controller = MPCController(model, prob) |
Definition at line 145 of file hanging-chain-mpc.py.
fig |
Definition at line 165 of file hanging-chain-mpc.py.
ax |
Definition at line 165 of file hanging-chain-mpc.py.
x = np.linspace(-0.25, 1.25, 256) |
Definition at line 166 of file hanging-chain-mpc.py.
y = np.linspace(-2.5, 1, 256) |
Definition at line 166 of file hanging-chain-mpc.py.
z |
Definition at line 166 of file hanging-chain-mpc.py.
label |
Definition at line 167 of file hanging-chain-mpc.py.
X |
Definition at line 175 of file hanging-chain-mpc.py.
Y |
Definition at line 175 of file hanging-chain-mpc.py.
int Z = g_constr(constr_coeff, X) + constr_lb - Y |
Definition at line 176 of file hanging-chain-mpc.py.
list fx = [patheffects.withTickedStroke(spacing=7, linewidth=0.8)] |
Definition at line 178 of file hanging-chain-mpc.py.
Definition at line 179 of file hanging-chain-mpc.py.
collections |
Definition at line 180 of file hanging-chain-mpc.py.
path_effects |
Definition at line 180 of file hanging-chain-mpc.py.
ani |
Definition at line 205 of file hanging-chain-mpc.py.
out |
Definition at line 213 of file hanging-chain-mpc.py.
exist_ok |
Definition at line 215 of file hanging-chain-mpc.py.