#pid #control #implemented #advanced #standard #pid-gain

no-std advanced-pid

An advanced PID control library implemented in Rust

6 releases

0.2.2 May 17, 2024
0.2.1 May 3, 2024
0.1.2 May 2, 2024

#7 in #advanced

MIT license

28KB
489 lines

advanced-pid-rs

An advanced PID control library implemented in Rust

Crates.io Version Documentation at docs.rs License: MIT CI

Crates.io | API Docs | Examples

Highlights

  • Supports various types of PID controls
    • Position (standard) PID Control
    • Velocity form PID Control
    • Derivative action based on PV (PI-D)
    • Proportional action based on PV (I-PD)
  • Customizable PID gains and limits
  • no_std support
  • User-friendly with the PidController trait
  • Includes a simulation example
  • Allows switching between f32 and f64 floating point types through feature flags

Installation

To install, run the following Cargo command in your project directory:

cargo add advanced-pid

Or add the following to your Cargo.toml:

[dependencies]
advanced-pid = "0.2.2"

Quick Start

cargo run --example simulation

Examples

Example of Standard PID Control

use advanced_pid::{prelude::*, Pid, PidGain};

fn main() {
    let gain = PidGain {
        kp: 1.0,
        ki: 0.3,
        kd: 0.1,
    };
    let mut pid = Pid::new(gain.into());

    println!("{:5.2}", pid.update(1.0, 0.0, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.5, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.8, 1.0));
}

Example of Velocity Form PID Control

use advanced_pid::{prelude::*, PidConfig, VelPid};

fn main() {
    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
    let mut pid = VelPid::new(config);

    let target = 1.0;
    let dt = 1.0;

    println!("{:5.2}", pid.update(target, 0.0, dt));
    println!("{:5.2}", pid.update(target, 0.1, dt));
    println!("{:5.2}", pid.update(target, 0.3, dt));
}

More information

For additional information, please visit:

License

Copyright (c) 2024 Yoshikawa Teru

This project is released under the MIT License, see LICENSE.

No runtime deps

Features