Skip to content

Commit ac6e8fa

Browse files
authored
Merge pull request #962 from JuliaControl/negmarg
Fix negative phase margin
2 parents 987c0ec + bdbeb80 commit ac6e8fa

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

lib/ControlSystemsBase/src/ControlSystemsBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function __init__()
244244
print(io, " for automatic discretization (applicable to systems without delays or nonlinearities only).")
245245
end
246246
plots_id = Base.PkgId(UUID("91a5bcdd-55d7-5caf-9e0b-520d859cae80"), "Plots")
247-
if exc.f !== nothing && nameof(exc.f) === :plot && parentmodule(argtypes[1]) == @__MODULE__() && !haskey(Base.loaded_modules, plots_id)
247+
if exc.f isa Function && nameof(exc.f) === :plot && parentmodule(argtypes[1]) == @__MODULE__() && !haskey(Base.loaded_modules, plots_id)
248248
printstyled(io, "\nPlotting is not available unless Plots.jl is loaded manually. Call `using Plots` before plotting.", color=:green, bold=true)
249249
elseif (exc.f == /) && argtypes[2] <: DelayLtiSystem
250250
print(io, "A delayed system can not be inverted. Consider use of the function `feedback`.")

lib/ControlSystemsBase/src/analysis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ function sisomargin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMa
506506
if !allMargins #Only output the smallest margins
507507
gm, idx = findmin([gm;Inf])
508508
wgm = [wgm;NaN][idx]
509-
pm, idx = findmin([abs.(pm);Inf])
509+
pm, idx = findmin([pm;Inf])
510510
fi = [fi;NaN][idx]
511511
wpm = [wpm;NaN][idx]
512512
if full

lib/ControlSystemsBase/src/connections.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ Base.typed_hcat(::Type{S}, X::Union{AbstractArray{<:Number,1}, AbstractArray{<:N
140140

141141
## Mixed-type array creation
142142
# When creating an array of systems, an error may be thrown if the default Base.vect is called that tries to promote all systems to a common type. E.g., when using non-proper transfer functions and statespace systems. We thus opt out of the conversion with the method below
143-
function Base.vect(X::LTISystem...)
144-
LTISystem[X...]
143+
function Base.vect(X0::LTISystem, X::LTISystem...)
144+
LTISystem[X0, X...]
145145
end
146146

147-
function Base.vect(X::T...) where T <: LTISystem
148-
T[X...]
147+
function Base.vect(X0::T, X::T...) where T <: LTISystem
148+
T[X0, X...]
149149
end
150150

151151
"""

lib/ControlSystemsBase/test/runtests.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import Base.isapprox # In framework and test_synthesis
44
import SparseArrays: sparse # In test_matrix_comps
55
import Polynomials: conv # In test_conversion and test_synthesis
66
using Aqua
7-
# @testset "Aqua" begin
8-
# Aqua.test_all(ControlSystemsBase;
9-
# ambiguities = false, # causes 100s of hits in all dependencies
10-
# stale_deps = true, # Aqua complains about itself https://github.com/JuliaTesting/Aqua.jl/issues/78
11-
# project_toml_formatting = false, # https://github.com/JuliaTesting/Aqua.jl/issues/105
12-
# )
13-
# end
7+
@testset "Aqua" begin
8+
Aqua.test_all(ControlSystemsBase;
9+
ambiguities = false, # causes 100s of hits in all dependencies
10+
stale_deps = true, # Aqua complains about itself https://github.com/JuliaTesting/Aqua.jl/issues/78
11+
project_toml_formatting = false, # https://github.com/JuliaTesting/Aqua.jl/issues/105
12+
)
13+
end
1414

1515

1616
include("framework.jl")

lib/ControlSystemsBase/test/test_analysis.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ Lw = freqresp(L, m[1][])[]
245245
@test imag(Lw) 0 atol = 1e-6 # Test definition of gain margin
246246
@test inv(-real(Lw)) m[2][] atol = 1e-6 # Test definition of gain margin
247247

248+
# https://github.com/JuliaControl/ControlSystems.jl/issues/961
249+
P = tf(1,[5, 10.25, 6.25, 1])
250+
w_180, gm, w_c, pm = margin(50P)
251+
@test pm[] -35.1 rtol=1e-2
248252

249253
# RGA
250254
a = 10

0 commit comments

Comments
 (0)