Skip to content

Commit 5d13ee9

Browse files
feat: allow namespacing statemachine equations
1 parent 95f9fdd commit 5d13ee9

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ function namespace_expr(
12071207
O
12081208
end
12091209
end
1210+
12101211
_nonum(@nospecialize x) = x isa Num ? x.val : x
12111212

12121213
"""

src/systems/state_machines.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,36 @@ entry
153153
154154
When used in a finite state machine, this operator returns `true` if the queried state is active and false otherwise.
155155
""" activeState
156+
157+
function vars!(vars, O::Transition; op = Differential)
158+
vars!(vars, O.from)
159+
vars!(vars, O.to)
160+
vars!(vars, O.cond; op)
161+
return vars
162+
end
163+
function vars!(vars, O::InitialState; op = Differential)
164+
vars!(vars, O.s; op)
165+
return vars
166+
end
167+
function vars!(vars, O::StateMachineOperator; op = Differential)
168+
error("Unhandled state machine operator")
169+
end
170+
171+
function namespace_expr(
172+
O::Transition, sys, n = nameof(sys); ivs = independent_variables(sys))
173+
return Transition(
174+
O.from === nothing ? O.from : renamespace(sys, O.from),
175+
O.to === nothing ? O.to : renamespace(sys, O.to),
176+
O.cond === nothing ? O.cond : namespace_expr(O.cond, sys),
177+
O.immediate, O.reset, O.synchronize, O.priority
178+
)
179+
end
180+
181+
function namespace_expr(
182+
O::InitialState, sys, n = nameof(sys); ivs = independent_variables(sys))
183+
return InitialState(O.s === nothing ? O.s : renamespace(sys, O.s))
184+
end
185+
186+
function namespace_expr(O::StateMachineOperator, sys, n = nameof(sys); kwargs...)
187+
error("Unhandled state machine operator")
188+
end

src/utils.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ vars(eq::Equation; op = Differential) = vars!(Set(), eq; op = op)
391391
function vars!(vars, eq::Equation; op = Differential)
392392
(vars!(vars, eq.lhs; op = op); vars!(vars, eq.rhs; op = op); vars)
393393
end
394+
function vars!(vars, O::AbstractSystem; op = Differential)
395+
for eq in equations(O)
396+
vars!(vars, eq; op)
397+
end
398+
return vars
399+
end
394400
function vars!(vars, O; op = Differential)
395401
if isvariable(O)
396402
if iscall(O) && operation(O) === getindex && iscalledparameter(first(arguments(O)))

0 commit comments

Comments
 (0)