|
| 1 | +# Saturation / Rate-Limiter / Slew Blocks |
| 2 | + |
| 3 | +## Overview & Motivation |
| 4 | + |
| 5 | +Real actuators — valves, motors, heaters, servos — impose two distinct constraints on any command signal: a travel limit (the actuator cannot physically move past a hard stop) and a speed limit (the mechanism cannot slew arbitrarily fast without damaging itself or the system). Ignoring either constraint causes physically impossible commands, mechanical stress, and, in closed-loop systems, integrator wind-up that degrades recovery after saturation. |
| 6 | + |
| 7 | +These three primitives model exactly those constraints. Saturation enforces the travel limit by clipping the output to a fixed interval. The rate limiter enforces the speed limit by allowing the output to move at most a fixed amount per sample period. Composing them — applying the rate limiter first, then the saturator — guarantees every emitted sample simultaneously respects both bounds, making them the mandatory prerequisite for anti-windup in any integrating controller. |
| 8 | + |
| 9 | +## Mathematical Theory |
| 10 | + |
| 11 | +### Saturation |
| 12 | + |
| 13 | +Given bounds $[\ell, h]$ with $\ell < h$, saturation is defined as: |
| 14 | + |
| 15 | +$$y = \text{sat}(u) = \min\!\bigl(\max(u,\, \ell),\, h\bigr)$$ |
| 16 | + |
| 17 | +This is a memoryless, instantaneous projection onto the interval $[\ell, h]$. |
| 18 | + |
| 19 | +### Rate Limiter (Slew Limiter) |
| 20 | + |
| 21 | +Let $\Delta_{\max} = r \cdot T_s$ be the maximum permitted change per sample, where $r$ is the slew rate (units per second) and $T_s$ is the sample period (seconds). Define the state $y[n-1]$ as the last emitted output. The output at tick $n$ is: |
| 22 | + |
| 23 | +$$\delta[n] = \text{sat}_{\Delta_{\max}}(u[n] - y[n-1]) = \min\!\bigl(\max(u[n] - y[n-1],\,-\Delta_{\max}),\,+\Delta_{\max}\bigr)$$ |
| 24 | + |
| 25 | +$$y[n] = y[n-1] + \delta[n]$$ |
| 26 | + |
| 27 | +On the first sample (priming), $y[0] = u[0]$ and no limiting is applied, so the output tracks the first command exactly. |
| 28 | + |
| 29 | +### Composed Block (Slew-Then-Clamp) |
| 30 | + |
| 31 | +$$y_{\text{composed}}[n] = \text{sat}\!\bigl(y_{\text{slew}}[n]\bigr)$$ |
| 32 | + |
| 33 | +Applying the rate limiter before the saturator is essential. If the order were reversed (clamp then slew), a step command to a saturated bound would allow the rate limiter to move the output outside the saturation interval for one tick before the clamp could correct it. |
| 34 | + |
| 35 | +## Complexity Analysis |
| 36 | + |
| 37 | +| Case | Time | Space | Notes | |
| 38 | +|---------|--------|--------|-----------------------------------------------| |
| 39 | +| Best | $O(1)$ | $O(1)$ | Two compare-and-select operations | |
| 40 | +| Average | $O(1)$ | $O(1)$ | One multiply + two compares for rate limit | |
| 41 | +| Worst | $O(1)$ | $O(1)$ | Fixed instruction count; no branching on size | |
| 42 | + |
| 43 | +Each block maintains at most two scalar parameters and one scalar state word. The hot path is branch-light: `min`/`max` compile to conditional-move instructions on modern architectures. |
| 44 | + |
| 45 | +## Step-by-Step Walkthrough |
| 46 | + |
| 47 | +Parameters: $\ell = -0.5$, $h = 0.5$, $r = 0.1\,\text{s}^{-1}$, $T_s = 1\,\text{s}$ ($\Delta_{\max} = 0.1$). Step request: $u = 1.0$ for all ticks, starting from $y[-1] = 0$. |
| 48 | + |
| 49 | +| Tick $n$ | $u[n]$ | $\delta[n]$ | $y_{\text{slew}}[n]$ | $y_{\text{composed}}[n]$ | |
| 50 | +|----------|--------|-------------|----------------------|--------------------------| |
| 51 | +| 0 | 1.0 | 0.1 | 0.1 | 0.1 | |
| 52 | +| 1 | 1.0 | 0.1 | 0.2 | 0.2 | |
| 53 | +| 2 | 1.0 | 0.1 | 0.3 | 0.3 | |
| 54 | +| 3 | 1.0 | 0.1 | 0.4 | 0.4 | |
| 55 | +| 4 | 1.0 | 0.1 | 0.5 | 0.5 | |
| 56 | +| 5 | 1.0 | 0.1 | 0.6 | 0.5 (clamped) | |
| 57 | + |
| 58 | +The ramp is linear until the saturator clips it at $h = 0.5$. The rate limiter continues to advance its internal state, but the composed output is held at the bound. |
| 59 | + |
| 60 | +## Pitfalls & Edge Cases |
| 61 | + |
| 62 | +- **Zero slew rate**: $r = 0$ means $\Delta_{\max} = 0$; the output freezes at the primed value for all subsequent inputs. This is valid for a hold block but surprising if unintentional. |
| 63 | +- **Collapsed saturation** ($\ell = h$): every output equals that constant regardless of input. The rate limiter still advances but the saturator immediately overwrites the result. |
| 64 | +- **Priming semantics**: the first call to the rate limiter always passes through without limiting. Systems that require immediate rate-limiting from the first sample must call `Reset` with the desired initial state before the first control tick. |
| 65 | +- **Order of composition**: slew-then-clamp is the only order that guarantees simultaneous satisfaction of both constraints at every tick. |
| 66 | +- **Floating-point accumulation**: repeated addition of $\delta[n]$ can accumulate rounding error over many ticks. For long-running loops at high rate, the error remains bounded by machine epsilon times the number of steps times $\Delta_{\max}$. |
| 67 | + |
| 68 | +## Variants & Generalizations |
| 69 | + |
| 70 | +- **Asymmetric rate limiter**: use separate positive and negative slew rates $r^+$, $r^-$ to model actuators with different rise and fall speeds (e.g., a valve that opens slowly but closes fast). |
| 71 | +- **Variable-rate limiter**: replace the fixed $\Delta_{\max}$ with a schedule or feedback signal for gain-scheduled slew limiting. |
| 72 | +- **Deadband + saturation**: insert a deadband nonlinearity before the saturator to model mechanical backlash or sensor noise floors. |
| 73 | + |
| 74 | +## Applications |
| 75 | + |
| 76 | +- **Motor drives**: limit acceleration commands to prevent over-current trips while hard-bounding the velocity or position command within safe travel. |
| 77 | +- **Thermal control**: ramp heater power slowly to avoid thermal shock while clamping to the maximum safe power level. |
| 78 | +- **Anti-windup**: feed the saturated (clamped) output back to the integrator of a PID controller so accumulation stops when the actuator is pinned at a bound. |
| 79 | +- **Sensor fusion pre-processing**: slew-limit noisy sensor inputs before they enter an estimator to attenuate impulsive outliers without a dedicated filter. |
| 80 | + |
| 81 | +## Connections to Other Algorithms |
| 82 | + |
| 83 | +- **PidIncremental**: consumes the clamped output for anti-windup; the saturation block provides the feedback signal that stops integrator accumulation. |
| 84 | +- **BangBangHysteresis**: an alternative, discontinuous actuator constraint that switches between two fixed outputs; saturation is the continuous analog. |
| 85 | +- **ExponentialMovingAverage**: can approximate a low-pass slew effect but does not enforce a hard rate bound and has no priming concept. |
| 86 | + |
| 87 | +## References & Further Reading |
| 88 | + |
| 89 | +- K. J. Astrom, R. M. Murray, *Feedback Systems: An Introduction for Scientists and Engineers* (2008), sections on actuator saturation and integrator windup. |
| 90 | +- K. J. Astrom, T. Hagglund, *Advanced PID Control* (2006), Chapter 6: Anti-windup. |
0 commit comments