A controller measures the error between the commanded setpoint \(\omega_{\text{ref}}\) and the measured speed \(\omega\), then computes a control input \(u\) that reduces this error to zero. The simplest choice is a PI (proportional + integral). PI works wonderfully on linear systems, and surprisingly well even on mildly non-linear ones โ but it struggles with strongly non-linear plants like our rotor with its exponential drag.
We’ll therefore go through two controllers:
Classical textbook:
$$ u(t) = K_{p}, e(t) + K_{i}\int_0^{t} e(\tau),d\tau \qquad\text{with}\quad e(t) = \omega_{\text{ref}}(t) - \omega(t) $$
With the identified model (\(\tau, k_2, k\)) from the previous page, a few rules-of-thumb on the linearised system around the operating point:
In Simulink the controller is a single Discrete PID block with the Back-calculation anti-wind-up scheme enabled. No custom code.
Why PI is not enough here. The exponential drag means the plant gain decreases as speed grows โ a PI tuned for low speed is sluggish at high speed, and vice versa. Gain scheduling (one PI per speed band) would fix this, at the cost of tuning several operating points. Super-Twisting gets the same robustness with one set of gains for the entire range.
Super-Twisting is a second-order sliding-mode controller. It handles strongly non-linear plants without needing a per-unit tuning pass, at the cost of two gains and a little theory.
Step 1 โ the sliding surface. Define the error \(s = \omega - \omega_{\text{ref}}\). The controller’s job is to drive \(s \to 0\) and keep it there.
Step 2 โ first-order sliding mode would use
$$ u(t) = -k,\operatorname{sign}(s(t)) $$
This guarantees \(s \to 0\) in finite time for any plant with bounded uncertainty, but produces a discontinuous control signal โ chatter โ that excites high-frequency unmodelled dynamics.
Step 3 โ Super-Twisting smooths the discontinuity with a continuous control law that still guarantees finite-time convergence:
$$ u(t) = -k_{1}\sqrt{|s(t)|},\operatorname{sign}(s(t)) ;+; \int_{0}^{t} -k_{2},\operatorname{sign}!\big(s(\tau)\big),d\tau $$

Every block is standard Simulink (Sum, Gain, Sqrt, Sign, Integrator). The resulting controller generates embedded C code that runs in under a microsecond on a dsPIC33AK512MPS506 @ 200 MIPS โ more than fast enough for the 1 kHz control loop the Picooz needs.
Once the PI and Super-Twisting controllers run, try the in-betweens โ they are all one-subsystem-swap away in Simulink:
| Controller | Strength | Weakness |
|---|---|---|
| PI | Trivial to tune, universal | Chatters near non-linearity transitions |
| Gain-scheduled PI | Better than a single PI | One PI per operating point; clumsy |
| Feedback linearisation + PI | Cancels non-linearity exactly | Relies on the model being exactly right |
| Super-Twisting | Robust, model-light, two gains | Requires understanding sliding-mode theory |
Swapping between them is a subsystem swap in Simulink โ the rest of the chain (acquisition, plant, logging) is identical. That is the payoff of MBD architecture: your controllers are interchangeable building blocks.
The tutorial ships both controllers as standalone subsystems that you drop into the simulation or deployment model:
sign(), sqrt(), and integrator.Both show up inside the simulation model on the next page. Compare them side by side on the identified plant before committing either to hardware.
With an identified plant and a working controller, the next step is to close the loop in simulation, then press Build to generate C code and flash the target.
Next โ 5. Simulate & Deploy
Back โ 3. Identification โ Five Methods