Continuous.Tests.PIDTextbook
Text-book-mode harness for MSL cross-validation of the PID controller.
Our PID is a 2-DOF controller (setpoint weighting). It reduces exactly to the single-input text-book PID of Modelica.Blocks.Continuous.PID when wp = 1, wd = 1, and the measurement u_m is held at zero — then every term acts on the same signal u_s, and the internal integrator and derivative states evolve identically to MSL's I.y and D.x.
This harness mirrors ModelicaTest.Blocks.Continuous: the same ramp (offset = 0.5, start_time = 0.5, duration = 2) drives u_s, with Ti = 0.5, Td = 0.1, Nd = 10, and the internal states initialized to zero (InitialState in MSL). Cross-validated against pID.I.y / pID.D.x in test/msl_snapshots/PID.csv by test/msl_validation/pid.jl.
Usage
BlockComponents.Continuous.Tests.PIDTextbook()
Behavior
Source
"""
Text-book-mode harness for MSL cross-validation of the PID controller.
Our `PID` is a 2-DOF controller (setpoint weighting). It reduces *exactly* to the
single-input text-book PID of `Modelica.Blocks.Continuous.PID` when `wp = 1`,
`wd = 1`, and the measurement `u_m` is held at zero — then every term acts on the
same signal `u_s`, and the internal integrator and derivative states evolve
identically to MSL's `I.y` and `D.x`.
This harness mirrors `ModelicaTest.Blocks.Continuous`: the same ramp
(`offset = 0.5`, `start_time = 0.5`, `duration = 2`) drives `u_s`, with `Ti = 0.5`,
`Td = 0.1`, `Nd = 10`, and the internal states initialized to zero
(`InitialState` in MSL). Cross-validated against `pID.I.y` / `pID.D.x` in
`test/msl_snapshots/PID.csv` by `test/msl_validation/pid.jl`.
"""
test component PIDTextbook
"Ramp driving the setpoint (matches the MSL Continuous test ramp)"
ramp = BlockComponents.Sources.Ramp(offset = 0.5, start_time = 0.5, duration = 2.0, height = 1.0) {"Dyad": {"placement": {"diagram": {"x1": 10, "y1": 20, "x2": 110, "y2": 120}}}}
"Zero source for the measurement input"
zero = BlockComponents.Sources.Constant(k = 0.0) {
"Dyad": {"placement": {"diagram": {"x1": 20, "y1": 200, "x2": 120, "y2": 300}}}
}
"PID reduced to text-book form (wp = wd = 1, u_m = 0)"
pid = BlockComponents.Continuous.PID(Ti = 0.5, Td = 0.1, Nd = 10, wp = 1, wd = 1) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 160, "x2": 400, "y2": 60}}}
}
relations
connect(ramp.y, pid.u_s) {
"Dyad": {"edges": [{"S": 1, "M": [{"x": 170, "y": 70}, {"x": 170, "y": 133}], "E": 2}]}
}
connect(zero.y, pid.u_m) {
"Dyad": {"edges": [{"S": 1, "M": [{"x": 240, "y": 250}, {"x": 240, "y": 87}], "E": 2}]}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 1.1,
"atol": {"pid.integrator.y": 0.001, "pid.derivative.x": 0.001, "pid.y": 0.001},
"expect": {"signals": ["pid.integrator.y", "pid.derivative.x", "pid.y"]}
}
}
}
}
endFlattened Source
"""
Text-book-mode harness for MSL cross-validation of the PID controller.
Our `PID` is a 2-DOF controller (setpoint weighting). It reduces *exactly* to the
single-input text-book PID of `Modelica.Blocks.Continuous.PID` when `wp = 1`,
`wd = 1`, and the measurement `u_m` is held at zero — then every term acts on the
same signal `u_s`, and the internal integrator and derivative states evolve
identically to MSL's `I.y` and `D.x`.
This harness mirrors `ModelicaTest.Blocks.Continuous`: the same ramp
(`offset = 0.5`, `start_time = 0.5`, `duration = 2`) drives `u_s`, with `Ti = 0.5`,
`Td = 0.1`, `Nd = 10`, and the internal states initialized to zero
(`InitialState` in MSL). Cross-validated against `pID.I.y` / `pID.D.x` in
`test/msl_snapshots/PID.csv` by `test/msl_validation/pid.jl`.
"""
test component PIDTextbook
"Ramp driving the setpoint (matches the MSL Continuous test ramp)"
ramp = BlockComponents.Sources.Ramp(offset = 0.5, start_time = 0.5, duration = 2.0, height = 1.0) {"Dyad": {"placement": {"diagram": {"x1": 10, "y1": 20, "x2": 110, "y2": 120}}}}
"Zero source for the measurement input"
zero = BlockComponents.Sources.Constant(k = 0.0) {
"Dyad": {"placement": {"diagram": {"x1": 20, "y1": 200, "x2": 120, "y2": 300}}}
}
"PID reduced to text-book form (wp = wd = 1, u_m = 0)"
pid = BlockComponents.Continuous.PID(Ti = 0.5, Td = 0.1, Nd = 10, wp = 1, wd = 1) {
"Dyad": {"placement": {"diagram": {"x1": 300, "y1": 160, "x2": 400, "y2": 60}}}
}
relations
connect(ramp.y, pid.u_s) {
"Dyad": {"edges": [{"S": 1, "M": [{"x": 170, "y": 70}, {"x": 170, "y": 133}], "E": 2}]}
}
connect(zero.y, pid.u_m) {
"Dyad": {"edges": [{"S": 1, "M": [{"x": 240, "y": 250}, {"x": 240, "y": 87}], "E": 2}]}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://BlockComponents/Example.svg"},
"tests": {
"case1": {
"stop": 1.1,
"atol": {"pid.integrator.y": 0.001, "pid.derivative.x": 0.001, "pid.y": 0.001},
"expect": {"signals": ["pid.integrator.y", "pid.derivative.x", "pid.y"]}
}
}
}
}
endTest Cases
Test Case case1
pltpltplt