pub struct PidBuilder<T> { /* private fields */ }Expand description
PID controller builder
Builds Biquad from action gains, gain limits, input offset and output limits.
let b: Biquad<f32> = PidBuilder::default()
.period(1e-3)
.gain(Action::I, 1e-3)
.gain(Action::P, 1.0)
.gain(Action::D, 1e2)
.limit(Action::I, 1e3)
.limit(Action::D, 1e1)
.build()
.into();Implementations§
Source§impl<T: Float> PidBuilder<T>
impl<T: Float> PidBuilder<T>
Sourcepub fn gain(&mut self, action: Action, gain: T) -> &mut Self
pub fn gain(&mut self, action: Action, gain: T) -> &mut Self
Gain for a given action
Gain units are output/input * time.powi(order) where
outputare output (y) unitsinputare input (x) unitstimeare sample period units, e.g. SI secondsorderis the action order: the frequency exponent (-1for integrating,0for proportional, etc.)
Gains are accurate in the low frequency limit. Towards Nyquist, the frequency response is warped.
Note that limit signs and gain signs should match.
let tau = 1e-3;
let ki = 1e-4;
let i: Biquad<f32> = PidBuilder::default()
.period(tau)
.gain(Action::I, ki)
.build()
.into();
let x0 = 5.0;
let y0 = i.update(&mut [0.0; 4], x0);
assert!((y0 / (x0 * tau * ki) - 1.0).abs() < 2.0 * f32::EPSILON);§Arguments
action: Action to controlgain: Gain value
Sourcepub fn limit(&mut self, action: Action, limit: T) -> &mut Self
pub fn limit(&mut self, action: Action, limit: T) -> &mut Self
Gain limit for a given action
Gain limit units are output/input. See also PidBuilder::gain().
Multiple gains and limits may interact and lead to peaking.
Note that limit signs and gain signs should match and that the default limits are positive infinity.
let ki_limit = 1e3;
let i: Biquad<f32> = PidBuilder::default()
.gain(Action::I, 8.0)
.limit(Action::I, ki_limit)
.build()
.into();
let mut xy = [0.0; 4];
let x0 = 5.0;
for _ in 0..1000 {
i.update(&mut xy, x0);
}
let y0 = i.update(&mut xy, x0);
assert!((y0 / (x0 * ki_limit) - 1.0f32).abs() < 1e-3);§Arguments
action: Action to limit in gainlimit: Gain limit
Sourcepub fn build<C>(&self) -> [C; 5]
pub fn build<C>(&self) -> [C; 5]
Compute coefficients and return Biquad.
No attempt is made to detect NaNs, non-finite gains, non-positive period, zero gain limits, or gain/limit sign mismatches. These will consequently result in NaNs/infinities, peaking, or notches in the Biquad coefficients.
Gain limits for unused gain actions or for proportional action are ignored.
let i: Biquad<f32> = PidBuilder::default()
.gain(Action::P, 3.0)
.order(Order::P)
.build()
.into();
assert_eq!(i, Biquad::proportional(3.0));§Panic
Will panic in debug mode on fixed point coefficient overflow.
Trait Implementations§
Source§impl<T: Clone> Clone for PidBuilder<T>
impl<T: Clone> Clone for PidBuilder<T>
Source§fn clone(&self) -> PidBuilder<T>
fn clone(&self) -> PidBuilder<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more