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: 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)
3
4
5
6
7
8
9
10
11
12
13
fn main() {
    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
    let mut pid = VelPid::new(config);

    let target = 1.0;
    let dt = 1.0;

    println!("{:5.2}", pid.update(target, 0.0, dt));
    println!("{:5.2}", pid.update(target, 0.1, dt));
    println!("{:5.2}", pid.update(target, 0.3, dt));
}
More examples
Hide additional examples
examples/pid_with_limits.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
fn main() {
    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
    let mut pid = Pid::new(config);

    println!("{:5.2}", pid.update(1.0, 0.0, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.1, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.3, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.6, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.9, 1.0));
    println!("{:5.2}", pid.update(1.0, 1.2, 1.0));
}
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;
        }
    }
}
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)
3
4
5
6
7
8
9
10
11
12
13
fn main() {
    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
    let mut pid = VelPid::new(config);

    let target = 1.0;
    let dt = 1.0;

    println!("{:5.2}", pid.update(target, 0.0, dt));
    println!("{:5.2}", pid.update(target, 0.1, dt));
    println!("{:5.2}", pid.update(target, 0.3, dt));
}
More examples
Hide additional examples
examples/pid_with_limits.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
fn main() {
    let config = PidConfig::new(1.0, 0.1, 0.1).with_limits(-1.0, 1.0);
    let mut pid = Pid::new(config);

    println!("{:5.2}", pid.update(1.0, 0.0, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.1, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.3, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.6, 1.0));
    println!("{:5.2}", pid.update(1.0, 0.9, 1.0));
    println!("{:5.2}", pid.update(1.0, 1.2, 1.0));
}
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§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy 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> 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,

§

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>,

§

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>,

§

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.