Skip to content

Commit

Permalink
better error message for improper delay conversion (#831)
Browse files Browse the repository at this point in the history
* better error message for improper delay conversion

* create s var
  • Loading branch information
baggepinnen authored Apr 26, 2023
1 parent 604a9ab commit 1e1512e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ControlSystemsBase/src/types/DelayLtiSystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ function Base.convert(::Type{DelayLtiSystem{T1,S}}, d::T2) where {T1,T2 <: Abstr
end

function Base.convert(::Type{DelayLtiSystem{T,S}}, sys::TransferFunction{TE}) where {T,S,TE}
if issiso(sys) && length(numvec(sys.matrix[1,1])) > length(denvec(sys.matrix[1,1]))
error("The transfer function is not proper and can not be converted to a DelayLtiSystem type. If you tried to form the system `exp(sL) * B / A` where `B / A` is proper, add parenthesis to make it `exp(sL) * (B / A)`.")
end

DelayLtiSystem{T,S}(convert(StateSpace{TE, T}, sys))
end
# Catch convertsion between T
Expand Down
4 changes: 4 additions & 0 deletions lib/ControlSystemsBase/test/test_conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ H3 = zpk([(-1+im*sqrt(79))/8, (-1-im*sqrt(79))/8], [-3/2], 2)
@test zpk(G3) H3 rtol=1e-15
@test zpk(H3) == H3

s = tf("s")
@test_throws ErrorException delay(5)*((s+1))/((s+2)*(s+0.5))
@test_throws ErrorException delay(5)*zpk((s+1))/zpk((s+2)*(s+0.5))

# Test complex 1
A = [1.0 + im 1; 0 -2-3im]
B = [0;2]
Expand Down

0 comments on commit 1e1512e

Please sign in to comment.