Expand description
An advanced PID control library implemented in Rust.
This library provides an interface for PID controllers and several implementations.
It supports various types of PID controls and allows for customization of PID gains and limits.
It is designed to be no_std compatible, but can also be used with std.
§Features
- Standard (Positional) PID Control (
pidmodule) - Velocity form PID Control (
vel_pidmodule) - PI-D Control where the Derivative action is based on the Process Variable (PV) (
pi_dmodule) - I-PD Control where both Proportional and Derivative actions are based on the Process Variable (PV) (
i_pdmodule) - Customizable PID gains and limits (
configmodule)
§Usage
To use, implement the PidController trait for your controller.
The trait provides a new method for creating a new controller, an update method for updating the controller,
and a reset_config method for resetting the controller’s configuration.
§Installation
To install, run the following Cargo command in your project directory:
cargo add advanced-pidOr add the following to your Cargo.toml:
[dependencies]
advanced-pid = "0.2.3"§No-std support
This library is designed to be no_std compatible.
To use this library in a no_std environment, disable the default features in your Cargo.toml:
[dependencies]
advanced-pid = { version = "0.2.3", default-features = false }§Floating point precision
This library allows switching between f32 and f64 floating point types through feature flags.
By default, f32 precision is used.
To use f64 precision, enable the f64 feature in your Cargo.toml:
[dependencies]
advanced-pid = { version = "0.2.3", features = ["f64"] }§Examples
use advanced_pid::{prelude::*, Pid, PidGain};
let target = 1.0;
let actual = 0.0;
let dt = 1.0;
let gain = PidGain {
kp: 1.0,
ki: 0.3,
kd: 0.1,
};
let mut pid = Pid::new(gain.into());
println!("{}", pid.update(target, actual, dt));For more examples, see the examples.
Re-exports§
pub use crate::i_pd::Ipd;pub use crate::pi_d::PiD;pub use crate::pid::Pid;pub use crate::vel_pid::VelPid;
Modules§
- config
- The
configmodule provides structures for configuring a PID controller. - i_pd
- The
i_pdmodule provides a PID controller where the proportional action is based on the process variable (PV). - pi_d
- The
pi_dmodule provides a PID controller where the derivative action is based on the process variable (PV). - pid
- The
pidmodule provides a standard (position form) PID controller. - prelude
- The
preludemodule provides a prelude for theadvanced_pidcrate. - vel_pid
- The
vel_pidmodule provides a velocity form PID controller.
Traits§
- PidController
PidControlleris a trait that provides a standard interface for PID controllers.
Type Aliases§
- PidConfig
- Type alias for PID configuration.
- PidGain
- Type alias for PID gains.