Skip to content

Commit 8e20ebd

Browse files
committed
clarify causality of analysis_point and add test for it
1 parent 9950a35 commit 8e20ebd

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/Blocks/analysis_points.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,24 @@ function Base.show(io::IO, ::MIME"text/plain", ap::AnalysisPoint)
8585
end
8686

8787
"""
88-
connect(in, ap::AnalysisPoint, out)
89-
connect(in, ap_name::Symbol, out)
88+
connect(output_connector, ap_name::Symbol, input_connector)
89+
connect(output_connector, ap::AnalysisPoint, input_connector)
9090
91-
Connect `in` and `out` with an [`AnalysisPoint`](@ref) inbetween.
92-
The incoming connection `in` is expected to be of type [`RealOutput`](@ref), and vice versa.
91+
Connect `output_connector` and `input_connector` with an [`AnalysisPoint`](@ref) inbetween.
92+
The incoming connection `output_connector` is expected to be of type [`RealOutput`](@ref), and vice versa.
93+
NOTE: The connection is assumed to be *causal*, meaning that
94+
```
95+
connect(C.output, :plant_input, P.input)
96+
```
97+
is correct, whereas
98+
```
99+
connect(P.input, :plant_input, C.output)
100+
```
101+
typically is not (unless the model is an inverse model).
93102
94103
# Arguments:
95-
- `in`: A connector of type [`RealOutput`](@ref)
96-
- `out`: A connector of type [`RealInput`](@ref)
104+
- `output_connector`: A connector of type [`RealOutput`](@ref)
105+
- `input_connector`: A connector of type [`RealInput`](@ref)
97106
- `ap`: An explicitly created [`AnalysisPoint`](@ref)
98107
- `ap_name`: If a name is given, an [`AnalysisPoint`](@ref) with the given name will be created automatically.
99108
"""

test/Blocks/test_analysis_points.jl

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ model = SystemModel()
186186
@named er = Add(k2=-1)
187187

188188
connections = [
189-
connect(r.output, :r, filt.input)
190-
connect(filt.output, er.input1)
191-
connect(pid.ctr_output, model.torque.tau)
192-
connect(model.inertia2.flange_b, sensor.flange)
193-
connect(er.input2, :y, sensor.phi)
194-
connect(er.output, :e, pid.err_input)
189+
connect(r.output, :r, filt.input)
190+
connect(filt.output, er.input1)
191+
connect(pid.ctr_output, :u, model.torque.tau)
192+
connect(model.inertia2.flange_b, sensor.flange)
193+
connect(sensor.phi, :y, er.input2)
194+
connect(er.output, :e, pid.err_input)
195195
]
196196

197197
closed_loop = ODESystem(connections, t, systems = [model, pid, filt, sensor, r, er], name = :closed_loop)
@@ -213,4 +213,12 @@ stepres = ControlSystemsBase.step(c2d(lsys, 0.001), 4)
213213
@test stepres.y[:] sol(0:0.001:4, idxs=model.inertia2.phi) rtol=1e-4
214214

215215
# plot(stepres, plotx=true, ploty=true, size=(800, 1200), leftmargin=5Plots.mm)
216-
# plot!(sol, vars = [model.inertia2.phi], sp=1, l=:dash)
216+
# plot!(sol, vars = [model.inertia2.phi], sp=1, l=:dash)
217+
218+
matrices, ssys = get_sensitivity(closed_loop, :y)
219+
So = ss(matrices...)
220+
221+
matrices, ssys = get_sensitivity(closed_loop, :u)
222+
Si = ss(matrices...)
223+
224+
@test tf(So) tf(Si)

0 commit comments

Comments
 (0)