@@ -2,7 +2,7 @@ using ModelingToolkit, ModelingToolkitStandardLibrary.Blocks
2
2
using OrdinaryDiffEq, LinearAlgebra
3
3
using Test
4
4
using ModelingToolkit: t_nounits as t, D_nounits as D, AnalysisPoint, get_sensitivity,
5
- get_comp_sensitivity, get_looptransfer
5
+ get_comp_sensitivity, get_looptransfer, open_loop, AbstractSystem
6
6
using Symbolics: NAMESPACE_SEPARATOR
7
7
8
8
@testset " AnalysisPoint is lowered to `connect`" begin
@@ -13,14 +13,14 @@ using Symbolics: NAMESPACE_SEPARATOR
13
13
eqs = [connect (P. output, C. input)
14
14
connect (C. output, ap, P. input)]
15
15
sys_ap = ODESystem (eqs, t, systems = [P, C], name = :hej )
16
- sys_ap2 = @test_nowarn expand_connections (sys )
16
+ sys_ap2 = @test_nowarn expand_connections (sys_ap )
17
17
18
18
@test all (eq -> ! (eq. lhs isa AnalysisPoint), equations (sys_ap2))
19
19
20
20
eqs = [connect (P. output, C. input)
21
21
connect (C. output, P. input)]
22
22
sys_normal = ODESystem (eqs, t, systems = [P, C], name = :hej )
23
- sys_normal2 = @test_nowarn expand_connections (sys )
23
+ sys_normal2 = @test_nowarn expand_connections (sys_normal )
24
24
25
25
@test isequal (sys_ap2, sys_normal2)
26
26
end
191
191
@test matrices. B[] * matrices. C[] == 1 # both positive
192
192
@test matrices. D[] == 0
193
193
end
194
-
195
- using ModelingToolkit, OrdinaryDiffEq, LinearAlgebra
196
- using ModelingToolkitStandardLibrary. Mechanical. Rotational
197
- using ModelingToolkitStandardLibrary. Blocks: Sine, PID, SecondOrder, Step, RealOutput
198
- using ModelingToolkit: connect
199
-
200
- @testset " Complicated model" begin
201
- # Parameters
202
- m1 = 1
203
- m2 = 1
204
- k = 1000 # Spring stiffness
205
- c = 10 # Damping coefficient
206
- @named inertia1 = Inertia (; J = m1)
207
- @named inertia2 = Inertia (; J = m2)
208
- @named spring = Spring (; c = k)
209
- @named damper = Damper (; d = c)
210
- @named torque = Torque ()
211
-
212
- function SystemModel (u = nothing ; name = :model )
213
- eqs = [connect (torque. flange, inertia1. flange_a)
214
- connect (inertia1. flange_b, spring. flange_a, damper. flange_a)
215
- connect (inertia2. flange_a, spring. flange_b, damper. flange_b)]
216
- if u != = nothing
217
- push! (eqs, connect (torque. tau, u. output))
218
- return ODESystem (eqs, t;
219
- systems = [
220
- torque,
221
- inertia1,
222
- inertia2,
223
- spring,
224
- damper,
225
- u
226
- ],
227
- name)
228
- end
229
- ODESystem (eqs, t; systems = [torque, inertia1, inertia2, spring, damper], name)
230
- end
231
-
232
- @named r = Step (start_time = 0 )
233
- model = SystemModel ()
234
- @named pid = PID (k = 100 , Ti = 0.5 , Td = 1 )
235
- @named filt = SecondOrder (d = 0.9 , w = 10 )
236
- @named sensor = AngleSensor ()
237
- @named er = Add (k2 = - 1 )
238
-
239
- connections = [connect (r. output, :r , filt. input)
240
- connect (filt. output, er. input1)
241
- connect (pid. ctr_output, :u , model. torque. tau)
242
- connect (model. inertia2. flange_b, sensor. flange)
243
- connect (sensor. phi, :y , er. input2)
244
- connect (er. output, :e , pid. err_input)]
245
-
246
- closed_loop = ODESystem (connections, t, systems = [model, pid, filt, sensor, r, er],
247
- name = :closed_loop , defaults = [
248
- model. inertia1. phi => 0.0 ,
249
- model. inertia2. phi => 0.0 ,
250
- model. inertia1. w => 0.0 ,
251
- model. inertia2. w => 0.0 ,
252
- filt. x => 0.0 ,
253
- filt. xd => 0.0
254
- ])
255
-
256
- sys = structural_simplify (closed_loop)
257
- prob = ODEProblem (sys, unknowns (sys) .=> 0.0 , (0.0 , 4.0 ))
258
- sol = solve (prob, Rodas5P (), reltol = 1e-6 , abstol = 1e-9 )
259
- end
0 commit comments