Skip to content

Commit b49025a

Browse files
committed
add angle unwrapping in nicholsplot
1 parent 037e406 commit b49025a

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

lib/ControlSystemsBase/ext/ControlSystemsBaseMakieExt.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ function CSMakie.pzmap!(ax::Axis, systems::Union{LTISystem, AbstractVector{<:LTI
111111
return ax
112112
end
113113

114-
# ====== Bodeplot ======
115114
function CSMakie.bodeplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}},
116115
w=nothing; plotphase=true, unwrap=true, hz=false,
117116
balance=true, adjust_phase_start=true, adaptive=true, kwargs...)
@@ -219,7 +218,6 @@ function CSMakie.bodeplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}}
219218
return fig
220219
end
221220

222-
# ====== Nyquistplot ======
223221
function CSMakie.nyquistplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}},
224222
w=nothing; Ms_circles=Float64[], Mt_circles=Float64[],
225223
unit_circle=false, hz=false, critical_point=-1,
@@ -309,7 +307,6 @@ function CSMakie.nyquistplot(systems::Union{LTISystem, AbstractVector{<:LTISyste
309307
return fig
310308
end
311309

312-
# ====== Sigmaplot ======
313310
function CSMakie.sigmaplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}},
314311
w=nothing; hz=false, balance=true, extrema=false, kwargs...)
315312
systems_vec = systems isa AbstractVector ? systems : [systems]
@@ -345,7 +342,6 @@ function CSMakie.sigmaplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}
345342
return fig
346343
end
347344

348-
# ====== Marginplot ======
349345
function CSMakie.marginplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}},
350346
w=nothing; plotphase=true, hz=false, balance=true,
351347
adjust_phase_start=true, adaptive=true, kwargs...)
@@ -493,7 +489,6 @@ function CSMakie.marginplot(systems::Union{LTISystem, AbstractVector{<:LTISystem
493489
return fig
494490
end
495491

496-
# ====== Root Locus Plot ======
497492
function CSMakie.rlocusplot(P::LTISystem, K=500; output=false, kwargs...)
498493
# Compute root locus
499494
result = rlocus(P, K; output=output)
@@ -543,7 +538,6 @@ function CSMakie.rlocusplot(P::LTISystem, K=500; output=false, kwargs...)
543538
return fig
544539
end
545540

546-
# ====== RGA Plot ======
547541
function CSMakie.rgaplot(systems::Union{LTISystem, AbstractVector{<:LTISystem}},
548542
w=nothing; hz=false, balance=true, kwargs...)
549543
systems_vec = systems isa AbstractVector ? systems : [systems]
@@ -616,7 +610,8 @@ function CSMakie.nicholsplot(systems::Union{LTISystem, AbstractVector{<:LTISyste
616610
ℑdata = dropdims(ℑresp, dims=(1,2))
617611
mag = 20*log10.(sqrt.(ℜdata.^2 + ℑdata.^2))
618612
angles = 180/π*angle.(ℜdata .+ im*ℑdata)
619-
613+
# unwrap angles
614+
ControlSystemsBase.unwrap!(angles)
620615
lines!(ax, angles, mag, linewidth=2, label="System $sysi")
621616
end
622617

@@ -626,10 +621,6 @@ function CSMakie.nicholsplot(systems::Union{LTISystem, AbstractVector{<:LTISyste
626621
return fig
627622
end
628623

629-
# ====== Direct plot methods for types ======
630-
# These allow direct plotting of types with plot()
631-
632-
# Direct plot method for SimResult
633624
function Makie.plot(r::SimResult; plotu=false, plotx=false, ploty=true)
634625
ny, nu, nx = r.ny, r.nu, r.nx
635626
t = r.t
@@ -684,7 +675,7 @@ function Makie.plot(r::SimResult; plotu=false, plotx=false, ploty=true)
684675
end
685676
end
686677

687-
# Plot states
678+
# Plot state
688679
if plotx
689680
for i in 1:nx
690681
ax = Axis(gl[plotind, 1],
@@ -719,7 +710,6 @@ function Makie.plot(r::SimResult; plotu=false, plotx=false, ploty=true)
719710
return fig
720711
end
721712

722-
# Direct plot method for StepInfo
723713
function Makie.plot(si::StepInfo)
724714
fig = Figure()
725715
ax = Axis(fig[1,1],

lib/ControlSystemsBase/test/test_makie_plots.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using GLMakie
55

66
@testset "Makie Plot Tests" begin
77
# Create test systems
8-
P = tf([1], [1, 2, 1])
8+
P = tf([1.2], [1, 2, 1])*tf(1, [10, 1])
99
P2 = tf([1, 2], [1, 3, 2])
1010
Pss = ss(P)
1111
Pmimo = [P P2; P2 P]
@@ -129,7 +129,7 @@ using GLMakie
129129
end
130130

131131
@testset "StepInfo plot" begin
132-
res = step(P, 10)
132+
res = step(P, 100)
133133
si = stepinfo(res)
134134
@test_nowarn begin
135135
fig = plot(si)

0 commit comments

Comments
 (0)