MathematicalSystems.jl
MathematicalSystems.jl copied to clipboard
Periodic input iterators
In #15 we implement either constant or varying input iterators. An abstraction of an infinitely periodic input could be useful, and maybe it can be implemented by combining Base.IsInfinite()
with an AbstractVector
field.
Not sure, if I understand the concept and the usage of Input
in MathematicalSystems
, but I implemented a periodic input in my MPC
package something like this:
# TODO: make immutable (with Ref)
using TreeViews
using Crayons
mutable struct FixedInput{MT<:AbstractMatrix} <: AbstractController
U::MT
n::Integer
k::Integer
end
function control_input(ctrl::FixedInput)
u = ctrl.U[:, mod(ctrl.k, ctrl.n) + 1]
ctrl.k += 1
return u
end
This would be used as
U = [1 2;
1 2]
input = FixedInput(U, 10, 0)
u1 = control_input(input) # [1, 1]
u2 = control_input(input) # [2, 2]
u3 = control_input(input) # [1, 1]
Maybe this idea can be of use.
Not sure, if I understand the concept and the usage of Input in MathematicalSystems,
We can probably improve the docs, I've commented here. The idea is that this type models an input to a system and it can be iterated over; the concrete interpretation is left for downstream packages. Very much like in your example.