Skip to content

Commit 13bb219

Browse files
authored
Merge pull request #113 from baggepinnen/analysis_point
Update analysis points to use find/replace in MTK
2 parents b7a9196 + d70e7c7 commit 13bb219

File tree

6 files changed

+303
-138
lines changed

6 files changed

+303
-138
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ version = "1.5.0"
55

66
[deps]
77
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
8+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
89
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
910
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
1011
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1112

1213
[compat]
1314
IfElse = "0.1"
14-
ModelingToolkit = "8"
15+
ModelingToolkit = "8.24"
1516
OffsetArrays = "1"
1617
Symbolics = "4.9"
1718
julia = "1.6"

docs/src/API/linear_analysis.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Linear analysis refers to the process of linearizing a nonlinear model and analy
77

88
- [`get_sensitivity`](@ref) get the [sensitivity function (wiki)](https://en.wikipedia.org/wiki/Sensitivity_(control_systems)), $S(s)$, as defined in the field of control theory.
99
- [`get_comp_sensitivity`](@ref) get the complementary sensitivity function $T(s) : S(s)+T(s)=1$.
10-
- [`get_looptransfer`](@ref) get the (open) loop-transfer function where the loop starts and ends in the analysis point.
11-
- [`linearize`](@ref) can be called with two analysis points denoting the input and output of the linearized system. Parts of the model not appearing between the input and output will be removed.
10+
- [`get_looptransfer`](@ref) get the (open) loop-transfer function where the loop starts and ends in the analysis point. For a typical simple feedback connection with a plant $P(s)$ and a controller $C(s)$, the loop-transfer function at the plant output is $P(s)C(s)$.
11+
- [`linearize`](@ref) can be called with two analysis points denoting the input and output of the linearized system.
1212
- [`open_loop`](@ref) return a new (nonlinear) system where the loop has been broken in the analysis point, i.e., the connection the analysis point usually implies has been removed.
1313

1414
An analysis point can be created explicitly using the constructor [`AnalysisPoint`](@ref), or automatically when connecting two causal components using `connect`:
@@ -52,7 +52,7 @@ We create `ControlSystemsBase.StateSpace` objects using
5252
using ControlSystemsBase, Plots
5353
S = ss(matrices_S...)
5454
T = ss(matrices_T...)
55-
bodeplot([S, T], lab=["S" "" "T" ""])
55+
bodeplot([S, T], lab=["S" "" "T" ""], plot_title="Bode plot of sensitivity functions", margin=5Plots.mm)
5656
```
5757

5858
The sensitivity functions obtained this way should be equivalent to the ones obtained with the code below
@@ -79,14 +79,28 @@ L = P*(-C) # Add the minus sign to build the negative feedback into the controll
7979

8080
To obtain the transfer function between two analysis points, we call `linearize`
8181
```@example LINEAR_ANALYSIS
82-
matrices_P = linearize(sys, :plant_input, :plant_output)[1]
82+
matrices_PS = linearize(sys, :plant_input, :plant_output)[1]
8383
```
84-
this particular transfer function should be equivalent to the linear system `P`, i.e., equivalent to this call
85-
```@example LINEAR_ANALYSIS
86-
@unpack input, output = P # To get the correct namespace
87-
linearize(P, [input.u], [output.u])[1]
84+
this particular transfer function should be equivalent to the linear system `P(s)S(s)`, i.e., equivalent to
85+
```@example LINEAR_ANALYSIS_CS
86+
feedback(P, C)
87+
```
88+
89+
### Obtaining transfer functions
90+
A statespace system from [ControlSystemsBase](https://juliacontrol.github.io/ControlSystems.jl/latest/man/creating_systems/) can be converted to a transfer function using the function `tf`:
91+
```@example LINEAR_ANALYSIS_CS
92+
tf(S)
8893
```
8994

95+
## Gain and phase margins
96+
Further linear analysis can be performed using the [analysis methods from ControlSystemsBase](https://juliacontrol.github.io/ControlSystems.jl/latest/lib/analysis/). For example, calculating the gain and phase margins of a system can be done using
97+
```@example LINEAR_ANALYSIS_CS
98+
margin(P)
99+
```
100+
(they are infinite for this system). A Nyquist plot can be produced using
101+
```@example LINEAR_ANALYSIS_CS
102+
nyquistplot(P)
103+
```
90104
## Index
91105
```@index
92106
Pages = ["linear_analysis.md"]

src/Blocks/Blocks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export Integrator, Derivative, FirstOrder, SecondOrder, StateSpace
2626
export PI, LimPI, PID, LimPID
2727
include("continuous.jl")
2828

29-
export AnalysisPoint, expand_analysis_points, get_sensitivity, get_comp_sensitivity,
29+
export AnalysisPoint, get_sensitivity, get_comp_sensitivity,
3030
get_looptransfer, open_loop
3131
include("analysis_points.jl")
3232

0 commit comments

Comments
 (0)