Expand description
High-performance PID controller with no_std support, IIR-filtered derivative,
configurable anti-windup, and optional thread safety.
§Architecture
The library is split into two layers:
- Pure function:
pid_computetakes aControllerConfigandPidState, returns a control output and updated state. Works inno_stdenvironments. - Stateful controllers (requires
std):PidControllerandThreadSafePidControllerwrap the pure function with automatic state management and performance statistics.
§Quick start
use pidgeon::{ControllerConfig, PidState, pid_compute};
// 1. Build a validated config
let config = ControllerConfig::builder()
.with_kp(2.0)
.with_ki(0.5)
.with_kd(0.1)
.with_setpoint(100.0)
.with_output_limits(0.0, 255.0)
.build()
.unwrap();
// 2. Start with default state
let mut state = PidState::default();
// 3. Run the control loop
let dt = 0.01; // 10 ms
for _ in 0..100 {
let process_value = 80.0; // read from sensor
let (output, next_state) = pid_compute(&config, &state, process_value, dt).unwrap();
state = next_state;
// apply `output` to actuator
}§Feature flags
| Feature | Default | Effect |
|---|---|---|
std | yes | Enables PidController, ThreadSafePidController, and Error impl |
debugging | no | Streams PID telemetry via Iggy.rs (implies std) |
benchmarks | no | Enables criterion benchmarks (implies std) |
wasm | no | Swaps std::time for web_time (implies std) |
Structs§
- Controller
Config - Validated, immutable PID controller configuration.
- Controller
Config Builder - Builder for
ControllerConfig. Collects PID parameters without validation untilbuild()is called. - Controller
Statistics - Runtime performance metrics for a
PidController. - PidController
- Stateful PID controller with built-in performance statistics.
- PidState
- Persistent state carried between
pid_computeinvocations. - Thread
Safe PidController - Thread-safe PID controller backed by
Arc<Mutex<PidController>>.
Enums§
- Anti
Windup Mode - Anti-windup strategy for the integral term.
- Derivative
Mode - Selects which signal the derivative term operates on.
- PidError
- Error type for PID controller operations.
Functions§
- pid_
compute - Computes one PID control step as a pure function.