6 releases
0.2.2 | May 17, 2024 |
---|---|
0.2.1 | May 3, 2024 |
0.1.2 | May 2, 2024 |
#558 in Algorithms
28KB
489 lines
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
andf64
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.