260260
261261@testset " LinMPC set model" begin
262262 estim = KalmanFilter (setop! (LinModel (tf (5 , [2 , 1 ]), 3 ), yop= [10 ], uop= [1 ]))
263- mpc = LinMPC (estim, Nwt= [0 ], Hp= 1000 , Hc= 1 )
263+ mpc = LinMPC (estim, Nwt= [0 ], Cwt = 1e4 , Hp= 1000 , Hc= 1 )
264264 mpc = setconstraint! (mpc, umin= [- 24 ], umax= [26 ])
265265 mpc = setconstraint! (mpc, ymin= [- 54 ], ymax= [56 ])
266266 @test mpc. Yop ≈ fill (10.0 , 1000 )
286286 r = [40 ]
287287 u = moveinput! (mpc, r)
288288 @test u ≈ [13 ] atol= 1e-2
289+ setmodel! (mpc, Mwt= [100 ], Nwt= [200 ], Lwt= [300 ])
290+ @test mpc. M_Hp ≈ diagm (fill (100 , 1000 ))
291+ @test mpc. Ñ_Hc ≈ diagm ([200 , 1e4 ])
292+ @test mpc. L_Hp ≈ diagm (fill (300 , 1000 ))
289293 setmodel! (mpc, M_Hp= diagm (1 : 1000 ), Ñ_Hc= diagm ([0.1 ;1e6 ]), L_Hp= diagm (1.1 : 1000.1 ))
290294 @test mpc. M_Hp ≈ diagm (1 : 1000 )
291295 @test mpc. Ñ_Hc ≈ diagm ([0.1 ;1e6 ])
417421 r = [40 ]
418422 u = moveinput! (mpc, r)
419423 @test u ≈ [13 ] atol= 1e-2
424+ setmodel! (mpc, Mwt= [100 ], Nwt= [200 ], Lwt= [300 ])
425+ @test mpc. M_Hp ≈ diagm (fill (100 , 1000 ))
426+ @test mpc. Ñ_Hc ≈ diagm ([200 ])
427+ @test mpc. L_Hp ≈ diagm (fill (300 , 1000 ))
420428 setmodel! (mpc, M_Hp= diagm (1 : 1000 ), Ñ_Hc= [0.1 ], L_Hp= diagm (1.1 : 1000.1 ))
421429 @test mpc. M_Hp ≈ diagm (1 : 1000 )
422430 @test mpc. Ñ_Hc ≈ [0.1 ]
694702
695703@testset " NonLinMPC set model" begin
696704 estim = KalmanFilter (setop! (LinModel (tf (5 , [2 , 1 ]), 3 ), yop= [10 ], uop= [1 ]))
697- mpc = NonLinMPC (estim, Nwt= [0 ], Hp= 1000 , Hc= 1 )
705+ mpc = NonLinMPC (estim, Nwt= [0 ], Cwt = 1e4 , Hp= 1000 , Hc= 1 )
698706 mpc = setconstraint! (mpc, umin= [- 24 ], umax= [26 ])
699707 mpc = setconstraint! (mpc, ymin= [- 54 ], ymax= [56 ])
700708 @test mpc. Yop ≈ fill (10.0 , 1000 )
@@ -720,17 +728,25 @@ end
720728 r = [40 ]
721729 u = moveinput! (mpc, r)
722730 @test u ≈ [13 ] atol= 1e-2
731+ setmodel! (mpc, Mwt= [100 ], Nwt= [200 ], Lwt= [300 ])
732+ @test mpc. M_Hp ≈ diagm (fill (100 , 1000 ))
733+ @test mpc. Ñ_Hc ≈ diagm ([200 , 1e4 ])
734+ @test mpc. L_Hp ≈ diagm (fill (300 , 1000 ))
723735 setmodel! (mpc, M_Hp= diagm (1 : 1000 ), Ñ_Hc= diagm ([0.1 ;1e6 ]), L_Hp= diagm (1.1 : 1000.1 ))
724736 @test mpc. M_Hp ≈ diagm (1 : 1000 )
725737 @test mpc. Ñ_Hc ≈ diagm ([0.1 ;1e6 ])
726738 @test mpc. L_Hp ≈ diagm (1.1 : 1000.1 )
727739 f (x,u,d) = estim. model. A* x + estim. model. Bu* u + estim. model. Bd* d
728740 h (x,d) = estim. model. C* x + estim. model. Du* d
729741 nonlinmodel = NonLinModel (f, h, 10.0 , 1 , 1 , 1 )
730- nmpc = NonLinMPC (nonlinmodel, Hp= 1000 , Hc= 1 )
731- setmodel! (nmpc, M_Hp= diagm (1 : 1000 ), Ñ_Hc= diagm ([0.1 ;1e6 ]), L_Hp= diagm (1.1 : 1000.1 ))
742+ nmpc = NonLinMPC (nonlinmodel, Nwt= [0 ], Cwt= 1e4 , Hp= 1000 , Hc= 10 )
743+ setmodel! (nmpc, Mwt= [100 ], Nwt= [200 ], Lwt= [300 ])
744+ @test nmpc. M_Hp ≈ diagm (fill (100 , 1000 ))
745+ @test nmpc. Ñ_Hc ≈ diagm ([fill (200 , 10 ); 1e4 ])
746+ @test nmpc. L_Hp ≈ diagm (fill (300 , 1000 ))
747+ setmodel! (nmpc, M_Hp= diagm (1 : 1000 ), Ñ_Hc= diagm ([fill (0.1 , 10 );1e6 ]), L_Hp= diagm (1.1 : 1000.1 ))
732748 @test nmpc. M_Hp ≈ diagm (1 : 1000 )
733- @test nmpc. Ñ_Hc ≈ diagm ([0.1 ;1e6 ])
749+ @test nmpc. Ñ_Hc ≈ diagm ([fill ( 0.1 , 10 ) ;1e6 ])
734750 @test nmpc. L_Hp ≈ diagm (1.1 : 1000.1 )
735751 @test_throws ErrorException setmodel! (nmpc, deepcopy (nonlinmodel))
736752end
0 commit comments