Skip to content

Commit

Permalink
make feedback handle numbers in signal spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 12, 2025
1 parent 2a8aa33 commit a7cd0f0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions lib/ControlSystemsBase/src/connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ function feedback(sys1::AbstractStateSpace, sys2::AbstractStateSpace;
if !(isa(Y2, Colon) || allunique(Y2)); @warn "Connecting single output to multiple inputs Y2=$Y2"; end
if !(isa(U1, Colon) || allunique(U1)); @warn "Connecting multiple outputs to a single input U1=$U1"; end
if !(isa(U2, Colon) || allunique(U2)); @warn "Connecting a single output to multiple inputs U2=$U2"; end
U1 isa Number && (U1 = [U1])
Y1 isa Number && (Y1 = [Y1])
U2 isa Number && (U2 = [U2])
Y2 isa Number && (Y2 = [Y2])
W1 isa Number && (W1 = [W1])
Z1 isa Number && (Z1 = [Z1])
W2 isa Number && (W2 = [W2])
Z2 isa Number && (Z2 = [Z2])

if (U1 isa Colon ? size(sys1, 2) : length(U1)) != (Y2 isa Colon ? size(sys2, 1) : length(Y2))
error("Lengths of U1 ($U1) and Y2 ($Y2) must be equal")
Expand Down Expand Up @@ -394,13 +402,13 @@ function feedback(sys1::AbstractStateSpace, sys2::AbstractStateSpace;
R1 = try
inv*I - s2_D22*s1_D22) # slightly faster than α*inv(I - α*s2_D22*s1_D22)
catch
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 not invertible")

Check warning on line 405 in lib/ControlSystemsBase/src/connections.jl

View check run for this annotation

Codecov / codecov/patch

lib/ControlSystemsBase/src/connections.jl#L405

Added line #L405 was not covered by tests
end

R2 = try
inv(I - α*s1_D22*s2_D22)
catch
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
error("Ill-posed feedback interconnection, I - α*s1_D22*s2_D22 not invertible")

Check warning on line 411 in lib/ControlSystemsBase/src/connections.jl

View check run for this annotation

Codecov / codecov/patch

lib/ControlSystemsBase/src/connections.jl#L411

Added line #L411 was not covered by tests
end

s2_B2R2 = s2_B2*R2
Expand Down Expand Up @@ -463,7 +471,7 @@ r | - | | | | | y
```
"""
function feedback2dof(P::TransferFunction{TE}, C::TransferFunction{TE}, F::TransferFunction{TE}) where TE
!issiso(P) || return tf(feedback2dof(ss(P), ss(C), ss(F)))
issiso(P) || return tf(feedback2dof(ss(P), ss(C), ss(F)))
timeevol = common_timeevol(P, C, F)

Pn,Pd = numpoly(P)[], denpoly(P)[]
Expand Down
5 changes: 3 additions & 2 deletions lib/ControlSystemsBase/src/pid_design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ The `form` can be chosen as one of the following (determines how the arguments `
This controller has negative feedback built in, and the closed-loop system from `r` to `y` is thus formed as
```
Cr, Cy = C[1, 1], C[1, 2]
feedback(P, Cy, pos_feedback=true)*Cr # Alternative 1
feedback(P, -Cy)*Cr # Alternative 2
feedback(P, Cy, pos_feedback=true)*Cr # Alternative 1
feedback(P, -Cy)*Cr # Alternative 2
feedback(P, C, U2=2, W2=1, W1=[], pos_feedback=true) # Alternative 3, less pretty but more efficient, returns smaller realization
```
"""
function pid_2dof(args...; state_space = true, Ts = nothing, disc = :tustin, kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion lib/ControlSystemsBase/src/sensitivity_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ T = G[P.ny+1:end, P.ny+1:end] # Input complimentary sensitivity function
The gang of four can be plotted like so
```julia
Gcl = extended_gangoffour(G, C) # Form closed-loop system
bodeplot(Gcl, lab=["S" "CS" "PS" "T"], plotphase=false) |> display # Plot gang of four
bodeplot(Gcl, lab=["S" "PS" "CS" "T"], plotphase=false) |> display # Plot gang of four
```
Note, the last input of Gcl is the negative of the `PS` and `T` transfer functions from `gangoffour2`. To get a transfer matrix with the same sign as [`G_PS`](@ref) and [`input_comp_sensitivity`](@ref), call `extended_gangoffour(P, C, pos=false)`.
See `glover_mcfarlane` from RobustAndOptimalControl.jl for an extended example. See also `ncfmargin` and `feedback_control` from RobustAndOptimalControl.jl.
Expand Down

0 comments on commit a7cd0f0

Please sign in to comment.