Skip to content

Commit

Permalink
fix #941
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Oct 24, 2024
1 parent 613f0d0 commit edd7e29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/ControlSystemsBase/src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ function sisomargin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMa
if !allMargins #Only output the smallest margins
gm, idx = findmin([gm;Inf])
wgm = [wgm;NaN][idx]
fi = [fi;NaN][idx]
pm, idx = findmin([abs.(pm);Inf])
fi = [fi;NaN][idx]
wpm = [wpm;NaN][idx]
if full
if !isnan(fi) #fi may be NaN, fullPhase is a scalar
Expand Down Expand Up @@ -509,19 +509,19 @@ function _findCrossings(w, n, res)
tcross = Vector{eltype(w)}()
for i in 1:(length(w)-1)
if res[i] == 0
wcross = [wcross; w[i]]
tcross = [tcross; i]
push!(wcross, w[i])
push!(tcross, i)
elseif n[i] != n[i+1]
#Interpolate to approximate crossing
t = res[i]/(res[i]-res[i+1])
tcross = [tcross; i+t]
push!(tcross, i+t)
wt = w[i]+t*(w[i+1]-w[i])
wcross = [wcross; wt]
push!(wcross, wt)
end
end
if res[end] == 0 #Special case if multiple points
wcross = [wcross; w[end]]
tcross = [tcross; length(w)]
push!(wcross, w[end])
push!(tcross, length(w))
end
wcross, tcross
end
Expand Down
11 changes: 11 additions & 0 deletions lib/ControlSystemsBase/test/test_analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ dm = delaymargin(P)[]

@test delaymargin(tf(0.1, [1, 1])) == Inf

# https://github.com/JuliaControl/ControlSystems.jl/issues/941
C = 0.6 + 30 * tf([1, 0], [1])
G = tf([0.04, 0.0001, 1.1], [1, 0.03, 254.9])
H = tf([0.25], [1, 1, 0.25])
L = C * G * H * delay(1)
m = margin(L)
Lw = freqresp(L, m[1][])[]
@test imag(Lw) 0 atol = 1e-6 # Test definition of gain margin
@test inv(-real(Lw)) m[2][] atol = 1e-6 # Test definition of gain margin


# RGA
a = 10
P = ss([0 a; -a 0], I(2), [1 a; -a 1], 0)
Expand Down

0 comments on commit edd7e29

Please sign in to comment.