Trait advanced_pid::PidController
source · pub trait PidController {
// Required methods
fn new(config: PidConfig) -> Self;
fn update(&mut self, set_point: f32, actual: f32, dt: f32) -> f32;
// Provided method
fn reset_config(&mut self, config: PidConfig)
where Self: Sized { ... }
}Expand description
PidController is a trait that provides a standard interface for PID controllers.
It provides methods for creating a new controller Self::new(), updating the controller Self::update(), and resetting the controller’s configuration Self::reset_config().
Required Methods§
Provided Methods§
sourcefn reset_config(&mut self, config: PidConfig)where
Self: Sized,
fn reset_config(&mut self, config: PidConfig)where
Self: Sized,
Resets the controller’s configuration to the specified configuration.
use advanced_pid::{prelude::*, Pid, PidConfig};
let mut controller = Pid::default();
let config = PidConfig::new(1.0, 0.3, 0.1);
controller.reset_config(config);Examples found in repository?
examples/simulation_with_instant.rs (line 8)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
let mut pid = VelPid::default();
let config = PidConfig::new(0.8, 0.3, 0.2).with_limits(-1.2, 1.2);
pid.reset_config(config);
let target = 1.0;
let mut actual = 0.0;
let mut pre = Instant::now();
loop {
let now = Instant::now();
let dt = now - pre;
if dt > Duration::from_secs(1) {
let sec = as_secs(dt);
let output = pid.update(target, actual, sec);
actual += (output - actual) / 8.0;
println!("{:5.2}\t{:5.2}\t{:?}", actual, output, dt);
pre = now;
}
}
}Object Safety§
This trait is not object safe.