[][src]Crate pid_lite

A small PID controller library.

This crate implements the classic independent PID formulation.

Introduction

PID controllers are an integral part of control systems, and provide a way to perform error correction. It's used to control things like throughput or resource allocation: as the resource approaches capacity, the returned correction decreases. And because it is aware of a time factor, it can deal with rapid changes as well.

Loop Tuning

However PID controllers are not a silver bullet: they are a tool in a wider toolbox. To maximally benefit from them they need to be tuned to the workload. This is done through three parameters: proportional_gain, integral_gain and derivative_gain. Automated algorithms exist to tune these parameters based on sample workloads, but those are out of scope for this crate.

Read more on loop tuning.

No-std support

#[no_std] support can be enabled by disabling the default crate-level features. This disables the Controller::update method which automatically calculates the time elapsed. Instead use the Controller::update_elapsed method which takes an externally calculated Duration.

Examples

use pid_lite::Controller;
use std::thread;
use std::time::Duration;

let target = 80.0;
let mut controller = Controller::new(target, 0.25, 0.01, 0.01);

loop {
    let correction = controller.update(measure());
    apply_correction(correction);
    thread::sleep(Duration::from_secs(1));
}

Structs

Controller

PID controller