Skip to main content

RateModel

Struct RateModel 

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

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: usize

Ticks from a moment command to its first effect on the rate, at least 1.

§dt_s: f32

The tick the model steps at, in s: the mean dt it was fitted over.

Implementations§

Source§

impl RateModel

Source

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);
Source

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);
Source

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§

Source§

impl Clone for RateModel

Source§

fn clone(&self) -> Self

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 RateModel

Source§

impl Debug for RateModel

Source§

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

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

impl PartialEq for RateModel

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RateModel

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.