Skip to content

Commit 52785a9

Browse files
YingboMabaggepinnen
andcommitted
Only clocks and continuous are inferred types
Co-authored-by: Fredrik Bagge Carlson <[email protected]>
1 parent 07b477f commit 52785a9

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

src/systems/clock_inference.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ function ClockInference(ts::TearingState)
1414
inferred = Int[]
1515
for (i, v) in enumerate(fullvars)
1616
d = get_time_domain(v)
17-
if d === nothing
18-
dd = Inferred()
19-
else
17+
if d isa Union{AbstractClock, Continuous}
2018
push!(inferred, i)
2119
dd = d
20+
else
21+
dd = Inferred()
2222
end
2323
var_domain[i] = dd
2424
end
@@ -46,9 +46,6 @@ function infer_clocks!(ci::ClockInference)
4646
c = BitSet(c′)
4747
idxs = intersect(c, inferred)
4848
isempty(idxs) && continue
49-
for i in idxs
50-
@show var_domain[i]
51-
end
5249
if !allequal(var_domain[i] for i in idxs)
5350
display(fullvars[c′])
5451
throw(ClockInferenceException("Clocks are not consistent in connected component $(fullvars[c′])"))

test/clock.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,59 @@ d2 = Clock(t, dt2)
7474
@test varmap[x] == Continuous()
7575
@test varmap[y] == Continuous()
7676
@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

Comments
 (0)