Skip to content

Commit 28a483f

Browse files
committed
debug: correct lastu0 size in LinMPC
1 parent 2fc285e commit 28a483f

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/controller/explicitmpc.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct ExplicitMPC{
5353
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc)
5454
E, G, J, K, V, B = init_predmat(model, estim, transcription, Hp, Hc)
5555
# dummy val (updated just before optimization):
56-
F, fx̂ = zeros(NT, ny*Hp), zeros(NT, nx̂)
56+
F = zeros(NT, ny*Hp)
5757
P̃Δu, P̃u, Ẽ = PΔu, Pu, E # no slack variable ϵ for ExplicitMPC
5858
= init_quadprog(model, weights, Ẽ, P̃Δu, P̃u)
5959
# dummy vals (updated just before optimization):
@@ -218,7 +218,7 @@ addinfo!(info, mpc::ExplicitMPC) = info
218218

219219

220220
"Update the prediction matrices and Cholesky factorization."
221-
function setmodel_controller!(mpc::ExplicitMPC, _ )
221+
function setmodel_controller!(mpc::ExplicitMPC, uop_old, _ )
222222
model, estim, transcription = mpc.estim.model, mpc.estim, mpc.transcription
223223
nu, ny, nd, Hp, Hc = model.nu, model.ny, model.nd, mpc.Hp, mpc.Hc
224224
# --- predictions matrices ---
@@ -235,6 +235,7 @@ function setmodel_controller!(mpc::ExplicitMPC, _ )
235235
mpc.H̃ .=
236236
set_objective_hessian!(mpc)
237237
# --- operating points ---
238+
mpc.lastu0 .+= uop_old .- model.uop
238239
for i in 0:Hp-1
239240
mpc.Uop[(1+nu*i):(nu+nu*i)] .= model.uop
240241
mpc.Yop[(1+ny*i):(ny+ny*i)] .= model.yop

src/controller/linmpc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct LinMPC{
6161
= copy(model.yop) # dummy vals (updated just before optimization)
6262
# dummy vals (updated just before optimization):
6363
R̂y, R̂u, Tu_lastu0 = zeros(NT, ny*Hp), zeros(NT, nu*Hp), zeros(NT, nu*Hp)
64-
lastu0 = zeros(NT, ny)
64+
lastu0 = zeros(NT, nu)
6565
PΔu = init_ZtoΔU(estim, transcription, Hp, Hc)
6666
Pu, Tu = init_ZtoU(estim, transcription, Hp, Hc)
6767
E, G, J, K, V, B, ex̂, gx̂, jx̂, kx̂, vx̂, bx̂ = init_predmat(

test/2_test_state_estim.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ end
264264
@test kalmanfilter. [0.2]
265265
preparestate!(kalmanfilter, [55.0])
266266
@test evaloutput(kalmanfilter) [55.0]
267-
@test kalmanfilter.lastu0 [2.0 - 3.0]
268267
preparestate!(kalmanfilter, [55.0])
269268
= updatestate!(kalmanfilter, [3.0], [55.0])
270269
@test [3.0]
@@ -507,7 +506,6 @@ end
507506
@test internalmodel. [0.2]
508507
preparestate!(internalmodel, [55.0])
509508
@test evaloutput(internalmodel) [55.0]
510-
@test internalmodel.lastu0 [2.0 - 3.0]
511509
preparestate!(internalmodel, [55.0])
512510
= updatestate!(internalmodel, [3.0], [55.0])
513511
@test [3.0]
@@ -653,7 +651,6 @@ end
653651
@test ukf1. [0.2]
654652
preparestate!(ukf1, [55.0])
655653
@test evaloutput(ukf1) [55.0]
656-
@test ukf1.lastu0 [2.0 - 3.0]
657654
preparestate!(ukf1, [55.0])
658655
= updatestate!(ukf1, [3.0], [55.0])
659656
@test [3.0]
@@ -818,7 +815,6 @@ end
818815
@test ekf1. [0.2]
819816
preparestate!(ekf1, [55.0])
820817
@test evaloutput(ekf1) [55.0]
821-
@test ekf1.lastu0 [2.0 - 3.0]
822818
preparestate!(ekf1, [55.0])
823819
= updatestate!(ekf1, [3.0], [55.0])
824820
@test [3.0]

test/3_test_predictive_control.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ end
361361
preparestate!(mpc, [10])
362362
u = moveinput!(mpc, r)
363363
@test u [2] atol=1e-2
364+
@test mpc.lastu0 [2] - [1] atol=1e-2
364365
setmodel!(mpc, setop!(LinModel(tf(5, [2, 1]), 3), yop=[20], uop=[11]))
365366
@test mpc.Yop fill(20.0, 1000)
366367
@test mpc.Uop fill(11.0, 1000)
367368
@test mpc.con.U0min fill(-24.0 - 1 + 1 - 11, 1000)
368369
@test mpc.con.U0max fill(26.0 - 1 + 1 - 11, 1000)
369370
@test mpc.con.Y0min fill(-54.0 - 10 + 10 - 20, 1000)
370371
@test mpc.con.Y0max fill(56.0 - 10 + 10 - 20, 1000)
372+
@test mpc.lastu0 [2] - [11] atol=1e-2
371373
r = [40]
372374
u = moveinput!(mpc, r)
373375
@test u [15] atol=1e-2
@@ -556,9 +558,11 @@ end
556558
preparestate!(mpc, [10])
557559
u = moveinput!(mpc, r)
558560
@test u [2] atol=1e-2
561+
@test mpc.lastu0 [2] - [1] atol=1e-2
559562
setmodel!(mpc, setop!(LinModel(tf(5, [2, 1]), 3), yop=[20], uop=[11]))
560563
@test mpc.Yop fill(20.0, 1000)
561564
@test mpc.Uop fill(11.0, 1000)
565+
@test mpc.lastu0 [2] - [11] atol=1e-2
562566
r = [40]
563567
u = moveinput!(mpc, r)
564568
@test u [15] atol=1e-2
@@ -1112,13 +1116,15 @@ end
11121116
preparestate!(mpc, [10])
11131117
u = moveinput!(mpc, r)
11141118
@test u [2] atol=1e-2
1119+
@test mpc.lastu0 [2] - [1] atol=1e-2
11151120
setmodel!(mpc, setop!(LinModel(tf(5, [200, 1]), 300), yop=[20], uop=[11]))
11161121
@test mpc.Yop fill(20.0, 1000)
11171122
@test mpc.Uop fill(11.0, 1000)
11181123
@test mpc.con.U0min fill(-24.0 - 1 + 1 - 11, 1000)
11191124
@test mpc.con.U0max fill(26.0 - 1 + 1 - 11, 1000)
11201125
@test mpc.con.Y0min fill(-54.0 - 10 + 10 - 20, 1000)
11211126
@test mpc.con.Y0max fill(56.0 - 10 + 10 - 20, 1000)
1127+
@test mpc.lastu0 [2] - [11] atol=1e-2
11221128
r = [40]
11231129
u = moveinput!(mpc, r)
11241130
@test u [15] atol=1e-2

0 commit comments

Comments
 (0)