Skip to content

Commit eb0ea1a

Browse files
committedOct 3, 2018
updated plot limits, travis and documentation plots
2 parents fc457b4 + ee9bc1f commit eb0ea1a

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed
 

‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ notifications:
66
email: false
77
after_success:
88
- julia -e 'using Pkg; import ControlSystems; cd(joinpath(dirname(pathof(ControlSystems)), "..")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
9-
- julia -e 'using Pkg; Pkg.add("Documenter")'
9+
- julia -e 'using Pkg; Pkg.add("Documenter"); Pkg.add("GR"); Pkg.add("Plots"); Pkg.add("DSP")'
1010
- julia -e 'using Pkg; import ControlSystems; cd(joinpath(dirname(pathof(ControlSystems)), "..")); include(joinpath("docs", "make.jl"))'

‎docs/make.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Documenter, ControlSystems, Plots
1+
using Documenter, ControlSystems, Plots, LinearAlgebra, DSP
22
import GR # Bug with world age in Plots.jl, see https://github.com/JuliaPlots/Plots.jl/issues/1047
33

44
include("src/makeplots.jl")
@@ -23,6 +23,6 @@ end
2323
deploydocs(
2424
repo = "github.com/JuliaControl/ControlSystems.jl.git",
2525
latest = "master",
26-
julia = "0.6",
26+
julia = "1.0",
2727
deps = myDeps
2828
)

‎docs/src/makeplots.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Q = Matrix{Float64}(I,2,2)
1616
R = Matrix{Float64}(I,1,1)
1717
L = dlqr(A,B,Q,R) # lqr(sys,Q,R) can also be used
1818

19-
u(x,t) = -L*x + 1.5(t>=2.5)# Form control law (u is a function of t and x), a constant input disturbance is affecting the system from t≧2.5
19+
u(x,t) = -L*x .+ 1.5(t>=2.5)# Form control law (u is a function of t and x), a constant input disturbance is affecting the system from t≧2.5
2020
t=0:h:5
2121
x0 = [1,0]
2222
y, t, x, uout = lsim(sys,u,t,x0=x0)
@@ -71,7 +71,7 @@ Plots.savefig(plotsDir*"/ppgofplot.svg")
7171

