Skip to content

Commit

Permalink
more robust gangoffour and gofplot
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 17, 2021
1 parent 9ffced5 commit d0ba231
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
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

0 comments on commit d0ba231

Please sign in to comment.