pub struct RateModel {
pub rate_weights: [f32; 2],
pub moment_weights: [f32; 3],
pub delay_ticks: usize,
pub dt_s: f32,
}Expand description
A rate axis’s response to its moment command, fitted in flight: the body rate one tick on
from the last two rates and three moments, delay_ticks back.
y[k] = r₁·y[k−1] + r₂·y[k−2] + m₀·u[k−d] + m₁·u[k−d−1] + m₂·u[k−d−2], with y the body
rate in rad/s, u the normalized moment, r the rate_weights, m
the moment_weights, and d the delay. A body that integrates its
moment through one motor lag fits it with r₁ = 1 + p, r₂ = −p, p the lag’s pole: the
form IdentifyProbe fits, its moment on one weight or, half a tick later, two equal ones.
Fields§
§rate_weights: [f32; 2]Weights of the last two body rates, y[k−1] and y[k−2].
moment_weights: [f32; 3]Weights of the moments u[k−d], u[k−d−1], and u[k−d−2].
delay_ticks: usizeTicks from a moment command to its first effect on the rate, at least 1.
dt_s: f32The tick the model steps at, in s: the mean dt it was fitted over.
Implementations§
Source§impl RateModel
impl RateModel
Sourcepub fn lag_s(&self) -> Option<f32>
pub fn lag_s(&self) -> Option<f32>
The motor lag’s time constant, in s, from its pole p = −r₂: −dt / ln p for a pole
in (0, 1). A pole at or below 0 is a lag under a tick, which the delay absorbs, so 0
(#563). None for a pole at or past 1, which grows rather than lags.
§Examples
use stable_flight::tuning::RateModel;
// A 30 ms lag at 250 Hz: p = e^(−0.004/0.03).
let p = (-0.004f32 / 0.03).exp();
let model = RateModel {
rate_weights: [1.0 + p, -p],
moment_weights: [0.1, 0.0, 0.0],
delay_ticks: 1,
dt_s: 0.004,
};
assert!((model.lag_s().unwrap() - 0.03).abs() < 1e-5);Sourcepub fn response(&self, w_radps: f32) -> Complex<f32>
pub fn response(&self, w_radps: f32) -> Complex<f32>
The model’s frequency response at w_radps: body rate per unit moment, delay included,
(m₀ + m₁·z⁻¹ + m₂·z⁻²)·z⁻ᵈ / (1 − r₁·z⁻¹ − r₂·z⁻²) at z⁻¹ = e^(−jω·dt). Its phase
starts near −90° (the body integrates its moment) and falls with the lag and the delay.
§Examples
use stable_flight::tuning::RateModel;
// An integrator alone, one tick of delay: about 1/(jω) per unit gain.
let model = RateModel {
rate_weights: [1.0, 0.0],
moment_weights: [0.004, 0.0, 0.0],
delay_ticks: 1,
dt_s: 0.004,
};
let response = model.response(1.0);
assert!((response.norm_sqr() - 1.0).abs() < 0.02);Sourcepub fn accel_radps2(&self) -> Option<f32>
pub fn accel_radps2(&self) -> Option<f32>
The axis’s angular acceleration per unit moment once the lag has settled, in rad/s²:
the moments’ total weight over (1 − p)·dt, a pole at or below 0 taken as 0, as
lag_s takes it. None without a lag.
Trait Implementations§
impl Copy for RateModel
impl StructuralPartialEq for RateModel
Auto Trait Implementations§
impl Forget for RateModel
impl Freeze for RateModel
impl Move for RateModel
impl RefUnwindSafe for RateModel
impl Send for RateModel
impl Sync for RateModel
impl Unpin for RateModel
impl UnsafeUnpin for RateModel
impl UnwindSafe for RateModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.