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 * uExamples include temperature, pressure, flow, and motor speed loops.
Fields§
§sample_period: FloatNominal 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: FloatEstimated 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: FloatController feedback gain.
observer_beta1: FloatFirst observer gain for output estimation.
observer_beta2: FloatSecond observer gain for total-disturbance estimation.
output_limit: Option<OutputLimit>Optional output clamp.
Implementations§
Source§impl LadrcFirstOrderConfig
impl LadrcFirstOrderConfig
Sourcepub fn from_bandwidth(
sample_period: Float,
b0: Float,
controller_bandwidth: Float,
observer_bandwidth: Float,
) -> Self
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?
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}Sourcepub const fn with_output_limit(self, limit: OutputLimit) -> Self
pub const fn with_output_limit(self, limit: OutputLimit) -> Self
Returns the same configuration with an output clamp.
Examples found in repository?
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}Sourcepub fn validate(self) -> Result<(), ConfigError>
pub fn validate(self) -> Result<(), ConfigError>
Validates all parameters.
Trait Implementations§
Source§impl Clone for LadrcFirstOrderConfig
impl Clone for LadrcFirstOrderConfig
Source§fn clone(&self) -> LadrcFirstOrderConfig
fn clone(&self) -> LadrcFirstOrderConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for LadrcFirstOrderConfig
Source§impl Debug for LadrcFirstOrderConfig
impl Debug for LadrcFirstOrderConfig
Source§impl PartialEq for LadrcFirstOrderConfig
impl PartialEq for LadrcFirstOrderConfig
Source§fn eq(&self, other: &LadrcFirstOrderConfig) -> bool
fn eq(&self, other: &LadrcFirstOrderConfig) -> bool
self and other values to be equal, and is used by ==.