@@ -74,3 +74,59 @@ d2 = Clock(t, dt2)
74
74
@test varmap[x] == Continuous ()
75
75
@test varmap[y] == Continuous ()
76
76
@test varmap[u] == Continuous ()
77
+
78
+ @info " test composed systems"
79
+
80
+ dt = 0.5
81
+ @variables t
82
+ d = Clock (t, dt)
83
+ k = ShiftIndex (d)
84
+ timevec = 0 : 0.1 : 4
85
+
86
+ function plant (; name)
87
+ @variables x (t)= 1 u (t)= 0 y (t)= 0
88
+ D = Differential (t)
89
+ eqs = [D (x) ~ - x + u
90
+ y ~ x]
91
+ ODESystem (eqs, t; name = name)
92
+ end
93
+
94
+ function filt (; name)
95
+ @variables x (t)= 0 u (t)= 0 y (t)= 0
96
+ a = 1 / exp (dt)
97
+ eqs = [x (k + 1 ) ~ a * x + (1 - a) * u (k)
98
+ y ~ x]
99
+ ODESystem (eqs, t, name = name)
100
+ end
101
+
102
+ function controller (kp; name)
103
+ @variables y (t)= 0 r (t)= 0 ud (t)= 0 yd (t)= 0
104
+ @parameters kp = kp
105
+ eqs = [yd ~ Sample (y)
106
+ ud ~ kp * (r - yd)]
107
+ ODESystem (eqs, t; name = name)
108
+ end
109
+
110
+ @named f = filt ()
111
+ @named c = controller (1 )
112
+ @named p = plant ()
113
+
114
+ connections = [f. u ~ - 1 # (t >= 1) # step input
115
+ f. y ~ c. r # filtered reference to controller reference
116
+ Hold (c. ud) ~ p. u # controller output to plant input
117
+ p. y ~ c. y]
118
+
119
+ @named cl = ODESystem (connections, t, systems = [f, c, p])
120
+
121
+ ci, varmap = infer_clocks (cl)
122
+
123
+ @test varmap[f. x] == Clock (t, 0.5 )
124
+ @test varmap[p. x] == Continuous ()
125
+ @test varmap[p. y] == Continuous ()
126
+ @test varmap[c. ud] == Clock (t, 0.5 )
127
+ @test varmap[c. yd] == Clock (t, 0.5 )
128
+ @test varmap[c. y] == Continuous ()
129
+ @test varmap[f. y] == Clock (t, 0.5 )
130
+ @test varmap[f. u] == Clock (t, 0.5 )
131
+ @test varmap[p. u] == Continuous ()
132
+ @test varmap[c. r] == Clock (t, 0.5 )
0 commit comments