pid-ctrl-0.1.0 has been yanked.
Overview
A proportional-integral-derivative (PID) controller.
Inspired by pid-rs
With cleaner API and assumptions (constant time delta, symmetrical limits) dropped.
Features
- Discrete time PID controller
- Defined for generic float types
- Attempts to conform to rust API Guidelines
#![no_std]
- Limits for each of p, i, d terms and output
- Calculates derivative term using measurement over error (no derivative kick on new setpoint)
- Clamps time interval to between
Float::epsilon()
andFloat::infinity()
Installation
cargo add pid-ctrl
Examples
let mut pid = new_with_pid;
let setpoint = 5.0;
let prev_measurement = 0.0;
// calling init optional. Setpoint and prev_measurement set to 0.0 by default.
// Recommended to avoid derivative kick on startup
pid.init;
let measurement = 0.0;
let time_delta = 1.0;
assert_eq!;
// changing pid constants
pid.kp.set_scale;
assert_eq!;
// setting symmetrical limits around zero
pid.kp.limits.set_limit;
assert_eq!;
let time_delta = 0.5;
assert_eq!;
// setting upper limits returns error if new value conflicts with lower limit
pid.ki.limits.try_set_upper.unwrap;
assert_eq!;
// time_delta gets clamped to Float::epsilon() - Float::infinity()
let measurement = 1.0;
let time_delta = -7.0;
pid.kd.set_scale;
assert_eq!;
// configure setpoint directly
pid.setpoint = 1.0;
assert_eq!;
Contribute
Feel free to raise issues.
Would like to make #![no_std]
optional so types can impl Display trait.