pub struct Builder<T> { /* private fields */ }Expand description
PID controller builder
Builds Biquad from action gains, gain limits, input offset and output limits.
let b: Biquad<f32> = pid::Builder::default()
.gain(pid::Action::I, 1e-3)
.gain(pid::Action::P, 1.0)
.gain(pid::Action::D, 1e2)
.limit(pid::Action::I, 1e3)
.limit(pid::Action::D, 1e1)
.build(&1e-3);Implementations§
Source§impl<T: Float> Builder<T>
impl<T: Float> Builder<T>
Sourcepub fn gain(self, action: Action, gain: T) -> Self
pub fn gain(self, action: Action, gain: T) -> 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> = pid::Builder::default().gain(pid::Action::I, ki).build(&tau);
let x0 = 5.0;
let y0 = i.process(&mut DirectForm1::default(), x0);
assert!((y0 / (x0 * tau * ki) - 1.0).abs() < 2.0 * f32::EPSILON);§Arguments
action: Action to controlgain: Gain value
Sourcepub fn limit(self, action: Action, limit: T) -> Self
pub fn limit(self, action: Action, limit: T) -> Self
Gain limit for a given action
Gain limit units are output/input. See also Builder::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> = pid::Builder::default()
.gain(pid::Action::I, 8.0)
.limit(pid::Action::I, ki_limit)
.build(&1.0);
let mut xy = DirectForm1::default();
let x0 = 5.0;
for _ in 0..1000 {
i.process(&mut xy, x0);
}
let y0 = i.process(&mut xy, x0);
assert!((y0 / (x0 * ki_limit) - 1.0f32).abs() < 1e-3);§Arguments
action: Action to limit in gainlimit: Gain limit
Trait Implementations§
Source§impl<T, C> Build<[C; 5]> for Builder<T>
impl<T, C> Build<[C; 5]> for Builder<T>
Source§fn build(&self, period: &T) -> [C; 5]
fn build(&self, period: &T) -> [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> = pid::Builder::default()
.gain(pid::Action::P, 3.0)
.order(pid::Order::P)
.build(&1.0);
assert_eq!(i, Biquad::proportional(3.0f32));§Arguments
t_unit: Sample period in some units, e.g. SI seconds
§Panic
Will panic in debug mode on fixed point coefficient overflow.