@@ -20,7 +20,8 @@ mpc_kf.estim()
2020u = mpc_kf ([55 , 30 ])
2121sim! (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 ])
2425initstate! (mpc_lo, model. uop, model ())
2526preparestate! (mpc_lo, [55 , 30 ])
2627mpc_lo. estim ()
@@ -79,18 +80,21 @@ exmpc.estim()
7980u = exmpc ([55 , 30 ])
8081sim! (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
8688end
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
9093end
9194
95+ sys2 = minreal (ss (sys))
9296nlmodel = 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)
96100y = nlmodel ()
@@ -101,8 +105,9 @@ nmpc_im.estim()
101105u = nmpc_im ([55 , 30 ])
102106sim! (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)
107112initstate! (nmpc_ukf, nlmodel. uop, y)
108113preparestate! (nmpc_ukf, [55 , 30 ])
@@ -115,8 +120,9 @@ preparestate!(nmpc_ekf, [55, 30])
115120u = nmpc_ekf ([55 , 30 ])
116121sim! (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)
121127setconstraint! (nmpc_mhe. estim, x̂min= [- 50 ,- 50 ,- 50 ,- 50 ], x̂max= [50 ,50 ,50 ,50 ])
122128initstate! (nmpc_mhe, nlmodel. uop, y)
0 commit comments