Crate advanced_pid
source ·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 (
pid
module) - Velocity form PID Control (
vel_pid
module) - PI-D Control where the Derivative action is based on the Process Variable (PV) (
pi_d
module) - I-PD Control where both Proportional and Derivative actions are based on the Process Variable (PV) (
i_pd
module) - Customizable PID gains and limits (
config
module)
§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-pid
Or add the following to your Cargo.toml:
[dependencies]
advanced-pid = "0.2.2"
§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.2", 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.2", 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§
- The
config
module provides structures for configuring a PID controller. - The
i_pd
module provides a PID controller where the proportional action is based on the process variable (PV). - The
pi_d
module provides a PID controller where the derivative action is based on the process variable (PV). - The
pid
module provides a standard (position form) PID controller. - The
prelude
module provides a prelude for theadvanced_pid
crate. - The
vel_pid
module provides a velocity form PID controller.
Traits§
PidController
is a trait that provides a standard interface for PID controllers.
Type Aliases§
- Type alias for PID configuration.
- Type alias for PID gains.