Config

Struct 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: f32

Implementations§

Source§

impl Config

Source

pub fn new(kp: f32, ki: f32, kd: f32) -> Self

Creates a new Config with the specified gains.

Examples found in repository?
examples/vel_pid.rs (line 4)
3fn main() {
4    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
5    let mut pid = VelPid::new(config);
6
7    let target = 1.0;
8    let dt = 1.0;
9
10    println!("{:5.2}", pid.update(target, 0.0, dt));
11    println!("{:5.2}", pid.update(target, 0.1, dt));
12    println!("{:5.2}", pid.update(target, 0.3, dt));
13}
More examples
Hide additional examples
examples/pid_with_limits.rs (line 4)
3fn main() {
4    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
5    let mut pid = Pid::new(config);
6
7    println!("{:5.2}", pid.update(1.0, 0.0, 1.0));
8    println!("{:5.2}", pid.update(1.0, 0.1, 1.0));
9    println!("{:5.2}", pid.update(1.0, 0.3, 1.0));
10    println!("{:5.2}", pid.update(1.0, 0.6, 1.0));
11    println!("{:5.2}", pid.update(1.0, 0.9, 1.0));
12    println!("{:5.2}", pid.update(1.0, 1.2, 1.0));
13}
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}
Source

pub fn with_limits(self, min: f32, max: f32) -> Self

Returns a new Config with the specified limits.

Examples found in repository?
examples/vel_pid.rs (line 4)
3fn main() {
4    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
5    let mut pid = VelPid::new(config);
6
7    let target = 1.0;
8    let dt = 1.0;
9
10    println!("{:5.2}", pid.update(target, 0.0, dt));
11    println!("{:5.2}", pid.update(target, 0.1, dt));
12    println!("{:5.2}", pid.update(target, 0.3, dt));
13}
More examples
Hide additional examples
examples/pid_with_limits.rs (line 4)
3fn main() {
4    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
5    let mut pid = Pid::new(config);
6
7    println!("{:5.2}", pid.update(1.0, 0.0, 1.0));
8    println!("{:5.2}", pid.update(1.0, 0.1, 1.0));
9    println!("{:5.2}", pid.update(1.0, 0.3, 1.0));
10    println!("{:5.2}", pid.update(1.0, 0.6, 1.0));
11    println!("{:5.2}", pid.update(1.0, 0.9, 1.0));
12    println!("{:5.2}", pid.update(1.0, 1.2, 1.0));
13}
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§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Gain> for Config

Source§

fn from(gain: Gain) -> Self

Converts a Gain into a Config.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.