Skip to content

Commit

Permalink
Merge pull request #737 from JuliaControl/gofmt
Browse files Browse the repository at this point in the history
add `Mt_lines` option to gofplot
  • Loading branch information
baggepinnen authored Sep 6, 2022
2 parents 5f0fc84 + a5c00a1 commit aa12d27
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fig
```
To get good robustness, we typically aim for a $M_t$ less than 1.5. In general, the smaller $M_t$ we require, the larger the controller gain will be.

Since we are designing a PID controller, we expect a large controller gain for high frequencies. This is generally undesirable for both robustness and noise reasons, and is commonly solved by introducing a lowpass filter in series with the controller. The example below passes the keyword argument `Tf=1/30ω` to indicate that we want to add a second-order lowpass filter with a cutoff frequency 20 times faster than the design frequency.
Since we are designing a PID controller, we expect a large controller gain for high frequencies. This is generally undesirable for both robustness and noise reasons, and is commonly solved by introducing a lowpass filter in series with the controller. The example below passes the keyword argument `Tf=1/20ω` to indicate that we want to add a second-order lowpass filter with a cutoff frequency 20 times faster than the design frequency.
```@example PIDDESIGN
Tf = 1/20ω
C, kp, ki, kd, fig, CF = loopshapingPID(P, ω; Mt, ϕt, doplot=true, Tf)
Expand Down
2 changes: 1 addition & 1 deletion src/pid_design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function loopshapingPID(P0, ω; Mt = 1.3, ϕt=75, form::Symbol = :standard, dopl
CF = C*F
fig = if doplot
w = exp10.(LinRange(log10(ω)-2, log10(ω)+2, 500))
f1 = gangoffourplot(P0,CF, w)
f1 = gangoffourplot(P0,CF, w, Mt_lines=[Mt])
f2 = nyquistplot([P0 * CF, P0], w, ylims=(-4,2), xlims=(-4,1.2), unit_circle=true, Mt_circles=[Mt], show=false, lab=["PC" "P"])
RecipesBase.plot!([ct, real(specpoint)], [0, imag(specpoint)], lab="ϕt = $(ϕt)°", l=:dash)

Expand Down
12 changes: 8 additions & 4 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ function _to1series(x,y)
x2,y2
end

_to1series(y) = _to1series(1:size(y,1),y)
_to1series(y) = _to1series(1:size(y,3),y)

@userplot Marginplot
"""
Expand Down Expand Up @@ -770,14 +770,14 @@ pzmap(sys::LTISystem; kwargs...) = pzmap([sys]; kwargs...)
pzmap!(sys::LTISystem; kwargs...) = pzmap!([sys]; kwargs...)

"""
fig = gangoffourplot(P::LTISystem, C::LTISystem; minimal=true, plotphase=false, Ms_lines = [1.0, 1.1, 1.2], sigma = true, kwargs...)
fig = gangoffourplot(P::LTISystem, C::LTISystem; minimal=true, plotphase=false, Ms_lines = [1.0, 1.1, 1.2], Mt_lines = [], sigma = true, kwargs...)
Gang-of-Four plot.
`sigma` determines whether a [`sigmaplot`](@ref) is used instead of a [`bodeplot`](@ref) for MIMO `S` and `T`.
`kwargs` are sent as argument to RecipesBase.plot.
"""
function gangoffourplot(P::Union{<:Vector, LTISystem}, C::Vector, args...; minimal=true, Ms_lines = [1.0, 1.1, 1.2], sigma = true, plotphase=false, kwargs...)
function gangoffourplot(P::Union{<:Vector, LTISystem}, C::Vector, args...; minimal=true, Ms_lines = [1.0, 1.1, 1.2], Mt_lines = [], sigma = true, plotphase=false, kwargs...)
if P isa LTISystem # Don't broadcast over scalar (with size?)
P = [P]
end
Expand All @@ -798,7 +798,11 @@ function gangoffourplot(P::Union{<:Vector, LTISystem}, C::Vector, args...; minim
Plots.hline!(ones(1, ninputs(D[1])*noutputs(D[1])), l=(:black, :dash), primary=false)
f3 = bodeplot(N, args...; show=false, title="C/(1+PC)", plotphase=false, kwargs...)
f4 = bp(T, args...; show=false, title="T = PC/(1+PC)", ylims=(3e-3,8), kwargs...)
Plots.hline!([1], l=(:black, :dash), primary=false)
if !isnothing(Mt_lines) && !isempty(Mt_lines)
Plots.hline!(Mt_lines', l=(:dash, [:green :orange :red :darkred :purple]), primary=false, lab=string.(Mt_lines'), ylims=(3e-3,8))
else
Plots.hline!([1.0], l=(:dash, :black), ylims=(3e-3,8))
end
Plots.plot(f1,f2,f3,f4, ticks=:default, ylabel="", legend=:bottomright)
end

Expand Down

0 comments on commit aa12d27

Please sign in to comment.