Qurak

Proportional derivative controller

Example 3 steps, run in order in one session. Every step was executed against the engine and the output below is what it produced.

Step 1
system = {x''[t] == u[t], x'[0] == x[0] == 0, u[0] == 1};
control = WhenEvent[Mod[t, τ], u[t] -> kp(xref - x[t] - td x'[t])];
params = {kp -> 1, td -> 1, τ -> 1, xref -> 1};

No output - this step sets something up for the next one.

Step 2
sol = NDSolve[{system, control} /. params, {x, u}, {t, 0, 12}, DiscreteVariables -> u];

No output - this step sets something up for the next one.

Step 3
Plot[Evaluate[{xref /. params, x[t], u[t]} /. sol], {t, 0, 12}, PlotLegends -> {"xref", "x(t)", "u(t)"}]
Output
-Graphics-

Functions used

Related recipes

All recipes · Function reference · Use this from an MCP client