Skip to content

Commit a954c3f

Browse files
committed
test: LinearMPC with hard bounds and tight tolerances
1 parent 2a4d5d6 commit a954c3f

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

test/5_test_extensions.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
u1 = [20.0, 20.0]
1313
u2 = [20.0, 20.0]
1414
model.x0 .= 0
15-
y_data = zeros(model.ny, N)
1615
u_data1, u_data2 = zeros(model.nu, N), zeros(model.nu, N)
1716
for k in 0:N-1
1817
k == 10 && (r .= [45; 30.0])
1918
k == 25 && (r .= [50; 45.0])
2019
y = model()
21-
y_data[:, k+1] = y
2220
preparestate!(mpc1, y)
2321
= LinearMPC.correct_state!(mpc2, y)
2422
u1 = moveinput!(mpc1, r)
@@ -28,11 +26,19 @@
2826
updatestate!(mpc1, u1, y)
2927
LinearMPC.predict_state!(mpc2, u2)
3028
end
31-
return y_data, u_data1, u_data2
29+
return u_data1, u_data2
3230
end
3331
N = 50
34-
y_data, u_data1, u_data2 = sim_both(model, mpc1, mpc2, N)
35-
@test u_data1 u_data2 atol=1e-3 rtol=1e-3
32+
u_data1, u_data2 = sim_both(model, mpc1, mpc2, N)
33+
@test u_data1 u_data2 atol=1e-3 rtol=1e-3 # looser tol due to different softening
34+
35+
mpc1_hard = LinMPC(model, Hp=15, Cwt=Inf, optim=optim)
36+
mpc1_hard = setconstraint!(mpc1_hard, ymin=[48, -Inf], umax=[Inf, 30])
37+
mpc2_hard = LinearMPC.MPC(mpc1_hard)
38+
u_data1_hard, u_data2_hard = sim_both(
39+
model, mpc1_hard, mpc2_hard, N
40+
)
41+
@test u_data1_hard u_data2_hard atol=1e-12 # exact match for hard constraints
3642

3743
mpc_ms = LinMPC(model; transcription=MultipleShooting(), optim)
3844
@test_throws ErrorException LinearMPC.MPC(mpc_ms)

0 commit comments

Comments
 (0)