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)
5fn main() {
6 let mut pid = VelPid::default();
7 let config = PidConfig::new(0.8, 0.3, 0.2).with_limits(-1.2, 1.2);
8 pid.reset_config(config);
9
10 let target = 1.0;
11 let mut actual = 0.0;
12
13 let mut pre = Instant::now();
14 loop {
15 let now = Instant::now();
16 let duration = pre.elapsed();
17 if duration > Duration::from_secs(1) {
18 let sec = as_secs(duration);
19 let output = pid.update(target, actual, sec);
20 actual += (output - actual) / 8.0;
21 println!("{:5.2}\t{:5.2}\t{:?}", actual, output, duration);
22 pre = now;
23 }
24 }
25}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)
5fn main() {
6 let mut pid = VelPid::default();
7 let config = PidConfig::new(0.8, 0.3, 0.2).with_limits(-1.2, 1.2);
8 pid.reset_config(config);
9
10 let target = 1.0;
11 let mut actual = 0.0;
12
13 let mut pre = Instant::now();
14 loop {
15 let now = Instant::now();
16 let duration = pre.elapsed();
17 if duration > Duration::from_secs(1) {
18 let sec = as_secs(duration);
19 let output = pid.update(target, actual, sec);
20 actual += (output - actual) / 8.0;
21 println!("{:5.2}\t{:5.2}\t{:?}", actual, output, duration);
22 pre = now;
23 }
24 }
25}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