Goal. Design a controller that drives the rotor to a commanded speed setpoint, rejecting disturbances (wind, battery droop, rotor wear), and is cheap enough to run in real time on the MCU.

Closed-loop control in one paragraph

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:

  1. PI โ€” the universal starting point. Tune, understand, measure its limits.
  2. Super-Twisting sliding-mode โ€” a robust non-linear controller that works with the Picooz plant without parameter-specific tuning.

Controller 1 โ€” PI baseline

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) $$

  • \(K_p\) is the instantaneous response โ€” larger \(K_p\) = faster but more oscillatory.
  • \(K_i\) is the integral gain โ€” it drives the steady-state error to zero.

Tuning a PI on the identified Picooz model

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:

  1. Cross-over frequency: pick \(\omega_c \sim 1/(3\tau)\) โ€” a bandwidth well below the plant’s non-linear limits.
  2. \(K_p = \omega_c / k\) and \(K_i = \omega_c^2 / (2k)\) are sensible starting values.
  3. Simulate in Simulink with the grey-box plant; iterate.

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.


Controller 2 โ€” Super-Twisting sliding-mode (SOSM)

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.

Intuition in three steps

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 $$

  • Two gains: \(k_1\) and \(k_2\).
  • The control signal \(u(t)\) is continuous โ€” no chatter.
  • Finite-time convergence, robust to any disturbance whose derivative is bounded by some \(L\).
  • A sufficient stability condition: \(k_2 > L\) and \(k_1^{2} \geq 4L\).

Tuning rules-of-thumb

  • Estimate a plausible disturbance-derivative bound \(L\). For the Picooz, \(L\) is dominated by battery voltage droop and mechanical changes (gust, rotor wear) โ€” a few V/s or rad/sยฒ in normalised units.
  • Pick \(k_2 \approx 2 L\) (safety margin) and \(k_1 \approx 2\sqrt{k_2}\).
  • Simulate with the identified plant. Adjust if the response is too slow (increase both) or chatters at the surface (increase only \(k_2\), keep \(k_1\) proportional).
Super-Twisting controller block diagram

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.


Four controllers worth comparing (as exercises)

Once the PI and Super-Twisting controllers run, try the in-betweens โ€” they are all one-subsystem-swap away in Simulink:

ControllerStrengthWeakness
PITrivial to tune, universalChatters near non-linearity transitions
Gain-scheduled PIBetter than a single PIOne PI per operating point; clumsy
Feedback linearisation + PICancels non-linearity exactlyRelies on the model being exactly right
Super-TwistingRobust, model-light, two gainsRequires 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.


Downloadable assets for the closed loop

The tutorial ships both controllers as standalone subsystems that you drop into the simulation or deployment model:

  • PI baseline โ€” standard Discrete PID block (no file needed; place it from Simulink’s Discrete library).
  • Super-Twisting โ€” a few Simulink blocks around 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.


What’s next

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