# pidwright

A discrete-time PID controller that behaves itself in a real loop, not just on
paper.

What you get beyond the naive three-term version:

- **Output clamping** — hard min/max on the command so you never ask the
  actuator for something it can't do.
- **Anti-windup** — the integrator freezes while the output is saturated, so it
  doesn't quietly wind up to an enormous value and then overshoot for ages once
  the error flips.
- **Derivative on measurement** — the derivative term watches the process
  variable, not the error, so stepping the setpoint doesn't produce a violent
  spike ("derivative kick").

Unit- and clock-agnostic: you supply `dt` on every `update`.

## Usage

```rust
use pidwright::Pid;

let mut pid = Pid::new(2.0, 1.0, 0.05).with_limits(0.0, 100.0);

let mut process = 0.0;
let dt = 0.02;
loop {
    let command = pid.update(/*setpoint*/ 50.0, process, dt);
    // ... apply `command` to your actuator, read the sensor back into `process`
#   break;
}
```

Call `pid.reset()` on a mode switch or after the loop has been open, so stale
integral/derivative state doesn't bump the output when you re-engage.

## License

Released into the public domain under the Unlicense.
