Skip to content

Commit

Permalink
Merge 96acc55 into 6312567
Browse files Browse the repository at this point in the history
  • Loading branch information
mfalt committed May 22, 2019
2 parents 6312567 + 96acc55 commit 6d0c937
Show file tree
Hide file tree
Showing 19 changed files with 1,018 additions and 8 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.5.3"
[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
10 changes: 10 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
julia 0.7
Plots
Polynomials
LaTeXStrings
DelayDiffEq
OrdinaryDiffEq
IterTools
Colors
DSP
Interpolations
19 changes: 19 additions & 0 deletions example/delayed_lti_system.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Plots

# Frequency domain analysis of a simple system with time delays

s = tf("s")

P = delay(0.2) * ss(1/(s+1))

K = 3; Ti = 0.3;
C = DelayLtiSystem(ss(K*(1 + 1/s)))

ω = exp10.(LinRange(-2,2,500))

L_fr = freqresp(C*P, ω)[:]
plot(real(L_fr), imag(L_fr), xlim=[-2,1], ylim=[-2,2], title="Nyquist curve")

G_yd = feedback(P, C)
plot(ω, abs.(freqresp(G_yd, ω)[:]), xscale=:log, yscale=:log,
title="Transfer function from load disturbances to output.")
80 changes: 80 additions & 0 deletions example/delayed_lti_timeresp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using ControlSystems, Plots
gr()

sys = feedback(1.0, ss(-1.0, 2, 1, 0) * (delay(2.0) + delay(3.0) + delay(2.5)))
sys = feedback(ss(-1.0, 1, 1, 0), delay(1.0))

t = 0:0.02:8
@time y, t, x = lsim(sys, t-> [t>=0 ? 1.0 : 0.0], t)
@time y, t, x = lsim(sys, [1.0], t)
@time y, t, x = lsim(sys, (out, t) -> (out .= (t>=0 ? 1.0 : 0.0)), t)
@time y, t, x = lsim(sys, (out, t) -> (out[1] = (t>=0 ? 1.0 : 0.0)), t)

function u0(out,t)
if t > 0
out[1] = 1
else
out[1] = 0
end
return
end

@time y, t, x = lsim(sys, u0, t)

plot(t, y')

s = tf("s")
P = delay(2.6)*ss((s+3.0)/(s^2+0.3*s+1))
C = 0.06 * ss(1.0 + 1/s);
P*C
T = feedback(P*C,1.0)

t = 0:0.1:70
y, t, x = lsim(T, t -> (t<0 ? 0 : 1 ), t)
plot(t, y, c = :blue)

w = 10 .^ (-2:0.01:2)
marginplot(P*C, w)
marginplot(P*C)

notch = ss(tf([1, 0.2, 1],[1, .8, 1]));
C = ss(0.05 * (1 + 1/s));
Tnotch = feedback(P*C*notch, 1.0)

stepplot(Tnotch)

y, t, x = step(C, method=:zoh)

y2, t2, x2 = step(Tnotch)
stepplot(Tnotch)

stepplot(Tnotch, 40, 0.1)

stepplot(T, 100)

G = delay(5)/(s+1)
T = feedback(G, 0.5)
w = 10 .^ (-2:0.01:3)
bodeplot(T, w, plotphase=false)

# Test conversion, promotion
delay(1,Int64) + 3.5

G = 1 + 0.5 * delay(3)
w = 10 .^(-2:0.001:2)
bodeplot(G, w, plotphase=false)

G = delay(1) * ((0.8*s^2+s+2)/(s^2+s))
T = feedback(G,1)
# Not possible with direct term
stepplot(T)

bodeplot(T)

G = 1/(s+1) + delay(4)
T = feedback(1,G)
# Not possible to lsim with direct term
stepplot(T)
bodeplot(T)

s = tf("s")
12 changes: 11 additions & 1 deletion src/ControlSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export LTISystem,
StateSpace,
HeteroStateSpace,
TransferFunction,
DelayLtiSystem,
ss,
tf,
zpk,
Expand Down Expand Up @@ -68,6 +69,8 @@ export LTISystem,
bode,
nyquist,
sigma,
# delay systems
delay,
# utilities
num, #Deprecated
den, #Deprecated
Expand All @@ -78,9 +81,11 @@ export LTISystem,


# QUESTION: are these used? LaTeXStrings, Requires, IterTools
using Polynomials, OrdinaryDiffEq, Plots, LaTeXStrings, LinearAlgebra
using Polynomials, Plots, LaTeXStrings, LinearAlgebra
using OrdinaryDiffEq, DelayDiffEq
export Plots
import Base: +, -, *, /, (==), (!=), isapprox, convert, promote_op
import Base: getproperty
import LinearAlgebra: BlasFloat
export lyap # Make sure LinearAlgebra.lyap is available
import Printf, Colors
Expand All @@ -102,6 +107,9 @@ include("types/SisoTfTypes/conversion.jl")

include("types/StateSpace.jl")

include("types/PartionedStateSpace.jl")
include("types/DelayLtiSystem.jl")

# Convenience constructors
include("types/tf.jl")
include("types/zpk.jl")
Expand All @@ -128,6 +136,8 @@ include("synthesis.jl")
include("simulators.jl")
include("pid_design.jl")

include("delay_systems.jl")

include("plotting.jl")

@deprecate num numvec
Expand Down
20 changes: 20 additions & 0 deletions src/connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ end

append(systems::LTISystem...) = append(promote(systems...)...)


function Base.vcat(systems::DelayLtiSystem...)
P = vcat_1([sys.P for sys in systems]...) # See PartitionedStateSpace
Tau = vcat([sys.Tau for sys in systems]...)
return DelayLtiSystem(P, Tau)
end

function Base.hcat(systems::DelayLtiSystem...)
P = hcat_1([sys.P for sys in systems]...) # See PartitionedStateSpace
Tau = vcat([sys.Tau for sys in systems]...)
return DelayLtiSystem(P, Tau)
end


function Base.vcat(systems::ST...) where ST <: AbstractStateSpace
# Perform checks
nu = systems[1].nu
Expand Down Expand Up @@ -125,6 +139,12 @@ Base.typed_hcat(::Type{T}, X...) where {T<:LTISystem} = hcat(convert.(T, X)...)
# Ambiguity
Base.typed_hcat(::Type{T}, X::Number...) where {T<:LTISystem, N} = hcat(convert.(T, X)...)

# Catch special cases where inv(sys) might not be possible after promotion, like improper tf
function /(sys1::Union{StateSpace,AbstractStateSpace}, sys2::LTISystem)
sys1new, sys2new = promote(sys1, 1/sys2)
return sys1new*sys2new
end

# function hvcat(rows::Tuple{Vararg{Int}}, systems::Union{Number,AbstractVecOrMat{<:Number},LTISystem}...)
# T = Base.promote_typeof(systems...)
# nbr = length(rows) # number of block rows
Expand Down
Loading

0 comments on commit 6d0c937

Please sign in to comment.