Skip to content

Commit a7cd0f0

Browse files
committed
make feedback handle numbers in signal spec.
1 parent 2a8aa33 commit a7cd0f0

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

lib/ControlSystemsBase/src/connections.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ function feedback(sys1::AbstractStateSpace, sys2::AbstractStateSpace;
331331
if !(isa(Y2, Colon) || allunique(Y2)); @warn "Connecting single output to multiple inputs Y2=$Y2"; end
332332
if !(isa(U1, Colon) || allunique(U1)); @warn "Connecting multiple outputs to a single input U1=$U1"; end
333333
if !(isa(U2, Colon) || allunique(U2)); @warn "Connecting a single output to multiple inputs U2=$U2"; end
334+
U1 isa Number && (U1 = [U1])
335+
Y1 isa Number && (Y1 = [Y1])
336+
U2 isa Number && (U2 = [U2])
337+
Y2 isa Number && (Y2 = [Y2])
338+
W1 isa Number && (W1 = [W1])
339+
Z1 isa Number && (Z1 = [Z1])
340+
W2 isa Number && (W2 = [W2])
341+
Z2 isa Number && (Z2 = [Z2])
334342

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

400408
R2 = try
401409
inv(I - α*s1_D22*s2_D22)
402410
catch
403-
error("Ill-posed feedback interconnection, I - α*s2_D22*s1_D22 or I - α*s2_D22*s1_D22 not invertible")
411+
error("Ill-posed feedback interconnection, I - α*s1_D22*s2_D22 not invertible")
404412
end
405413

406414
s2_B2R2 = s2_B2*R2
@@ -463,7 +471,7 @@ r | - | | | | | y
463471
```
464472
"""
465473
function feedback2dof(P::TransferFunction{TE}, C::TransferFunction{TE}, F::TransferFunction{TE}) where TE
466-
!issiso(P) || return tf(feedback2dof(ss(P), ss(C), ss(F)))
474+
issiso(P) || return tf(feedback2dof(ss(P), ss(C), ss(F)))
467475
timeevol = common_timeevol(P, C, F)
468476

469477
Pn,Pd = numpoly(P)[], denpoly(P)[]

lib/ControlSystemsBase/src/pid_design.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ The `form` can be chosen as one of the following (determines how the arguments `
131131
This controller has negative feedback built in, and the closed-loop system from `r` to `y` is thus formed as
132132
```
133133
Cr, Cy = C[1, 1], C[1, 2]
134-
feedback(P, Cy, pos_feedback=true)*Cr # Alternative 1
135-
feedback(P, -Cy)*Cr # Alternative 2
134+
feedback(P, Cy, pos_feedback=true)*Cr # Alternative 1
135+
feedback(P, -Cy)*Cr # Alternative 2
136+
feedback(P, C, U2=2, W2=1, W1=[], pos_feedback=true) # Alternative 3, less pretty but more efficient, returns smaller realization
136137
```
137138
"""
138139
function pid_2dof(args...; state_space = true, Ts = nothing, disc = :tustin, kwargs...)

lib/ControlSystemsBase/src/sensitivity_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ T = G[P.ny+1:end, P.ny+1:end] # Input complimentary sensitivity function
156156
The gang of four can be plotted like so
157157
```julia
158158
Gcl = extended_gangoffour(G, C) # Form closed-loop system
159-
bodeplot(Gcl, lab=["S" "CS" "PS" "T"], plotphase=false) |> display # Plot gang of four
159+
bodeplot(Gcl, lab=["S" "PS" "CS" "T"], plotphase=false) |> display # Plot gang of four
160160
```
161161
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)`.
162162
See `glover_mcfarlane` from RobustAndOptimalControl.jl for an extended example. See also `ncfmargin` and `feedback_control` from RobustAndOptimalControl.jl.

0 commit comments

Comments
 (0)