7272
P1(s) = exp(-sqrt(s))
7373
f1 = stabregionPID(P1,exp10.(range(-5, stop=1, length=1000))); Plots.savefig(plotsDir*"/stab1.svg")
74-
P2 = s -> 100*(s+6).^2./(s.*(s+1).^2.*(s+50).^2)
74+
P2 = s -> 100*(s+6).^2 ./(s.*(s+1).^2 .*(s+50).^2)
7575
f2 = stabregionPID(P2,exp10.(range(-5, stop=2, length=1000))); Plots.savefig(plotsDir*"/stab2.svg")
7676
P3 = tf(1,[1,1])^4
7777
f3 = stabregionPID(P3,exp10.(range(-5, stop=0, length=1000))); Plots.savefig(plotsDir*"/stab3.svg")
@@ -84,15 +84,15 @@ f3 = stabregionPID(P3,exp10.(range(-5, stop=0, length=1000))); Plots.savefig(plo
8484
P = tf([1.],[1., 1])
8585
ζ = 0.5 # Desired damping
8686
ws = exp10.(range(-1, stop=2, length=8)) # A vector of closed-loop bandwidths
87-
kp = 2*ζ*ws-1 # Simple pole placement with PI given the closed-loop bandwidth, the poles are placed in a butterworth pattern
87+
kp = 2*ζ*ws.-1 # Simple pole placement with PI given the closed-loop bandwidth, the poles are placed in a butterworth pattern
8888
ki = ws.^2
8989
pidplots(P,:nyquist,;kps=kp,kis=ki, ω= exp10.(range(-2, stop=2, length=500)))
9090
Plots.savefig(plotsDir*"/pidplotsnyquist1.svg")
9191
pidplots(P,:gof,;kps=kp,kis=ki, ω= exp10.(range(-2, stop=2, length=500)))
9292
Plots.savefig(plotsDir*"/pidplotgof1.svg")
9393

9494
kp = range(-1, stop=1, length=8) # Now try a different strategy, where we have specified a gain crossover frequency of 0.1 rad/s
95-
ki = sqrt.(1-kp.^2)./10
95+
ki = sqrt.(1 .-kp.^2)./10
9696
pidplots(P,:nyquist,;kps=kp,kis=ki)
9797
Plots.savefig(plotsDir*"/pidplotsnyquist2.svg")
9898
pidplots(P,:gof,;kps=kp,kis=ki)

‎src/matrix_comps.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ function care(A, B, Q, R)
1212
B*inv(R)*B'
1313
catch y
1414
if y isa SingularException
15-
error("R must be non-singular.")
15+
error("R must be non-singular in care.")
1616
else
17-
throw(t)
17+
throw(y)
1818
end
1919
end
2020

‎src/plotting.jl

+26-10
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,25 @@ function setPlotScale(str::AbstractString)
3838
_PlotScale, _PlotScaleFunc, _PlotScaleStr = plotSettings
3939
end
4040

41-
function getLogTicks(x)
41+
"""
42+
Get atributes from xlims or ylims
43+
default to extrema(wmag) if xlims/ylims not defined or empty
44+
"""
45+
function getlims(xylims, plotattributes, wmag)
46+
lims = get(plotattributes, xylims, extrema(wmag))
47+
if lims isa Tuple{<:Number, <:Number} # If x/ylims not supplied as empty
48+
return lims
49+
else
50+
return extrema(wmag)
51+
end
52+
end
53+
54+
function getLogTicks(x, minmax)
55+
minx, maxx = minmax
4256
major_minor_limit = 6
4357
minor_text_limit = 8
44-
min = ceil(log10(minimum(x)))
45-
max = floor(log10(maximum(x)))
58+
min = ceil(log10(minx))
59+
max = floor(log10(maxx))
4660
major = 10 .^ collect(min:max)
4761
if Plots.backend() != Plots.GRBackend()
4862
majorText = [latexstring("\$10^{$(round(Int64,i))}\$") for i = min:max]
@@ -57,7 +71,7 @@ function getLogTicks(x)
5771
minorText = ["$j*10^{$(round(Int64,i))}" for i = (min-1):(max+1) for j = 2:9]
5872
end
5973

60-
ind = findall(minimum(x) .<= minor .<= maximum(x))
74+
ind = findall(minx .<= minor .<= maxx)
6175
minor = minor[ind]
6276
minorText = minorText[ind]
6377
if length(minor) > minor_text_limit
@@ -205,7 +219,7 @@ optionally provided.
205219
`kwargs` is sent as argument to Plots.plot."""
206220
bodeplot
207221

208-
@recipe function bodeplot(p::Bodeplot; plotphase=true)
222+
@recipe function bodeplot(p::Bodeplot; plotphase=true, ylimsphase=())
209223
systems = p.args[1]
210224
if !isa(systems, AbstractArray)
211225
systems = typeof(systems)[systems]
@@ -222,7 +236,7 @@ bodeplot
222236
s2i(i,j) = LinearIndices((nu,(plotphase ? 2 : 1)*ny))[j,i]
223237
layout --> ((plotphase ? 2 : 1)*ny,nu)
224238
nw = length(w)
225-
xticks --> getLogTicks(w)
239+
xticks --> getLogTicks(w, getlims(:xlims, plotattributes, w))
226240

227241
for (si,s) = enumerate(systems)
228242
mag, phase = bode(s, w)[1:2]
@@ -246,7 +260,7 @@ bodeplot
246260
yscale --> _PlotScaleFunc
247261
xscale --> :log10
248262
if _PlotScale != "dB"
249-
yticks --> getLogTicks(magdata)
263+
yticks --> getLogTicks(magdata, getlims(:ylims, plotattributes, magdata))
250264
end
251265
xguide --> xlab
252266
yguide --> "Magnitude $_PlotScaleStr"
@@ -260,9 +274,11 @@ bodeplot
260274
if !plotphase
261275
continue
262276
end
277+
263278
@series begin
264279
grid --> true
265280
xscale --> :log10
281+
ylims := ylimsphase
266282
yguide --> "Phase (deg)"
267283
subplot --> s2i(2i,j)
268284
xguide --> "Frequency (rad/s)"
@@ -287,8 +303,8 @@ end
287303
yscale --> :log10
288304
xscale --> :log10
289305
yguide --> "Magnitude"
290-
xticks --> getLogTicks(w)
291-
yticks --> getLogTicks(magdata)
306+
xticks --> getLogTicks(w, getlims(:xlims, plotattributes, w))
307+
yticks --> getLogTicks(magdata, getlims(:ylims, plotattributes, magdata))
292308
x := w; y := magdata
293309
()
294310
end
@@ -306,7 +322,7 @@ end
306322
xscale --> :log10
307323
yguide --> "Phase (deg)"
308324
xguide --> "Frequency (rad/s)"
309-
xticks --> getLogTicks(w)
325+
xticks --> getLogTicks(w, getlims(:xlims, plotattributes, w))
310326
x := w; y := phasedata
311327
()
312328
end

0 commit comments

Comments
 (0)
Please sign in to comment.