1
1
using ModelingToolkit, OrdinaryDiffEq, LinearAlgebra, ControlSystemsBase
2
2
using ModelingToolkitStandardLibrary. Mechanical. Rotational
3
3
using ModelingToolkitStandardLibrary. Blocks
4
- using ModelingToolkit: connect, AnalysisPoint, t_nounits as t, D_nounits as D
4
+ using ModelingToolkit: connect, AnalysisPoint, t_nounits as t, D_nounits as D,
5
+ get_sensitivity, get_comp_sensitivity, get_looptransfer, open_loop
5
6
import ControlSystemsBase as CS
6
7
7
8
@testset " Complicated model" begin
@@ -154,10 +155,10 @@ end
154
155
t,
155
156
systems = [P_outer, sys_inner])
156
157
157
- Souter = sminreal (ss (get_sensitivity (sys_outer, :sys_inner_u )[1 ]. .. ))
158
+ Souter = sminreal (ss (get_sensitivity (sys_outer, sys_inner . u )[1 ]. .. ))
158
159
159
160
Sinner2 = sminreal (ss (get_sensitivity (
160
- sys_outer, :sys_inner_u , loop_openings = [:y2 ])[1 ]. .. ))
161
+ sys_outer, sys_inner . u , loop_openings = [:y2 ])[1 ]. .. ))
161
162
162
163
@test Sinner. nx == 1
163
164
@test Sinner == Sinner2
@@ -183,23 +184,23 @@ end
183
184
connect (K. output, :plant_input , P. input)]
184
185
sys = ODESystem (eqs, t, systems = [P, K], name = :hej )
185
186
186
- matrices, _ = Blocks . get_sensitivity (sys, :plant_input )
187
+ matrices, _ = get_sensitivity (sys, :plant_input )
187
188
S = CS. feedback (I (2 ), Kss * Pss, pos_feedback = true )
188
189
189
190
@test CS. tf (CS. ss (matrices... )) ≈ CS. tf (S)
190
191
191
- matrices, _ = Blocks . get_comp_sensitivity (sys, :plant_input )
192
+ matrices, _ = get_comp_sensitivity (sys, :plant_input )
192
193
T = - CS. feedback (Kss * Pss, I (2 ), pos_feedback = true )
193
194
194
195
# bodeplot([ss(matrices...), T])
195
196
@test CS. tf (CS. ss (matrices... )) ≈ CS. tf (T)
196
197
197
- matrices, _ = Blocks . get_looptransfer (
198
+ matrices, _ = get_looptransfer (
198
199
sys, :plant_input )
199
200
L = Kss * Pss
200
201
@test CS. tf (CS. ss (matrices... )) ≈ CS. tf (L)
201
202
202
- matrices, _ = linearize (sys, :plant_input , :plant_output )
203
+ matrices, _ = linearize (sys, AnalysisPoint ( :plant_input ) , :plant_output )
203
204
G = CS. feedback (Pss, Kss, pos_feedback = true )
204
205
@test CS. tf (CS. ss (matrices... )) ≈ CS. tf (G)
205
206
end
@@ -222,12 +223,53 @@ end
222
223
connect (F. output, sys_inner. add. input1)]
223
224
sys_outer = ODESystem (eqs, t, systems = [F, sys_inner, r], name = :outer )
224
225
225
- matrices, _ = get_sensitivity (sys_outer, [:, :inner_plant_output ])
226
+ matrices, _ = get_sensitivity (
227
+ sys_outer, [sys_outer. inner. plant_input, sys_outer. inner. plant_output])
226
228
227
229
Ps = tf (1 , [1 , 1 ]) |> ss
228
230
Cs = tf (1 ) |> ss
229
231
230
232
G = CS. ss (matrices... ) |> sminreal
231
233
Si = CS. feedback (1 , Cs * Ps)
232
234
@test tf (G[1 , 1 ]) ≈ tf (Si)
235
+
236
+ So = CS. feedback (1 , Ps * Cs)
237
+ @test tf (G[2 , 2 ]) ≈ tf (So)
238
+ @test tf (G[1 , 2 ]) ≈ tf (- CS. feedback (Cs, Ps))
239
+ @test tf (G[2 , 1 ]) ≈ tf (CS. feedback (Ps, Cs))
240
+
241
+ matrices, _ = get_comp_sensitivity (
242
+ sys_outer, [sys_outer. inner. plant_input, sys_outer. inner. plant_output])
243
+
244
+ G = CS. ss (matrices... ) |> sminreal
245
+ Ti = CS. feedback (Cs * Ps)
246
+ @test tf (G[1 , 1 ]) ≈ tf (Ti)
247
+
248
+ To = CS. feedback (Ps * Cs)
249
+ @test tf (G[2 , 2 ]) ≈ tf (To)
250
+ @test tf (G[1 , 2 ]) ≈ tf (CS. feedback (Cs, Ps)) # The negative sign appears in a confusing place due to negative feedback not happening through Ps
251
+ @test tf (G[2 , 1 ]) ≈ tf (- CS. feedback (Ps, Cs))
252
+
253
+ # matrices, _ = get_looptransfer(sys_outer, [:inner_plant_input, :inner_plant_output])
254
+ matrices, _ = get_looptransfer (sys_outer, sys_outer. inner. plant_input)
255
+ L = CS. ss (matrices... ) |> sminreal
256
+ @test tf (L) ≈ - tf (Cs * Ps)
257
+
258
+ matrices, _ = get_looptransfer (sys_outer, sys_outer. inner. plant_output)
259
+ L = CS. ss (matrices... ) |> sminreal
260
+ @test tf (L[1 , 1 ]) ≈ - tf (Ps * Cs)
261
+
262
+ # Calling looptransfer like below is not the intended way, but we can work out what it should return if we did so it remains a valid test
263
+ matrices, _ = get_looptransfer (
264
+ sys_outer, [sys_outer. inner. plant_input, sys_outer. inner. plant_output])
265
+ L = CS. ss (matrices... ) |> sminreal
266
+ @test tf (L[1 , 1 ]) ≈ tf (0 )
267
+ @test tf (L[2 , 2 ]) ≈ tf (0 )
268
+ @test sminreal (L[1 , 2 ]) ≈ ss (- 1 )
269
+ @test tf (L[2 , 1 ]) ≈ tf (Ps)
270
+
271
+ matrices, _ = linearize (
272
+ sys_outer, [sys_outer. inner. plant_input], [sys_inner. plant_output])
273
+ G = CS. ss (matrices... ) |> sminreal
274
+ @test tf (G) ≈ tf (CS. feedback (Ps, Cs))
233
275
end
0 commit comments