Skip to main content

LadrcFirstOrderConfig

Struct LadrcFirstOrderConfig 

Source
pub struct LadrcFirstOrderConfig {
    pub sample_period: Float,
    pub b0: Float,
    pub kp: Float,
    pub observer_beta1: Float,
    pub observer_beta2: Float,
    pub output_limit: Option<OutputLimit>,
}
Expand description

First-order LADRC configuration.

This configuration is for processes where the control command mostly changes the first derivative of the measured output:

y' = f + b0 * u

Examples include temperature, pressure, flow, and motor speed loops.

Fields§

§sample_period: Float

Nominal sampling period in seconds.

Plain update uses this value directly. update_at uses it only for the first call when no previous timestamp is known yet.

§b0: Float

Estimated plant input gain from command to output rate.

The value may be approximate, but the sign must match the real plant. A wrong sign usually makes the closed loop diverge.

§kp: Float

Controller feedback gain.

§observer_beta1: Float

First observer gain for output estimation.

§observer_beta2: Float

Second observer gain for total-disturbance estimation.

§output_limit: Option<OutputLimit>

Optional output clamp.

Implementations§

Source§

impl LadrcFirstOrderConfig

Source

pub fn from_bandwidth( sample_period: Float, b0: Float, controller_bandwidth: Float, observer_bandwidth: Float, ) -> Self

Creates a configuration from controller and observer bandwidths.

The gain placement is kp = wc, beta1 = 2 * wo, beta2 = wo^2.

controller_bandwidth controls the closed-loop response speed. observer_bandwidth controls how fast the observer estimates the total disturbance. A common first value is observer_bandwidth around three to five times controller_bandwidth.

Examples found in repository?
examples/first_order_temperature.rs (lines 7-10)
3fn main() -> Result<(), ladrc_no_std::ConfigError> {
4    let dt = 0.01;
5    let target_temperature = 55.0;
6
7    let config = LadrcFirstOrderConfig::from_bandwidth(
8        dt, 2.0, // one unit of heater command gives roughly +2 C/s initially
9        0.8, 4.0,
10    )
11    .with_output_limit(OutputLimit::new(0.0, 1.0));
12
13    let mut controller = LadrcFirstOrder::new(config)?;
14    let mut temperature = 20.0;
15    let ambient = 20.0;
16    let mut control = 0.0;
17
18    for step in 0..6_000 {
19        let out = controller.update(target_temperature, temperature);
20        control = out.control;
21
22        let open_window_disturbance = if step > 3_000 { -0.35 } else { 0.0 };
23        let plant_cooling = -0.04 * (temperature - ambient);
24        let plant_heating = 2.0 * control;
25
26        temperature += dt * (plant_cooling + plant_heating + open_window_disturbance);
27    }
28
29    println!("target temperature: {target_temperature:.2} C");
30    println!("final temperature:  {temperature:.2} C");
31    println!("final command:      {:.1} %", control * 100.0);
32
33    Ok(())
34}
Source

pub const fn with_output_limit(self, limit: OutputLimit) -> Self

Returns the same configuration with an output clamp.

Examples found in repository?
examples/first_order_temperature.rs (line 11)
3fn main() -> Result<(), ladrc_no_std::ConfigError> {
4    let dt = 0.01;
5    let target_temperature = 55.0;
6
7    let config = LadrcFirstOrderConfig::from_bandwidth(
8        dt, 2.0, // one unit of heater command gives roughly +2 C/s initially
9        0.8, 4.0,
10    )
11    .with_output_limit(OutputLimit::new(0.0, 1.0));
12
13    let mut controller = LadrcFirstOrder::new(config)?;
14    let mut temperature = 20.0;
15    let ambient = 20.0;
16    let mut control = 0.0;
17
18    for step in 0..6_000 {
19        let out = controller.update(target_temperature, temperature);
20        control = out.control;
21
22        let open_window_disturbance = if step > 3_000 { -0.35 } else { 0.0 };
23        let plant_cooling = -0.04 * (temperature - ambient);
24        let plant_heating = 2.0 * control;
25
26        temperature += dt * (plant_cooling + plant_heating + open_window_disturbance);
27    }
28
29    println!("target temperature: {target_temperature:.2} C");
30    println!("final temperature:  {temperature:.2} C");
31    println!("final command:      {:.1} %", control * 100.0);
32
33    Ok(())
34}
Source

pub fn validate(self) -> Result<(), ConfigError>

Validates all parameters.

Trait Implementations§

Source§

impl Clone for LadrcFirstOrderConfig

Source§

fn clone(&self) -> LadrcFirstOrderConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for LadrcFirstOrderConfig

Source§

impl Debug for LadrcFirstOrderConfig

Source§

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

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

impl PartialEq for LadrcFirstOrderConfig

Source§

fn eq(&self, other: &LadrcFirstOrderConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for LadrcFirstOrderConfig

Auto Trait Implementations§

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