Skip to main content

KalmanFilter

Struct KalmanFilter 

Source
pub struct KalmanFilter<const N: usize, const M: usize> {
    pub x: [f32; N],
    pub p: [[f32; N]; N],
    pub q: [[f32; N]; N],
    pub r: [[f32; M]; M],
}
Expand description

Const-generic linear Kalman filter: x' = F x (+ B u) + w, z = H x + v.

Measurement dimension M must be ≤ 16 so the innovation covariance can be inverted with the crate’s stack-limited matrix inverse.

Fields§

§x: [f32; N]

State estimate

§p: [[f32; N]; N]

State covariance P (N×N)

§q: [[f32; N]; N]

Process noise covariance Q (N×N)

§r: [[f32; M]; M]

Measurement noise covariance R (M×M)

Implementations§

Source§

impl<const N: usize, const M: usize> KalmanFilter<N, M>

Source

pub fn new( x0: [f32; N], p0: [[f32; N]; N], q: [[f32; N]; N], r: [[f32; M]; M], ) -> Self

Create a filter with initial state x0, covariance p0, and noise covariances q / r.

Source

pub fn from_variances(x0: [f32; N], p_var: f32, q_var: f32, r_var: f32) -> Self

Create a filter with diagonal P, Q, and R initialized from scalar variances.

Source

pub fn predict(&mut self, f: &[[f32; N]; N])

Prediction without control input: x ← F x, P ← F P Fᵀ + Q.

Source

pub fn predict_with_control<const U: usize>( &mut self, f: &[[f32; N]; N], b: &[[f32; U]; N], u: &[f32; U], )

Prediction with control: x ← F x + B u, P ← F P Fᵀ + Q.

Source

pub fn update(&mut self, h: &[[f32; N]; M], z: &[f32; M]) -> Status

Measurement update with observation matrix H (M×N) and measurement z.

On success returns Status::Success and updates x / P. If S is singular or M > 16, returns an error status and leaves the filter state unchanged.

Trait Implementations§

Source§

impl<const N: usize, const M: usize> Clone for KalmanFilter<N, M>

Source§

fn clone(&self) -> KalmanFilter<N, M>

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<const N: usize, const M: usize> Copy for KalmanFilter<N, M>

Source§

impl<const N: usize, const M: usize> Debug for KalmanFilter<N, M>

Source§

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

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

impl<const N: usize, const M: usize> PartialEq for KalmanFilter<N, M>

Source§

fn eq(&self, other: &KalmanFilter<N, M>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<const N: usize, const M: usize> StructuralPartialEq for KalmanFilter<N, M>

Auto Trait Implementations§

§

impl<const N: usize, const M: usize> Freeze for KalmanFilter<N, M>

§

impl<const N: usize, const M: usize> RefUnwindSafe for KalmanFilter<N, M>

§

impl<const N: usize, const M: usize> Send for KalmanFilter<N, M>

§

impl<const N: usize, const M: usize> Sync for KalmanFilter<N, M>

§

impl<const N: usize, const M: usize> Unpin for KalmanFilter<N, M>

§

impl<const N: usize, const M: usize> UnsafeUnpin for KalmanFilter<N, M>

§

impl<const N: usize, const M: usize> UnwindSafe for KalmanFilter<N, M>

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.