advanced-pid

Crates.ioadvanced-pid
lib.rsadvanced-pid
version0.2.2
sourcesrc
created_at2024-05-01 02:59:12.142099
updated_at2024-05-17 06:31:17.981893
descriptionAn advanced PID control library implemented in Rust
homepage
repositoryhttps://github.com/teruyamato0731/advanced-pid-rs
max_upload_size
id1225797
size36,463
Yoshikawa Teru (teruyamato0731)

documentation

https://docs.rs/advanced-pid/

README

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.

Commit count: 39

cargo fmt