Skip to content

Commit

Permalink
make feedback2dof work for any system type
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 12, 2025
1 parent 5982cc3 commit 2a8aa33
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
40 changes: 33 additions & 7 deletions docs/src/man/creating_systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Continuous-time transfer function model
```

The transfer functions created using this method will be of type `TransferFunction{SisoRational}`.
For more general expressions, it is often more convenient to define `s = tf("s")`:
For more general expressions, it is sometimes more convenient to define `s = tf("s")` (only use this approach for low-order systems).:
#### Example:
```julia
julia> s = tf("s")
Expand Down Expand Up @@ -295,10 +295,10 @@ The returned closed-loop system will have a state vector comprised of the state
---
Closed-loop system from reference to output
```
r ┌─────┐ ┌─────┐
───►│ │ u │ │ y
│ C ├────►│ P ├─┬─►
-┌►│ │ │ │ │
┌─────┐ ┌─────┐
r │ │ u │ │ y
──+►│ C ├────►│ P ├─┬─►
-│ │ │ │ │
│ └─────┘ └─────┘ │
│ │
└─────────────────────┘
Expand Down Expand Up @@ -396,6 +396,32 @@ Here, we have reversed the order of `P` and `C` to get the correct sign of the c

---

Two degree of freedom control system with feedforward ``F`` and feedback controller ``C``

```
+-------+
| |
+-----> F +----+
| | | |
| +-------+ |
| +-------+ | +-------+
r | - | | | | | y
+--+-----> C +----+----> P +---+-->
| | | | | |
| +-------+ +-------+ |
| |
+--------------------------------+
```

```math
Y = (F+C)\dfrac{P}{I + PC}R
```

Code: `feedback(P,C)*(F+C)` or `feedback2dof(P, C, F)`
- [`feedback2dof`](@ref)

---

Linear fractional transformation

```
Expand Down Expand Up @@ -445,9 +471,9 @@ I & P
w_1 \\ w_2
\end{bmatrix}
```
Code: This function requires the package [RobustAndOptimalControl.jl](https://juliacontrol.github.io/RobustAndOptimalControl.jl/dev/).
Code:
```julia
RobustAndOptimalControl.extended_gangoffour(P, C, pos=true)
extended_gangoffour(P, C, pos=true)
# For SISO P
S = G[1, 1]
PS = G[1, 2]
Expand Down
8 changes: 6 additions & 2 deletions lib/ControlSystemsBase/src/connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ end
feedback2dof(B,A,R,S,T) = tf(conv(B,T),zpconv(A,R,B,S))

"""
feedback2dof(P::TransferFunction, C::TransferFunction, F::TransferFunction)
feedback2dof(P, C, F)
Return the transfer function
`P(F+C)/(1+PC)`
Expand All @@ -463,7 +463,7 @@ r | - | | | | | y
```
"""
function feedback2dof(P::TransferFunction{TE}, C::TransferFunction{TE}, F::TransferFunction{TE}) where TE
!issiso(P) && error("Feedback not implemented for MIMO systems")
!issiso(P) || return tf(feedback2dof(ss(P), ss(C), ss(F)))
timeevol = common_timeevol(P, C, F)

Pn,Pd = numpoly(P)[], denpoly(P)[]
Expand All @@ -473,6 +473,10 @@ function feedback2dof(P::TransferFunction{TE}, C::TransferFunction{TE}, F::Trans
tf(Cd*Pn*Fn + Pn*Cn*Fd, den, timeevol)
end

function feedback2dof(P,C,F)
feedback(P,C)*(F+C)
end

"""
lft(G, Δ, type=:l)
Expand Down
2 changes: 2 additions & 0 deletions lib/ControlSystemsBase/test/test_connections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ F = tf(1.0, [1,1])
@test feedback2dof(P0, C, 0*F) == feedback(P0*C)
@test_nowarn feedback2dof(P0, C, F)

C = pid(1, 0, 1, form=:parallel)
hinfnorm(minreal(feedback2dof(ss(P0), ss(C*F), ss(F)) - feedback2dof(P0, C*F, F)))[1] < 1e-8


G1 = tf([1, 0],[1, 2, 2])
Expand Down

0 comments on commit 2a8aa33

Please sign in to comment.