Skip to content

Commit

Permalink
Merge branch 'master' into plotly2
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Sep 27, 2020
2 parents e79bc51 + cff0e96 commit 559cec3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: julia
julia:
- 1.0
- 1.3
- 1.5
- nightly
matrix:
allow_failures:
- julia: 1.3
- julia: nightly
fast_finish: true
notifications:
Expand Down
30 changes: 18 additions & 12 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,13 @@ function delaymargin(G::LTISystem)
dₘ
end

"""`S,D,N,T = gangoffour(P,C)`, `gangoffour(P::AbstractVector,C::AbstractVector)`
"""
S,D,N,T = gangoffour(P,C; minimal=true)
gangoffour(P::AbstractVector,C::AbstractVector; minimal=true)
Given a transfer function describing the Plant `P` and a transfer function describing the controller `C`, computes the four transfer functions in the Gang-of-Four.
Given a transfer function describing the Plant `P` and a transferfunction describing the controller `C`, computes the four transfer functions in the Gang-of-Four.
`minimal` determines whether or not to call `minreal` on the computed systems.
`S = 1/(1+PC)` Sensitivity function
Expand All @@ -464,29 +468,31 @@ Given a transfer function describing the Plant `P` and a transferfunction descri
`T = PC/(1+PC)` Complementary sensitivity function
Only supports SISO systems"""
function gangoffour(P::LTISystem,C::LTISystem)
function gangoffour(P::LTISystem,C::LTISystem; minimal=true)
if P.nu + P.ny + C.nu + C.ny > 4
error("gangoffour only supports SISO systems")
end
S = minreal(1/(1+P*C))
D = minreal(P*S)
N = minreal(C*S)
T = minreal(P*N)
minfun = minimal ? minreal : identity
S = (1/(1+P*C)) |> minfun
D = (P*S) |> minfun
N = (C*S) |> minfun
T = (P*N) |> minfun
return S, D, N, T
end


function gangoffour(P::AbstractVector, C::AbstractVector)
function gangoffour(P::AbstractVector, C::AbstractVector; minimal=true)
Base.depwarn("Deprecrated use of gangoffour(::Vector, ::Vector), use `broadcast` and `zip` instead", :gangoffour)
if P[1].nu + P[1].ny + C[1].nu + C[1].ny > 4
error("gangoffour only supports SISO systems")
end
length(P) == length(C) || error("P has to be the same length as C")
minfun = minimal ? minreal : identity
n = length(P)
S = [minreal(1/(1+P[i]*C[i])) for i in 1:n]
D = [minreal(P[i]*S[i]) for i in 1:n]
N = [minreal(C[i]*S[i]) for i in 1:n]
T = [minreal(P[i]*N[i]) for i in 1:n]
S = [minfun(1/(1+P[i]*C[i])) for i in 1:n]
D = [minfun(P[i]*S[i]) for i in 1:n]
N = [minfun(C[i]*S[i]) for i in 1:n]
T = [minfun(P[i]*N[i]) for i in 1:n]
return S, D, N, T
end

Expand Down
5 changes: 3 additions & 2 deletions src/timeresp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function lsim(sys::StateSpace, u::AbstractVecOrMat, t::AbstractVector;
dsys, x0map = c2d(sys, dt, :foh)
x0 = x0map*[x0; transpose(u[1:1,:])]
end
x = ltitr(dsys.A, dsys.B, Float64.(u), Float64.(x0))
x = ltitr(dsys.A, dsys.B, u, x0)
y = transpose(sys.C*transpose(x) + sys.D*transpose(u))
return y, t, x
end
Expand Down Expand Up @@ -191,7 +191,8 @@ If `u` is a function, then `u(x,i)` is called to calculate the control signal ev
function ltitr(A::AbstractMatrix{T}, B::AbstractMatrix{T}, u::AbstractVecOrMat,
x0::VecOrMat=zeros(T, size(A, 1))) where T
n = size(u, 1)
x = similar(A, size(A, 1), n)
S = promote_type(T, eltype(x0), eltype(u)) # Useful if either eltype is Dual
x = Array{S}(undef, size(A, 1), n)
for i=1:n
x[:,i] = x0
x0 = A * x0 + B * u[i,:]
Expand Down
11 changes: 6 additions & 5 deletions src/types/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function convert(::Type{TransferFunction{TE,S}}, G::TransferFunction) where {TE,
return TransferFunction{TE,eltype(Gnew_matrix)}(Gnew_matrix, TE(G.timeevol))
end

function convert(::Type{S}, sys::StateSpace) where {T, MT, TE, S <:StateSpace{TE,T,MT}}
function convert(::Type{S}, sys::AbstractStateSpace) where {T, MT, TE, S <:StateSpace{TE,T,MT}}
if sys isa S
return sys
else
Expand All @@ -78,7 +78,10 @@ Base.convert(::Type{HeteroStateSpace{TE1,AT,BT,CT,DT}}, s::StateSpace{TE2,T,MT})

Base.convert(::Type{HeteroStateSpace}, s::StateSpace) = HeteroStateSpace(s)

Base.convert(::Type{StateSpace}, s::HeteroStateSpace) = StateSpace(s.A, s.B, s.C, s.D, s.Ts)

function Base.convert(::Type{StateSpace}, G::TransferFunction{TE,<:SisoTf{T0}}) where {TE,T0<:Number}

T = Base.promote_op(/,T0,T0)
convert(StateSpace{TE,T,Matrix{T}}, G)
end
Expand Down Expand Up @@ -243,9 +246,9 @@ end
balance_transform(sys::StateSpace, perm::Bool=false) = balance_transform(sys.A,sys.B,sys.C,perm)


convert(::Type{TransferFunction}, sys::StateSpace{TE}) where TE = convert(TransferFunction{TE,SisoRational}, sys)
convert(::Type{TransferFunction}, sys::AbstractStateSpace{TE}) where TE = convert(TransferFunction{TE,SisoRational}, sys)

function convert(::Type{TransferFunction{TE,SisoRational{T}}}, sys::StateSpace) where {TE,T<:Number}
function convert(::Type{TransferFunction{TE,SisoRational{T}}}, sys::AbstractStateSpace) where {TE,T<:Number}
matrix = Matrix{SisoRational{T}}(undef, size(sys))

A, B, C, D = ssdata(sys)
Expand All @@ -270,8 +273,6 @@ end
function convert(::Type{TransferFunction{TE,SisoZpk{T,TR}}}, sys::StateSpace) where {TE,T<:Number, TR <: Number}
matrix = Matrix{SisoZpk{T,TR}}(undef, size(sys))

A, B, C, D = ssdata(sys)

for i=1:noutputs(sys), j=1:ninputs(sys)
z, p, k = siso_ss_to_zpk(sys, i, j)
matrix[i, j] = SisoZpk{T,TR}(z, p, k)
Expand Down
2 changes: 1 addition & 1 deletion src/types/tf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tf(D::AbstractArray{T}) where T = tf(D, Continuous())

tf(n::Number, args...; kwargs...) = tf([n], args...; kwargs...)

tf(sys::StateSpace) = convert(TransferFunction, sys) # NOTE: Would perhaps like to write TransferFunction{SisoRational}, but couldn't get this to work...
tf(sys::AbstractStateSpace) = convert(TransferFunction, sys) # NOTE: Would perhaps like to write TransferFunction{SisoRational}, but couldn't get this to work...

function tf(G::TransferFunction{TE,<:SisoTf{T}}) where {TE<:TimeEvolution,T<:Number}
convert(TransferFunction{TE,SisoRational{T}}, G)
Expand Down
1 change: 1 addition & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ numeric_type(sys::SisoTf) = numeric_type(typeof(sys))

numeric_type(::Type{TransferFunction{TE,S}}) where {TE,S} = numeric_type(S)
numeric_type(::Type{<:StateSpace{TE,T}}) where {TE,T} = T
numeric_type(::Type{<:HeteroStateSpace{TE,AT}}) where {TE,AT} = eltype(AT)
numeric_type(::Type{<:DelayLtiSystem{T}}) where {T} = T
numeric_type(sys::LTISystem) = numeric_type(typeof(sys))

Expand Down

0 comments on commit 559cec3

Please sign in to comment.