Skip to content

Commit

Permalink
Merge pull request #219 from JuliaControl/fixplots
Browse files Browse the repository at this point in the history
WIP Fixplots and example
  • Loading branch information
mfalt committed Oct 31, 2019
2 parents a0b1309 + 14b1f7f commit 1a38971
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 3 additions & 5 deletions example/delayed_lti_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ s = tf("s")
P = delay(0.2) * ss(1/(s+1))

K = 3; Ti = 0.3;
C = DelayLtiSystem(ss(K*(1 + 1/s)))
C = ss(K*(1 + 1/s))

ω = exp10.(LinRange(-2,2,500))

L_fr = freqresp(C*P, ω)[:]
plot(real(L_fr), imag(L_fr), xlim=[-2,1], ylim=[-2,2], title="Nyquist curve")
nyquistplot(P*C, ω, xlims=(-2,1), ylims=(-2,2), gaincircles=false)

G_yd = feedback(P, C)
plot(ω, abs.(freqresp(G_yd, ω)[:]), xscale=:log, yscale=:log,
title="Transfer function from load disturbances to output.")
bodeplot(G_yd, ω, plotphase=false, title="Transfer function from load disturbances to output.")
26 changes: 14 additions & 12 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ optionally provided.
`kwargs` is sent as argument to Plots.plot."""
bodeplot

@recipe function bodeplot(p::Bodeplot; plotphase=true, ylimsphase=())
@recipe function bodeplot(p::Bodeplot; plotphase=true, ylimsphase=(), unwrap=true)
systems, w = _processfreqplot(Val{:bode}(), p.args...)
ny, nu = size(systems[1])
s2i(i,j) = LinearIndices((nu,(plotphase ? 2 : 1)*ny))[j,i]
Expand Down Expand Up @@ -301,9 +301,7 @@ bodeplot
color --> styledict[:c]
w, magdata
end
if !plotphase
continue
end
plotphase || continue

@series begin
grid --> true
Expand All @@ -315,7 +313,7 @@ bodeplot
label --> "\$G_{$(si)}\$"
linestyle --> styledict[:l]
color --> styledict[:c]
w, phasedata
w, unwrap ? ControlSystems.unwrap(phasedata.*(pi/180)).*(180/pi) : phasedata
end

end
Expand Down Expand Up @@ -388,32 +386,36 @@ nyquistplot
redata = re_resp[:, i, j]
imdata = im_resp[:, i, j]
@series begin
ylims := (min(max(-20,minimum(imdata)),-1), max(min(20,maximum(imdata)),1))
xlims := (min(max(-20,minimum(redata)),-1), max(min(20,maximum(redata)),1))
ylims --> (min(max(-20,minimum(imdata)),-1), max(min(20,maximum(imdata)),1))
xlims --> (min(max(-20,minimum(redata)),-1), max(min(20,maximum(redata)),1))
title --> "Nyquist plot from: u($j)"
yguide --> "To: y($i)"
subplot --> s2i(i,j)
label --> "\$G_{$(si)}\$"
styledict = getStyleSys(si,length(systems))
linestyle --> styledict[:l]
seriescolor --> styledict[:c]
hover --> [Printf.@sprintf("ω = %.3f", w) for w in w]
color --> styledict[:c]
(redata, imdata)
end
# Plot rings
if gaincircles && si == length(systems)
v = range(0,stop=2π,length=100)
S,C = sin.(v),cos.(v)
@series begin
label := ""
primary := false
linestyle := :dash
color := :black
linecolor := :black
seriestype := :path
markershape := :none
(C,S)
end
@series begin
label := ""
primary := false
linestyle := :dash
color := :black
linecolor := :black
seriestype := :path
markershape := :none
(C .-1,S)
end
end
Expand Down

0 comments on commit 1a38971

Please sign in to comment.