Struct advanced_pid::config::Config
source · pub struct Config {
pub gain: Gain,
pub min: f32,
pub max: f32,
}Expand description
Config holds a Gain and also provides optional limits for the controller output.
Fields§
§gain: Gain§min: f32§max: f32Implementations§
source§impl Config
impl Config
sourcepub fn new(kp: f32, ki: f32, kd: f32) -> Self
pub fn new(kp: f32, ki: f32, kd: f32) -> Self
Creates a new Config with the specified gains.
Examples found in repository?
More examples
examples/simulation_with_instant.rs (line 7)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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 > std::time::Duration::from_secs(1) {
let output = pid.update(target, actual, dt.as_secs_f32());
actual += (output - actual) / 8.0;
println!("{:5.2}\t{:5.2}\t{:?}", actual, output, dt);
pre = now;
}
}
}sourcepub fn with_limits(self, min: f32, max: f32) -> Self
pub fn with_limits(self, min: f32, max: f32) -> Self
Returns a new Config with the specified limits.
Examples found in repository?
More examples
examples/simulation_with_instant.rs (line 7)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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 > std::time::Duration::from_secs(1) {
let output = pid.update(target, actual, dt.as_secs_f32());
actual += (output - actual) / 8.0;
println!("{:5.2}\t{:5.2}\t{:?}", actual, output, dt);
pre = now;
}
}
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more