Skip to content

Commit 6928f51

Browse files
Fix warnings in DC Motor PI tutorial
- Add complete initial conditions for all state variables (L1.i, inertia.w, inertia.phi, pi_controller.int.x) to avoid underdetermined system warning - Add note about Pluto-specific variable naming requirements - Use unique variable names in sensitivity analysis to avoid conflicts Fixes #410 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4778382 commit 6928f51

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

docs/src/tutorials/dc_motor_pi.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,20 @@ Now the model can be simulated. Typical rotational mechanical systems are descri
7575
(differential algebraic equations), however in this case, ModelingToolkit can simplify the model enough
7676
so that it can be represented as a system of `ODEs` (ordinary differential equations).
7777

78+
!!! note "Initial Conditions"
79+
We provide complete initial conditions for all state variables to avoid initialization warnings.
80+
These include the inductor current, inertia angular velocity and position, and the PI controller integrator state.
81+
7882
```@example dc_motor_pi
7983
sys = mtkcompile(model)
80-
prob = ODEProblem(sys, [sys.L1.i => 0.0], (0, 6.0))
84+
# Provide complete initial conditions for all state variables
85+
u0 = Dict(
86+
sys.L1.i => 0.0, # Initial inductor current
87+
sys.inertia.w => 0.0, # Initial angular velocity
88+
sys.inertia.phi => 0.0, # Initial angle
89+
sys.pi_controller.int.x => 0.0 # Initial PI integrator state
90+
)
91+
prob = ODEProblem(sys, u0, (0, 6.0))
8192
sol = solve(prob)
8293
8394
p1 = plot(sol.t, sol[sys.inertia.w], ylabel = "Angular Vel. in rad/s",
@@ -87,6 +98,11 @@ p2 = plot(sol.t, sol[sys.load.tau.u], ylabel = "Disturbance in Nm", label = "")
8798
plot(p1, p2, layout = (2, 1))
8899
```
89100

101+
!!! note "Pluto Notebooks"
102+
If you're using this example in a Pluto notebook, note that Pluto requires each variable to have a unique name.
103+
If you encounter "Multiple definitions" errors, rename variables accordingly (e.g., `simplified_sys1`, `simplified_sys2`, etc.).
104+
This is due to Pluto's reactive behavior where all variables must be uniquely named for automatic dependency tracking.
105+
90106
## Closed-loop analysis
91107

92108
When implementing and tuning a control system in simulation, it is a good practice to analyze the closed-loop properties and verify robustness of the closed-loop with respect to, e.g., modeling errors. To facilitate this, we added two analysis points to the set of connections above, more specifically, we added the analysis points named `:y` and `:u` to the connections (for more details on analysis points, see [Linear Analysis](@ref))
@@ -107,12 +123,14 @@ T(s) &= \dfrac{P(s)C(s)}{I + P(s)C(s)}
107123

108124
```@example dc_motor_pi
109125
using ControlSystemsBase
126+
# Get sensitivity function
110127
matrices_S,
111-
simplified_sys = Blocks.get_sensitivity(
128+
simplified_sys_S = Blocks.get_sensitivity(
112129
model, :y, op = Dict(unknowns(sys) .=> 0.0))
113130
So = ss(matrices_S...) |> minreal # The output-sensitivity function as a StateSpace system
131+
# Get complementary sensitivity function
114132
matrices_T,
115-
simplified_sys = Blocks.get_comp_sensitivity(
133+
simplified_sys_T = Blocks.get_comp_sensitivity(
116134
model, :y, op = Dict(unknowns(sys) .=> 0.0))
117135
To = ss(matrices_T...)# The output complementary sensitivity function as a StateSpace system
118136
bodeplot([So, To], label = ["S" "T"], plot_title = "Sensitivity functions",
@@ -123,7 +141,7 @@ Similarly, we may compute the loop-transfer function and plot its Nyquist curve
123141

124142
```@example dc_motor_pi
125143
matrices_L,
126-
simplified_sys = Blocks.get_looptransfer(
144+
simplified_sys_L = Blocks.get_looptransfer(
127145
model, :y, op = Dict(unknowns(sys) .=> 0.0))
128146
L = -ss(matrices_L...) # The loop-transfer function as a StateSpace system. The negative sign is to negate the built-in negative feedback
129147
Ms, ωMs = hinfnorm(So) # Compute the peak of the sensitivity function to draw a circle in the Nyquist plot

0 commit comments

Comments
 (0)