Skip to content

Commit 582f082

Browse files
committed
Fixed plotting in pidplots
1 parent 575f355 commit 582f082

File tree

3 files changed

+21
-54
lines changed

3 files changed

+21
-54
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ end
2121
deploydocs(
2222
repo = "github.com/JuliaControl/ControlSystems.jl.git",
2323
latest = "master",
24-
julia = "0.4",
24+
julia = "0.5",
2525
deps = myDeps
2626
)

src/pid_design.jl

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -57,67 +57,35 @@ function pidplots(P::LTISystem, args...; kps=0, kis=0, kds=0, time=false, series
5757
pz_ = in(:pz ,args)
5858
nichols_ = in(:nichols ,args)
5959

60-
61-
if nyquist_
62-
nq = Plots.plot()
63-
end
64-
if gof_
65-
bd = Plots.subplot(n=4,nc=2)
66-
end
67-
if pz_
68-
pz = Plots.plot()
69-
end
70-
if controller_
71-
cplot = plot()
72-
end
73-
60+
Cs = LTISystem[]
61+
PCs = LTISystem[]
62+
Ts = LTISystem[]
63+
labels = Array{String,2}(1,length(kps))
64+
colors = Array{Colors.RGB{Float64},2}(1, length(kps))
7465
for (i,kp) = enumerate(kps)
7566
ki = kis[i]
7667
kd = kds[i]
7768
label = "\$k_p = $(round(kp,3)), \\quad k_i = $(round(ki,3)), \\quad k_d = $(round(kd,3))\$"
7869

7970
C = pid(kp=kp,ki=ki,kd=kd,time=time,series=series)
8071
S,D,N,T = gangoffour(P,C)
81-
82-
if nyquist_
83-
NQ = nyquist(P*C,ω)
84-
redata = NQ[1][:]
85-
imdata = NQ[2][:]
86-
ylim = (max(-20,minimum(imdata)), min(20,maximum(imdata)))
87-
xlim = (max(-20,minimum(redata)), min(20,maximum(redata)))
88-
Plots.plot!(nq,redata,imdata, ylims=ylim, xlims=xlim, lab=label, c=getColorSys(i))
89-
end
90-
if gof_
91-
BD = bode(S,ω)
92-
Plots.plot!(bd[1,1],BD[3][:],BD[1][:], lab=label, c=getColorSys(i))
93-
BD = bode(D,ω)
94-
Plots.plot!(bd[1,2],BD[3][:],BD[1][:], lab=label, c=getColorSys(i))
95-
BD = bode(N,ω)
96-
Plots.plot!(bd[2,1],BD[3][:],BD[1][:], lab=label, c=getColorSys(i))
97-
BD = bode(T,ω)
98-
Plots.plot!(bd[2,2],BD[3][:],BD[1][:], lab=label, c=getColorSys(i))
99-
end
100-
if pz_
101-
pzmap!(pz,T)
102-
end
103-
if controller_
104-
BD = bode(C,ω)
105-
Plots.plot!(cplot,BD[3][:],BD[1][:], lab=label, c=getColorSys(i))
106-
end
72+
push!(Cs, C)
73+
push!(PCs, P*C)
74+
push!(Ts, T)
75+
labels[i] = label
10776
end
10877

109-
nyquist_ && Plots.plot!(nq,legend=true, title="Nyquist curves")
78+
if nyquist_
79+
nq = nyquistplot(PCs, ω, lab=labels, title="Nyquist curves")
80+
end
11081
if gof_
111-
Plots.plot!(bd[1,1],legend=true, title="S", xscale=:log10, yscale=:log10)
112-
Plots.plot!(bd[1,2],legend=true, title="D", xscale=:log10, yscale=:log10)
113-
Plots.plot!(bd[2,1],legend=true, title="N", xscale=:log10, yscale=:log10)
114-
Plots.plot!(bd[2,2],legend=true, title="T", xscale=:log10, yscale=:log10)
82+
bd = gangoffourplot(P, Cs, ω, lab=labels)
11583
end
11684
if pz_
117-
Plots.plot!(pz,title="Pole-zero map")
85+
pzmap(Ts, title="Pole-zero map")
11886
end
11987
if controller_
120-
Plots.plot!(cplot,title="Controller bode plot",legend=true, xscale=:log10, yscale=:log10)
88+
cplot = bodeplot(Cs, ω, lab=labels, title="Controller bode plot")
12189
end
12290

12391

src/plotting.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,11 @@ Gang-of-Four plot.
488488
function gangoffourplot(P::Union{Vector, LTISystem}, C::Vector, args...; plotphase=false, kwargs...)
489489
S,D,N,T = gangoffour(P,C)
490490
fig = bodeplot(LTISystem[[S[i] D[i]; N[i] T[i]] for i = 1:length(C)], args..., plotphase=plotphase; kwargs...)
491-
lower = plotphase ? 3 : 2
492-
s2i(i,j) = sub2ind((2,(plotphase?4:2)),j,i)
493-
Plots.plot!(fig,title="\$S = 1/(1+PC)\$", subplot=s2i(1,1))
494-
Plots.plot!(fig,title="\$D = P/(1+PC)\$", subplot=s2i(1,2))
495-
Plots.plot!(fig,title="\$N = C/(1+PC)\$", subplot=s2i(lower,1))
496-
Plots.plot!(fig,title="\$T = PC/(1+PC\$)", subplot=s2i(lower,2))
491+
titles = fill("", 1, plotphase ? 8 : 4)
492+
# Empty titles on phase
493+
titleIdx = plotphase ? [1,2,5,6] : [1,2,3,4]
494+
titles[titleIdx] = ["\$S = 1/(1+PC)\$", "\$D = P/(1+PC)\$", "\$N = C/(1+PC)\$", "\$T = PC/(1+PC\$)"]
495+
Plots.plot!(fig, title = titles)
497496
return fig
498497
end
499498

0 commit comments

Comments
 (0)