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
2 changes: 1 addition & 1 deletion src/types/Lti.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function Base.getproperty(sys::LTISystem, s::Symbol)
end

Base.propertynames(sys::LTISystem, private::Bool=false) =
(fieldnames(typeof(sys))..., (isdiscrete(sys) ? (:Ts,) : ())...)
(fieldnames(typeof(sys))..., :nu, :ny, (isdiscrete(sys) ? (:Ts,) : ())...)



Expand Down
4 changes: 4 additions & 0 deletions src/types/PartionedStateSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function getproperty(sys::PartionedStateSpace, d::Symbol)
end
end

function Base.propertynames(s::PartionedStateSpace, private::Bool=false)
(fieldnames(typeof(s))..., :B1, :B2, :C1, :C2, :D11, :D12, :D21, :D22, :nu, :ny, :nx, (isdiscrete(s) ? (:Ts,) : ())...)
end

timeevol(sys::PartionedStateSpace) = timeevol(sys.P)

function +(s1::PartionedStateSpace, s2::PartionedStateSpace)
Expand Down
4 changes: 4 additions & 0 deletions src/types/StateSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ function Base.getproperty(sys::AbstractStateSpace, s::Symbol)
end
end

function Base.propertynames(s::AbstractStateSpace, private::Bool=false)
(fieldnames(typeof(s))..., :nu, :ny, :nx, (isdiscrete(s) ? (:Ts,) : ())...)
end

#####################################################################
## Display Functions ##
#####################################################################
Expand Down
28 changes: 21 additions & 7 deletions src/types/TransferFunction.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
struct TransferFunction{TE, S<:SisoTf{T} where T} <: LTISystem{TE}
matrix::Matrix{S}
timeevol::TE
nu::Int
ny::Int
function TransferFunction{TE,S}(matrix::Matrix{S}, timeevol::TE) where {S,TE}
# Validate size of input and output names
ny, nu = size(matrix)
return new{TE,S}(matrix, timeevol, nu, ny)
return new{TE,S}(matrix, timeevol)
end
end
function TransferFunction(matrix::Matrix{S}, timeevol::TE) where {TE<:TimeEvolution, T<:Number, S<:SisoTf{T}}
Expand Down Expand Up @@ -35,6 +33,22 @@ Base.size(G::TransferFunction) = size(G.matrix)
Base.eltype(::Type{S}) where {S<:TransferFunction} = S
Base.zero(G::TransferFunction{TE,S}) where {TE,S} = tf(zeros(numeric_type(S), size(G)), G.timeevol) # can not create a zero of a discrete system from the type alone, the sampletime is not stored.

function Base.getproperty(G::TransferFunction, s::Symbol)
s ∈ fieldnames(typeof(G)) && return getfield(G, s)
if s === :ny
return size(G, 1)
elseif s === :nu
return size(G, 2)
elseif s === :Ts
if isdiscrete(G)
return timeevol(G).Ts
else
@warn "Getting time 0.0 for non-discrete systems is deprecated. Check `isdiscrete` before trying to access time."
return 0.0
end
throw(ArgumentError("$(typeof(G)) has no property named $s"))
end
end

function Base.getindex(G::TransferFunction{TE,S}, inds...) where {TE,S<:SisoTf}
if size(inds, 1) != 2
Expand Down Expand Up @@ -82,9 +96,9 @@ end

## EQUALITY ##
function ==(G1::TransferFunction, G2::TransferFunction)
fields = [:timeevol, :ny, :nu, :matrix]
fields = (:timeevol, :ny, :nu, :matrix)
for field in fields
if getfield(G1, field) != getfield(G2, field)
if getproperty(G1, field) != getproperty(G2, field)
return false
end
end
Expand All @@ -94,9 +108,9 @@ end
## Approximate ##
function isapprox(G1::TransferFunction, G2::TransferFunction; kwargs...)
G1, G2 = promote(G1, G2)
fieldsApprox = [:timeevol, :matrix]
fieldsApprox = (:timeevol, :matrix)
for field in fieldsApprox
if !(isapprox(getfield(G1, field), getfield(G2, field); kwargs...))
if !(isapprox(getproperty(G1, field), getproperty(G2, field); kwargs...))
return false
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_delayed_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ w = 10 .^ (-2:0.1:2)
@test freqresp(s11, w) ≈ freqresp(f2[1,1], w) rtol=1e-15


@test propertynames(delay(1.0)) == (:P, :Tau)
@test propertynames(delay(1.0)) == (:P, :Tau, :nu, :ny)


#FIXME: A lot more tests, including MIMO systems in particular
Expand Down
2 changes: 1 addition & 1 deletion test/test_partitioned_statespace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ sys2 = ControlSystems.PartionedStateSpace(ss(fill(1.0, 2, 2), fill(2.0, 2, 5), f
# TODO: Add some tests for interconnections, implicitly tested through delay system implementations though
@test (sys1 + sys1).P[1, 1] == (sys1.P[1,1] + sys1.P[1,1])

@test propertynames(sys1) == (:P, :nu1, :ny1)
@test propertynames(sys1) == (:P, :nu1, :ny1, :B1, :B2, :C1, :C2, :D11, :D12, :D21, :D22, :nu, :ny, :nx)
4 changes: 2 additions & 2 deletions test/test_statespace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
@test D_111.Ts == 0.005

# propertynames
@test propertynames(C_111) == (:A, :B, :C, :D, :timeevol)
@test propertynames(D_111) == (:A, :B, :C, :D, :timeevol, :Ts)
@test propertynames(C_111) == (:A, :B, :C, :D, :timeevol, :nu, :ny, :nx)
@test propertynames(D_111) == (:A, :B, :C, :D, :timeevol, :nu, :ny, :nx, :Ts)

# Printing
if SS <: StateSpace
Expand Down