Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more robust gangoffour and gofplot #424

Merged
merged 1 commit into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,28 +451,33 @@ function delaymargin(G::LTISystem)
dₘ
end

function robust_minreal(G, args...; kwargs...)
try
return minreal(G, args...; kwargs...)
catch
return G
end
end

"""
S,D,N,T = gangoffour(P,C; minimal=true)
gangoffour(P::AbstractVector,C::AbstractVector; minimal=true)

Given a transfer function describing the Plant `P` and a transfer function describing the controller `C`, computes the four transfer functions in the Gang-of-Four.

`minimal` determines whether or not to call `minreal` on the computed systems.

`S = 1/(1+PC)` Sensitivity function

`D = P/(1+PC)`

`N = C/(1+PC)`
- `minimal` determines whether or not to call `minreal` on the computed systems.
- `S = 1/(1+PC)` Sensitivity function
- `D = P/(1+PC)`
- `N = C/(1+PC)`
- `T = PC/(1+PC)` Complementary sensitivity function

`T = PC/(1+PC)` Complementary sensitivity function

Only supports SISO systems"""
Only supports SISO systems
"""
function gangoffour(P::LTISystem,C::LTISystem; minimal=true)
if P.nu + P.ny + C.nu + C.ny > 4
error("gangoffour only supports SISO systems")
end
minfun = minimal ? minreal : identity
minfun = minimal ? robust_minreal : identity
S = (1/(1+P*C)) |> minfun
D = (P*S) |> minfun
N = (C*S) |> minfun
Expand Down
14 changes: 8 additions & 6 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,20 @@ end
pzmap(sys::LTISystem; kwargs...) = pzmap([sys]; kwargs...)
pzmap!(sys::LTISystem; kwargs...) = pzmap!([sys]; kwargs...)

"""`fig = gangoffourplot(P::LTISystem, C::LTISystem)`, `gangoffourplot(P::Union{Vector, LTISystem}, C::Vector; plotphase=false)`

Gang-of-Four plot.
"""
fig = gangoffourplot(P::LTISystem, C::LTISystem; minimal=true, plotphase=false, kwargs...)
gangoffourplot(P::Union{Vector, LTISystem}, C::Vector; minimal=true, plotphase=false, kwargs...)

`kwargs` is sent as argument to Plots.plot."""
function gangoffourplot(P::Union{Vector, LTISystem}, C::Vector, args...; plotphase=false, kwargs...)
Gang-of-Four plot. `kwargs` is sent as argument to Plots.plot.
"""
function gangoffourplot(P::Union{Vector, LTISystem}, C::Vector, args...; minimal=true, plotphase=false, kwargs...)
# Array of (S,D,N,T)
if P isa LTISystem # Don't broadcast over scalar (with size?)
P = [P]
end
sys = gangoffour.(P,C)
sys = gangoffour.(P,C; minimal=minimal)
fig = bodeplot([[sys[i][1] sys[i][2]; sys[i][3] sys[i][4]] for i = 1:length(C)], args..., plotphase=plotphase; kwargs...)
hline!([1 1 1 1], l=(:black, :dash), primary=false)
titles = fill("", 1, plotphase ? 8 : 4)
# Empty titles on phase
titleIdx = plotphase ? [1,2,5,6] : [1,2,3,4]
Expand Down