Crates.io | cu-pid |
lib.rs | cu-pid |
version | |
source | src |
created_at | 2024-10-12 19:54:31.262052 |
updated_at | 2024-12-05 22:18:58.554023 |
description | A PID controller for the Copper project. |
homepage | https://github.com/copper-project |
repository | https://github.com/copper-project/copper-rs |
max_upload_size | |
id | 1406824 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Check out cu_rp_balancebot for a full example of how to use it.
To be able to use it, you need to specialize it before you can reference it in your copper RON config:
// in mymod.rs
use cu_pid::GenericPIDTask;
pub type MyPID = GenericPIDTask<MyPayload>;
// MyPayload needs to implement an Into<f32> trait to be able to be used as a reference for the PID controller
pub struct MyPayload {
pub value: f32,
}
impl Into<f32> for MyPayload {
fn into(self) -> f32 {
self.value
}
}
Then you can use it in your copper RON config:
(
id: "my_pid",
type: "mymod::MyPID", // Set your type alias here
config: {
"kp": 0.015,
"kd": 0.01,
"ki": 0.00005,
"setpoint": 3176.0,
"cutoff": 170.0,
},
),
[...]
kp
: Proportional gainki
: Integral gainkd
: Derivative gainsetpoint
: The target valuecutoff
: The +/- deviation from the setpoint that is considered acceptable, otherwise the PID will return None (
safety mode)The PID controller will return a full state with the p, i and d contributions in PIDControlOutput struct:
pub struct PIDControlOutput {
pub p: f32,
pub i: f32,
pub d: f32,
pub output: f32, // output == p+i+d
}