Skip to content

Commit f1c3b5e

Browse files
committed
added: new methods in precompile workload
Objects with `MultipleShooting`, `TrapezoidalCollocation` and `RungeKutta`, to try to reduce TTFX with them
1 parent f84798a commit f1c3b5e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/precompile.jl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ mpc_kf.estim()
2020
u = mpc_kf([55, 30])
2121
sim!(mpc_kf, 2, [55, 30])
2222

23-
mpc_lo = setconstraint!(LinMPC(Luenberger(model)), ymin=[45, -Inf])
23+
transcription = MultipleShooting()
24+
mpc_lo = setconstraint!(LinMPC(Luenberger(model); transcription), ymin=[45, -Inf])
2425
initstate!(mpc_lo, model.uop, model())
2526
preparestate!(mpc_lo, [55, 30])
2627
mpc_lo.estim()
@@ -79,18 +80,21 @@ exmpc.estim()
7980
u = exmpc([55, 30])
8081
sim!(exmpc, 2, [55, 30])
8182

82-
function f!(xnext, x, u, _, model)
83-
mul!(xnext, model.A , x)
84-
mul!(xnext, model.Bu, u, 1, 1)
83+
function f!(xnext, x, u, _ , p)
84+
A, B, _ = p
85+
mul!(xnext, A , x)
86+
mul!(xnext, B, u, 1, 1)
8587
return nothing
8688
end
87-
function h!(y, x, _, model)
88-
mul!(y, model.C, x)
89+
function h!(y, x, _ , p)
90+
_, _, C = p
91+
mul!(y, C, x)
8992
return nothing
9093
end
9194

95+
sys2 = minreal(ss(sys))
9296
nlmodel = setop!(
93-
NonLinModel(f!, h!, Ts, 2, 2, 2, solver=nothing, p=model),
97+
NonLinModel(f!, h!, Ts, 2, 2, 2, solver=RungeKutta(4), p=(sys2.A, sys2.B, sys2.C)),
9498
uop=[10, 10], yop=[50, 30]
9599
)
96100
y = nlmodel()
@@ -101,8 +105,9 @@ nmpc_im.estim()
101105
u = nmpc_im([55, 30])
102106
sim!(nmpc_im, 2, [55, 30])
103107

104-
nmpc_ukf = setconstraint!(
105-
NonLinMPC(UnscentedKalmanFilter(nlmodel), Hp=10, Cwt=1e3), ymin=[45, -Inf]
108+
transcription = MultipleShooting(f_threads=true)
109+
nmpc_ukf = setconstraint!(NonLinMPC(
110+
UnscentedKalmanFilter(nlmodel); Hp=10, transcription, Cwt=1e3), ymin=[45, -Inf]
106111
)
107112
initstate!(nmpc_ukf, nlmodel.uop, y)
108113
preparestate!(nmpc_ukf, [55, 30])
@@ -115,8 +120,9 @@ preparestate!(nmpc_ekf, [55, 30])
115120
u = nmpc_ekf([55, 30])
116121
sim!(nmpc_ekf, 2, [55, 30])
117122

118-
nmpc_mhe = setconstraint!(
119-
NonLinMPC(MovingHorizonEstimator(nlmodel, He=2), Hp=10, Cwt=Inf), ymin=[45, -Inf]
123+
transcription = TrapezoidalCollocation()
124+
nmpc_mhe = setconstraint!(NonLinMPC(
125+
MovingHorizonEstimator(nlmodel, He=2); transcription, Hp=10, Cwt=Inf), ymin=[45, -Inf]
120126
)
121127
setconstraint!(nmpc_mhe.estim, x̂min=[-50,-50,-50,-50], x̂max=[50,50,50,50])
122128
initstate!(nmpc_mhe, nlmodel.uop, y)

0 commit comments

Comments
 (0)