PI Controller (pi)
Corrects an error with proportional and integral action, and limits its output.
Group: Control · Kind: {"block":"pi","kind":"control"}
When to use it
Use it for the current, speed or voltage loop of a converter or drive. Use PID Controller when you need a derivative term.
Pins
| Pin | Domain | Meaning |
|---|---|---|
in |
signal | Error: reference minus feedback |
out |
signal | Controller output, kept between lo and hi |
Common parameters
kp: Strength of the reaction to error (Default: 1)ki: Strength of the reaction to past error (Default: 0)lo: Lowest value the output can reach (Default: -1e30)hi: Highest value the output can reach (Default: 1e30)
Parameters
| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
kp |
— | 1 | Strength of the reaction to error | |
ki |
1/s | 0 | Strength of the reaction to past error | |
lo |
— | -1e30 | Lowest value the output can reach | |
hi |
— | 1e30 | Highest value the output can reach | |
y0 |
— | 0 | Output at the start while the error is zero |
Parameter descriptions are in English in both languages.
Use for: Current loops · Voltage loops · Speed loops
Not for: Firmware loops at a sample rate → dpi · Loops that need a derivative → pid
Formulas
| Formula | Equation | Source |
|---|---|---|
| PI controller | C(s) = kp + ki/s | Åström & Murray, Feedback Systems, 2nd ed. (2021), ch. 11 (PID control) |
| Controller zero | fz = ki/(2π·kp) | Erickson & Maksimović, Fundamentals of Power Electronics, 3rd ed. (2020), ch. 9 (PI compensator) |
| Integral time | Ti = kp/ki | Åström & Hägglund, Advanced PID Control (2006), ch. 3 |
| Response to a constant error | y = min(kp·err + ki·err·t, hi) | Åström & Murray, Feedback Systems, 2nd ed. (2021), ch. 11 (PID control) |
Quick check
Inputs:
kp: Proportional gain = 500m —,kpki: Integral gain = 500 1/s,kierr: Constant error = 100m —t: Time since the error appeared = 1m shi: Upper output limit = 1 —,hi
Outputs:
fz: Zero frequency =ki/(2*pi*kp)Hzti: Integral time =kp/kisy: Output after t =min(kp*err + ki*err*t, hi)—
Model logic
- The block runs once per accepted solver step and adds ki·h·(in + previous in)/2 to its integral (trapezoid); a step that starts on a switching edge uses the input at its end.
- Anti-windup is by clamping: the integral is kept between lo - kp·in and hi - kp·in and the output between lo and hi, so it leaves a limit as soon as the error reverses.
- The integral starts at y0 clamped to lo and hi; the evaluations at t = 0 with no time step do not change it, so a loop starts at its operating point.
- The output follows the input in the same step through kp (direct feedthrough); an input that is not a finite number stops the run and names the block.
Model
out = kpe + kiintegral(e dt), held between lo and hi, where e is the input. The integral is kept inside lo - kpe ... hi - kpe, so the controller leaves a limit at once when the error reverses (anti-windup). The block has direct feedthrough through kp. The integral starts at y0, so a loop can start at its operating point.
Common mistakes
- The defaults are ki = 0 and no limits, so an unedited PI Controller is only a gain with no windup protection. Set ki, lo and hi.
- If the input depends on the output only through blocks with no delay, such as a plant modelled as a plain Gain, the run stops. Put an Integrator or a lag in the plant path.
- The unit of ki is the unit of kp per second. For a current loop a common rule is kp = L times the bandwidth and ki = R times the bandwidth, with the bandwidth in rad/s; using Hz makes the loop about six times too slow.
Problems rules: control.saturated, solver.control
Datasheet and sources
No datasheet applies. The gains come from the plant (L and R, or J and the torque constant) and your target bandwidth, and the limits from the actuator range, such as the current limit or 0 to 1 for a duty.
Example
Open the example with the command file.openExample and the name demo:pi.
Generated by cargo xtask reference from the usage texts and parameter specs. Do not edit by hand.