1- Ts = 4.0
2- sys = [ tf (1.90 ,[18.0 ,1 ]) tf (1.90 ,[18.0 ,1 ]) tf (1.90 ,[18.0 ,1 ]);
3- tf (- 0.74 ,[8.0 ,1 ]) tf (0.74 ,[8.0 ,1 ]) tf (- 0.74 ,[8.0 ,1 ]) ]
4- sys_ss = minreal (ss (sys))
5- Gss = c2d (sys_ss[:,1 : 2 ], Ts, :zoh )
6- Gss2 = c2d (sys_ss[:,1 : 2 ], 0.5 Ts, :zoh )
7-
8- @testset " LinModel construction" begin
1+ @testitem " LinModel construction" setup= [SetupMPCtests] begin
2+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
93 linmodel1 = LinModel (sys, Ts, i_u= 1 : 2 )
104 @test linmodel1. nx == 2
115 @test linmodel1. nu == 2
@@ -29,7 +23,7 @@ Gss2 = c2d(sys_ss[:,1:2], 0.5Ts, :zoh)
2923 @test linmodel2. dop ≈ zeros (0 ,1 )
3024
3125 linmodel3 = LinModel (Gss, 0.5 Ts)
32- @test linmodel3. Ts == 2 .0
26+ @test linmodel3. Ts == 200 .0
3327 @test linmodel3. A ≈ Gss2. A
3428 @test linmodel3. C ≈ Gss2. C
3529
@@ -55,7 +49,7 @@ Gss2 = c2d(sys_ss[:,1:2], 0.5Ts, :zoh)
5549 @test linmodel5. yop ≈ [50 ,30 ]
5650 @test linmodel5. dop ≈ [20 ]
5751
58- linmodel6 = LinModel ([delay (4 ) delay (4 )]* sys,Ts,i_d= [3 ])
52+ linmodel6 = LinModel ([delay (Ts ) delay (Ts )]* sys,Ts,i_d= [3 ])
5953 @test linmodel6. nx == 3
6054 @test sum (eigvals (linmodel6. A) .≈ 0 ) == 1
6155
@@ -103,7 +97,8 @@ Gss2 = c2d(sys_ss[:,1:2], 0.5Ts, :zoh)
10397 @test_throws ErrorException LinModel (sys_ss,Ts)
10498end
10599
106- @testset " LinModel sim methods" begin
100+ @testitem " LinModel sim methods" setup= [SetupMPCtests] begin
101+ using . SetupMPCtests, ControlSystemsBase
107102 linmodel1 = setop! (LinModel (Gss), uop= [10 ,50 ], yop= [50 ,30 ])
108103 @test updatestate! (linmodel1, [10 , 50 ]) ≈ zeros (2 )
109104 @test updatestate! (linmodel1, [10 , 50 ], Float64[]) ≈ zeros (2 )
@@ -123,26 +118,28 @@ end
123118 @test_throws DimensionMismatch evaloutput (linmodel1, zeros (1 ))
124119end
125120
126- @testset " LinModel real time simulations" begin
127- linmodel1 = LinModel (tf (2 , [10 , 1 ]), 0.1 )
121+ @testitem " LinModel real time simulations" setup= [SetupMPCtests] begin
122+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
123+ linmodel1 = LinModel (tf (2 , [10 , 1 ]), 0.25 )
128124 times1 = zeros (5 )
129125 for i= 1 : 5
130126 times1[i] = savetime! (linmodel1)
131127 updatestate! (linmodel1, [1 ])
132128 periodsleep (linmodel1)
133129 end
134- @test all (isapprox .(diff (times1[2 : end ]), 0.1 , atol= 0.01 ))
135- linmodel2 = LinModel (tf (2 , [0.1 , 1 ]), 0.001 )
130+ @test all (isapprox .(diff (times1[2 : end ]), 0.25 , atol= 0.01 ))
131+ linmodel2 = LinModel (tf (2 , [0.1 , 1 ]), 0.25 )
136132 times2 = zeros (5 )
137133 for i= 1 : 5
138134 times2[i] = savetime! (linmodel2)
139135 updatestate! (linmodel2, [1 ])
140136 periodsleep (linmodel2, true )
141137 end
142- @test all (isapprox .(diff (times2[2 : end ]), 0.001 , atol= 0.0001 ))
138+ @test all (isapprox .(diff (times2[2 : end ]), 0.25 , atol= 0.0001 ))
143139end
144140
145- @testset " NonLinModel construction" begin
141+ @testitem " NonLinModel construction" setup= [SetupMPCtests] begin
142+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
146143 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
147144 f1 (x,u,_,model) = model. A* x + model. Bu* u
148145 h1 (x,_,model) = model. C* x
249246 (x,_)-> linmodel1. C* x, Ts, 2 , 4 , 2 , 1 , solver= nothing )
250247end
251248
252- @testset " NonLinModel sim methods" begin
249+ @testitem " NonLinModel sim methods" setup= [SetupMPCtests] begin
250+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
253251 linmodel1 = LinModel (sys,Ts,i_u= [1 ,2 ])
254252 f1 (x,u,_,model) = model. A* x + model. Bu* u
255253 h1 (x,_,model) = model. C* x
268266 @test_throws DimensionMismatch evaloutput (nonlinmodel, zeros (1 ))
269267end
270268
271- @testset " NonLinModel linearization" begin
269+ @testitem " NonLinModel linearization" setup= [SetupMPCtests] begin
270+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra, ForwardDiff
272271 Ts = 1.0
273272 f1 (x,u,d,_) = x.^ 5 + u.^ 4 + d.^ 3
274273 h1 (x,d,_) = x.^ 2 + d
@@ -313,17 +312,18 @@ end
313312 linmodel3 = linearize (nonlinmodel3; x, u, d)
314313 for i= 1 : N
315314 ynl = nonlinmodel3 (d)
316- yl = linmodel3 (d)
315+ global yl = linmodel3 (d)
317316 Ynl[i] = ynl[1 ]
318317 Yl[i] = yl[1 ]
319- linmodel3 = linearize (nonlinmodel3; u, d)
318+ global linmodel3 = linearize (nonlinmodel3; u, d)
320319 updatestate! (nonlinmodel3, u, d)
321320 updatestate! (linmodel3, u, d)
322321 end
323322 @test all (isapprox .(Ynl, Yl, atol= 1e-6 ))
324323end
325324
326- @testset " NonLinModel real time simulations" begin
325+ @testitem " NonLinModel real time simulations" setup= [SetupMPCtests] begin
326+ using . SetupMPCtests, ControlSystemsBase, LinearAlgebra
327327 linmodel1 = LinModel (tf (2 , [10 , 1 ]), 0.1 )
328328 nonlinmodel1 = NonLinModel (
329329 (x,u,_,_)-> linmodel1. A* x + linmodel1. Bu* u,
0 commit comments