Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,28 @@ discrete-time systems that assume a fixed sample time, such as PID controllers a
filters.
""" SolverStepClock

isclock(c) = isa(c, TimeDomain) && @match c begin
isclock(c::TimeDomain) = @match c begin
PeriodicClock() => true
_ => false
end

issolverstepclock(c) = isa(c, TimeDomain) && @match c begin
issolverstepclock(c::TimeDomain) = @match c begin
SolverStepClock() => true
_ => false
end

iscontinuous(c) = isa(c, TimeDomain) && @match c begin
iscontinuous(c::TimeDomain) = @match c begin
ContinuousClock() => true
_ => false
end

is_discrete_time_domain(c) = !iscontinuous(c)
is_discrete_time_domain(c::TimeDomain) = !iscontinuous(c)

# workaround for https://github.com/Roger-luo/Moshi.jl/issues/43
isclock(::Any) = false
issolverstepclock(::Any) = false
iscontinuous(::Any) = false
is_discrete_time_domain(::Any) = false

function first_clock_tick_time(c, t0)
@match c begin
Expand Down
1 change: 1 addition & 0 deletions test/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using MLStyle: @match
@test is_discrete_time_domain(PeriodicClock(; dt = 1.0))
@test !is_discrete_time_domain(Continuous())
@test is_discrete_time_domain(SolverStepClock())
@test !is_discrete_time_domain(nothing)

@test first_clock_tick_time(PeriodicClock(; dt = 2.0), 5.0) === 6.0
@test_throws ErrorException first_clock_tick_time(Continuous(), 5.0)
Expand Down
Loading