agentleFS
90184479018447/julia-pro-p/skills/control-theory/SKILL.md

control-theory

Skill0 starsChanged 3 days agoMITView on GitHub

Control design on a process model with ControlSystems.jl: margins and crossover, PID tuning with dead time, LQR and pole placement, and MPC with constraints. Use when designing or tuning a controller.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use it when the reason is one of these: hard input or state constraints, MIMO interaction, or dead time long enough that no PID can be …

    line 64

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Control theory on a process model

The work is not typing a transfer function. It is deciding which model form the plant deserves, what margin the loop needs, and which of the four designs — PID, LQR, placement, MPC — the process actually justifies.

Depth

TopicWhere
nonlinear plant, equilibria, bifurcationnonlinear-dynamics
closed-loop ODE integration and eventsdifferential-equations

Pick the model form

PlantFormWhy
SISO, one dominant time constant, dead timetransfer functionmargins are readable directly
MIMO, or states you care about individuallystate spacecontrollability and observability are computable
dead time τ of the same order as the dynamicsdelay systema Padé fit changes phase where the loop lives
nonlinear (reactor, column, CSTR)linearise at the operating pointthe loop is only valid near it
using ControlSystemsBase
G = tf([10], [1, 3, 10])          # 10 / (s^2 + 3s + 10)
C = tf([5, 1], [1, 0])            # PI: (5s + 1)/s
L = C * G                         # open loop, series by multiplication
T = feedback(L)                   # closed loop
poles(T); margin(L)

State space: sys = ss(A, B, C, D), then rank(ctrb(A, B)) and rank(obsv(A, C)) against size(A, 1). A rank shortfall answers "why does this controller not work" more cheaply than any simulation.

Margins are the language

margin(L) returns the gain margin (absolute magnitude), the phase margin in degrees, and the two crossover frequencies. Two numbers and one physical fact:

  • Gain margin ≥ 6 dB, phase margin ≥ 30–45°. Below that the loop is one parameter change away from oscillation.
  • Dead time spends phase linearly: a delay of τ costs 57.3·ω·τ degrees at frequency ω. So crossover must satisfy ω_c·τ ≲ 0.5 (about 29° of the budget) or no gain gives the loop a healthy margin.
  • The margin is only as good as the model. Recompute it with every fitted parameter moved ±20% and the dead time by one sample. A margin that survives only at the nominal point is not a margin.

PID

Each term buys one thing: K_p speed, K_i removal of steady-state offset, K_d damping at the cost of noise amplification — which is why a real PID carries a derivative filter, K_d s/(τ_f s + 1) with τ_f ≈ 0.1 τ_d.

SituationTuning
model known, want a stated closed-loop time constantIMC/lambda: K_c = τ/(K(λ + θ)), τ_i = τ, with λ between τ/3 and τ
no model, plant can be pushed to oscillationZiegler-Nichols from ultimate gain and period — aggressive, expect roughly 25% overshoot
integrating plant (level, pressure)proportional on the level, slow integral, check windup before anything else

Anti-windup is part of the controller, not a refinement: clamp the integral while the actuator saturates, or the loop overshoots on every recovery. Sample at least 10× faster than the closed-loop bandwidth.

LQR and pole placement

K, S, E = lqr(A, B, Q, R) minimises ∫ x′Qx + u′Ru. Read Q and R as "how much I care about this state" and "how much actuator I am willing to spend", and start from Bryson's rule: Q_ii = 1/max(x_i)², R_jj = 1/max(u_j)². Scaling both by the same constant changes nothing; only their ratio moves the poles.

LQR has no integral action, so against a model mismatch it holds a steady-state offset. A loop that must track a setpoint adds an integrator state to the plant before designing. place(A, B, poles) hits exact pole locations but is ill-conditioned on fast systems and can demand enormous gain — prefer LQR unless the poles themselves are the specification.

MPC

Use it when the reason is one of these: hard input or state constraints, MIMO interaction, or dead time long enough that no PID can be detuned enough. Otherwise the PID is the cheaper loop with the better failure mode.

The formulation is the same every time: predict over horizon N with the linear model, minimise Σ x′Qx + u′Ru subject to x_{k+1} = Ax_k + Bu_k, input and state bounds, then apply only the first move and re-solve at the next sample. Use a horizon of 2–3× the settling time, on the same model whose margins you checked.

Tools: JuMP with a QP solver (OSQP, HiGHS) for the general case — see ../advanced-optimization/SKILL.md — or ModelPredictiveControl.jl for the standard linear setup. Two failures are diagnoses rather than bugs: the solver reporting infeasible means the bounds and the reference cannot coexist within the horizon, and a persistent offset under a disturbance means the model has no disturbance state, which offset-free MPC requires.

Traps

  • Padé-approximating dead time to make the tools work. A 2nd-order Padé matches phase near ω = 0 and diverges above 1/τ; a loop tuned on the Padé model oscillates on the real plant.
  • Tuning until the step response looks good. The step is one operating point; the margin and the ±20% sweep are the claims.
  • Discretising after designing. Sampling at 1 Hz a loop with 10 rad/s bandwidth adds a half-sample delay that eats the margin just paid for.
  • Saturation unmodelled. A controller that cannot saturate in the model passes every test and fails on the first startup.
  • A nonlinear plant with a linear claim. State the operating point beside every margin you report.

Done when

The plant is a transfer function or state-space pair whose controllability and observability you computed, the specs are numbers (settling time, overshoot, steady-state error), and the loop is closed around it: gain margin above 6 dB and phase margin above 30° read off the open-loop response, step and disturbance responses simulated, and the same margins holding with every plant parameter perturbed by ±20% and the dead time by one sample.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.