Skip to main content

KalmanFilter

Struct KalmanFilter 

Source
pub struct KalmanFilter { /* private fields */ }
Expand description

Discrete linear Kalman filter over fixed-size state, measurement, and control vectors.

Construct with KalmanFilter::new, assign the model matrices with the set_* methods, seed KalmanFilter::set_state_post and KalmanFilter::set_error_cov_post, then alternate predict/correct calls.

Implementations§

Source§

impl KalmanFilter

Source

pub fn new( dynam_params: usize, measure_params: usize, control_params: usize, ) -> Result<Self>

Creates a filter with zero-filled model matrices and covariances, matching cv::KalmanFilter::KalmanFilter.

§Errors

Returns an error unless dynam_params and measure_params are nonzero; control_params may be zero to disable the control input.

Source

pub fn set_transition_matrix(&mut self, matrix: &Matrix) -> Result<()>

Assigns the dynam x dynam state-transition matrix A.

§Errors

Returns an error unless matrix is [dynam, dynam] F32.

Source

pub fn set_control_matrix(&mut self, matrix: &Matrix) -> Result<()>

Assigns the dynam x control control-input matrix B.

§Errors

Returns an error unless matrix is [dynam, control] F32.

Source

pub fn set_measurement_matrix(&mut self, matrix: &Matrix) -> Result<()>

Assigns the measure x dynam measurement matrix H.

§Errors

Returns an error unless matrix is [measure, dynam] F32.

Source

pub fn set_process_noise_cov(&mut self, matrix: &Matrix) -> Result<()>

Assigns the dynam x dynam process-noise covariance Q.

§Errors

Returns an error unless matrix is [dynam, dynam] F32.

Source

pub fn set_measurement_noise_cov(&mut self, matrix: &Matrix) -> Result<()>

Assigns the measure x measure measurement-noise covariance R.

§Errors

Returns an error unless matrix is [measure, measure] F32.

Source

pub fn set_state_post(&mut self, state: &Matrix) -> Result<()>

Seeds the corrected state estimate consumed by the next predict call.

§Errors

Returns an error unless state holds exactly dynam F32 values.

Source

pub fn set_error_cov_post(&mut self, matrix: &Matrix) -> Result<()>

Seeds the corrected dynam x dynam error covariance P.

§Errors

Returns an error unless matrix is [dynam, dynam] F32.

Source

pub fn state_pre(&self) -> Result<Matrix>

Current predicted state [dynam, 1] (state_pre).

§Errors

Returns an error when the F32 output cannot be materialized.

Source

pub fn state_post(&self) -> Result<Matrix>

Current corrected state [dynam, 1] (state_post).

§Errors

Returns an error when the F32 output cannot be materialized.

Source

pub fn predict(&mut self, control: Option<&Matrix>) -> Result<Matrix>

Advances the model one step: state_pre = A * state_post + B * u, error_cov_pre = A * P * A' + Q. control must be [control, 1] when the filter was built with a nonzero control dimension. Like cv::KalmanFilter::predict, only the *_pre fields advance.

Returns state_pre as [dynam, 1].

§Errors

Returns an error for a wrongly sized or missing control input.

Source

pub fn correct(&mut self, measurement: &Matrix) -> Result<Matrix>

Fuses a measure-dimensional measurement: gain K = P_pre * H' * (H * P_pre * H' + R)^-1, then state_post = state_pre + K * (z - H * state_pre) and error_cov_post = (I - K * H) * P_pre.

Returns state_post as [dynam, 1].

§Errors

Returns an error for a wrongly sized measurement or a singular innovation covariance H * P_pre * H' + R.

Auto Trait Implementations§

§

impl Forget for KalmanFilter

§

impl Freeze for KalmanFilter
where *const u8 is !null: Freeze, PhantomData<f64>: Freeze,

§

impl Move for KalmanFilter

§

impl RefUnwindSafe for KalmanFilter

§

impl Send for KalmanFilter
where RawVecInner: Send,

§

impl Sync for KalmanFilter
where RawVecInner: Sync,

§

impl Unpin for KalmanFilter
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for KalmanFilter

§

impl UnwindSafe for KalmanFilter
where RawVecInner: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.