### Example Usage of size_buffer_Q_control Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_Q_control.html Demonstrates how to use the size_buffer_Q_control macro to get the buffer size for a system with one control input. ```rust const NUM_CONTROLS: usize = 1; assert_eq!(size_buffer_Q_control!(NUM_CONTROLS), 1); ``` -------------------------------- ### No_std Kalman Filter Setup with Macros Source: https://docs.rs/minikalman/latest/src/minikalman/lib.rs.html Example of setting up a Kalman filter for a no_std environment using helper macros to define static buffers for system and observation components. ```rust # #![allow(non_snake_case)] # #![allow(non_upper_case_globals)] use minikalman::buffers::types::* use minikalman::prelude::* use minikalman::regular::{RegularKalmanBuilder, RegularObservationBuilder}; const NUM_STATES: usize = 3; const NUM_OBSERVATIONS: usize = 1; // System buffers. impl_buffer_x!(static mut gravity_x, NUM_STATES, f32, 0.0); impl_buffer_A!(static mut gravity_A, NUM_STATES, f32, 0.0); impl_buffer_P!(static mut gravity_P, NUM_STATES, f32, 0.0); impl_buffer_Q_direct!(static mut gravity_Q, NUM_STATES, f32, 0.0); // Observation buffers. impl_buffer_z!(static mut gravity_z, NUM_OBSERVATIONS, f32, 0.0); impl_buffer_H!(static mut gravity_H, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); impl_buffer_R!(static mut gravity_R, NUM_OBSERVATIONS, f32, 0.0); impl_buffer_y!(static mut gravity_y, NUM_OBSERVATIONS, f32, 0.0); impl_buffer_S!(static mut gravity_S, NUM_OBSERVATIONS, f32, 0.0); impl_buffer_K!(static mut gravity_K, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); // Filter temporaries. impl_buffer_temp_x!(static mut gravity_temp_x, NUM_STATES, f32, 0.0); impl_buffer_temp_P!(static mut gravity_temp_P, NUM_STATES, f32, 0.0); // Observation temporaries. impl_buffer_temp_S_inv!(static mut gravity_temp_S_inv, NUM_OBSERVATIONS, f32, 0.0); // Observation temporaries. impl_buffer_temp_HP!(static mut gravity_temp_HP, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); impl_buffer_temp_PHt!(static mut gravity_temp_PHt, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); impl_buffer_temp_KHP!(static mut gravity_temp_KHP, NUM_STATES, f32, 0.0); let mut filter = RegularKalmanBuilder::new::( StateTransitionMatrixMutBuffer::from(unsafe { gravity_A.as_mut_slice() }), StateVectorBuffer::from(unsafe { gravity_x.as_mut_slice() }), EstimateCovarianceMatrixBuffer::from(unsafe { gravity_P.as_mut_slice() }), DirectProcessNoiseCovarianceMatrixBuffer::from(unsafe { gravity_Q.as_mut_slice() }), PredictedStateEstimateVectorBuffer::from(unsafe { gravity_temp_x.as_mut_slice() }), TemporaryStateMatrixBuffer::from(unsafe { gravity_temp_P.as_mut_slice() }), ); let mut measurement = RegularObservationBuilder::new::( ObservationMatrixMutBuffer::from(unsafe { gravity_H.as_mut_slice() }), MeasurementVectorBuffer::from(unsafe { gravity_z.as_mut_slice() }), MeasurementNoiseCovarianceMatrixBuffer::from(unsafe { gravity_R.as_mut_slice() }), InnovationVectorBuffer::from(unsafe { gravity_y.as_mut_slice() }), InnovationCovarianceMatrixBuffer::from(unsafe { gravity_S.as_mut_slice() }), KalmanGainMatrixBuffer::from(unsafe { gravity_K.as_mut_slice() }), TemporaryResidualCovarianceInvertedMatrixBuffer::from(unsafe { gravity_temp_S_inv.as_mut_slice() }), TemporaryHPMatrixBuffer::from(unsafe { gravity_temp_HP.as_mut_slice() }), TemporaryPHTMatrixBuffer::from(unsafe { gravity_temp_PHt.as_mut_slice() }), TemporaryKHPMatrixBuffer::from(unsafe { gravity_temp_KHP.as_mut_slice() }), ); ``` -------------------------------- ### KalmanFilterBuilder Default Example Source: https://docs.rs/minikalman/latest/minikalman/regular/builder/struct.KalmanFilterObservationBuilder.html Demonstrates how to create a Kalman filter measurement using the builder. This example requires the 'alloc' feature. ```rust use minikalman::regular::builder::KalmanFilterBuilder; const NUM_STATES: usize = 3; const NUM_OBSERVATIONS: usize = 5; let builder = KalmanFilterBuilder::::default(); // let mut filter = builder.build(); let mut measurement = builder.observations().build::(); ``` -------------------------------- ### Build and Operate Extended Kalman Filter Source: https://docs.rs/minikalman/latest/index.html Example demonstrating the setup and operation of an Extended Kalman Filter using its specific builder. This is used for systems with nonlinear dynamics or observations. Ensure 'std' or 'alloc' features are enabled. ```rust use minikalman::extended::builder::KalmanFilterBuilder; use minikalman::prelude::MatrixMut; const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 2; const NUM_OBSERVATIONS: usize = 1; let builder = KalmanFilterBuilder::::default(); let mut filter = builder.build(); let mut measurement = builder.observations().build::(); // Set up the system dynamics, control matrices, observation matrices, ... // Filter! loop { // Obtain the control values. let control_value = 1.0; // Update prediction using nonlinear transfer function. filter.predict_nonlinear(|current, next| { next[0] = current[0] * current[0]; next[1] = current[1].sin() * control_value; }); // Update your measurement vectors. measurement.measurement_vector_mut().apply(|z| { z[0] = 42.0; }); // Apply any measurements using a nonlinear measurement function. filter.correct_nonlinear(&mut measurement, |state, observation| { observation[0] = state[0].cos() + state[1].sin(); }); // Access the state let state = filter.state_vector(); let covariance = filter.estimate_covariance(); } ``` -------------------------------- ### Regular Kalman Filter Initialization and Usage Example Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/regular.rs.html Demonstrates the initialization of a RegularKalmanBuilder and its usage within a loop for prediction and correction steps. This example simulates a scenario with real distance measurements and observation errors. ```rust # #![allow(non_snake_case)] # use minikalman::prelude::*; use minikalman::regular::{RegularKalmanBuilder, RegularObservationBuilder}; # const NUM_STATES: usize = 3; # const NUM_CONTROLS: usize = 0; # const NUM_OBSERVATIONS: usize = 1; # // System buffers. # impl_buffer_x!(mut gravity_x, NUM_STATES, f32, 0.0); # impl_buffer_A!(mut gravity_A, NUM_STATES, f32, 0.0); # impl_buffer_P!(mut gravity_P, NUM_STATES, f32, 0.0); # impl_buffer_Q_direct!(mut gravity_Q, NUM_STATES, f32, 0.0); # # // Filter temporaries. # impl_buffer_temp_x!(mut gravity_temp_x, NUM_STATES, f32, 0.0); # impl_buffer_temp_P!(mut gravity_temp_P, NUM_STATES, f32, 0.0); # # let mut filter = RegularKalmanBuilder::new::( # gravity_A, # gravity_x, # gravity_P, # gravity_Q, # gravity_temp_x, # gravity_temp_P, # ); # # // Observation buffers. # impl_buffer_z!(mut gravity_z, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_H!(mut gravity_H, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); # impl_buffer_R!(mut gravity_R, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_y!(mut gravity_y, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_S!(mut gravity_S, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_K!(mut gravity_K, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); # # // Observation temporaries. # impl_buffer_temp_S_inv!(mut gravity_temp_S_inv, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_temp_HP!(mut gravity_temp_HP, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); # impl_buffer_temp_PHt!(mut gravity_temp_PHt, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_temp_KHP!(mut gravity_temp_KHP, NUM_STATES, f32, 0.0); # # let mut measurement = RegularObservationBuilder::new::( # gravity_H, # gravity_z, # gravity_R, # gravity_y, # gravity_S, # gravity_K, # gravity_temp_S_inv, # gravity_temp_HP, # gravity_temp_PHt, # gravity_temp_KHP, # ); # # const REAL_DISTANCE: &[f32] = &[0.0, 0.0, 0.0]; # const OBSERVATION_ERROR: &[f32] = &[0.0, 0.0, 0.0]; # # for t in 0..REAL_DISTANCE.len() { # // Prediction. # filter.predict(); # # // Measure ... # let m = REAL_DISTANCE[t] + OBSERVATION_ERROR[t]; # measurement.measurement_vector_mut().apply(|z| z[0] = m); # # // Update. # filter.correct(&mut measurement); # } ``` -------------------------------- ### Setup and Operation of an Extended Kalman Filter Source: https://docs.rs/minikalman/latest/src/minikalman/lib.rs.html Use `KalmanFilterBuilder` for setting up and operating an extended Kalman filter with nonlinear dynamics and measurement functions. This example shows initialization and the main loop for nonlinear prediction and correction. ```rust use minikalman::extended::builder::KalmanFilterBuilder; use minikalman::prelude::MatrixMut; const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 2; const NUM_OBSERVATIONS: usize = 1; let builder = KalmanFilterBuilder::::default(); let mut filter = builder.build(); let mut measurement = builder.observations().build::(); // Set up the system dynamics, control matrices, observation matrices, ... // Filter! loop { // Obtain the control values. let control_value = 1.0; // Update prediction using nonlinear transfer function. filter.predict_nonlinear(|current, next| { next[0] = current[0] * current[0]; next[1] = current[1].sin() * control_value; }); // Update your measurement vectors. measurement.measurement_vector_mut().apply(|z| { z[0] = 42.0; }); // Apply any measurements using a nonlinear measurement function. filter.correct_nonlinear(&mut measurement, |state, observation| { observation[0] = state[0].cos() + state[1].sin(); }); } ``` -------------------------------- ### Example: Generating a static mut Q buffer Source: https://docs.rs/minikalman/latest/minikalman/macro.impl_buffer_Q_direct.html Demonstrates how to use impl_buffer_Q_direct to create a static mutable buffer for the Q matrix, suitable for direct process noise covariance. The example verifies the buffer's length and initial value. ```rust const NUM_CONTROLS: usize = 2; impl_buffer_Q_direct!(static mut Q, NUM_CONTROLS, f32, 0.0); unsafe { assert_eq!(Q.len(), 4); assert_eq!(Q[0], 0.0_f32); } ``` -------------------------------- ### Example Usage of Regular Kalman Filter Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/regular.rs.html Demonstrates a typical workflow for a regular Kalman filter, including initialization, prediction, measurement updates, and correction. This example showcases how to set up the filter and observation structures and iterate through measurements. ```rust # #![allow(non_snake_case)] # use minikalman::prelude::*; # use minikalman::regular::{RegularKalmanBuilder, RegularObservationBuilder}; # const NUM_STATES: usize = 3; # const NUM_CONTROLS: usize = 0; # const NUM_OBSERVATIONS: usize = 1; # // System buffers. # impl_buffer_x!(mut gravity_x, NUM_STATES, f32, 0.0); # impl_buffer_A!(mut gravity_A, NUM_STATES, f32, 0.0); # impl_buffer_P!(mut gravity_P, NUM_STATES, f32, 0.0); # impl_buffer_Q_direct!(mut gravity_Q, NUM_STATES, f32, 0.0); # // Filter temporaries. # impl_buffer_temp_x!(mut gravity_temp_x, NUM_STATES, f32, 0.0); # impl_buffer_temp_P!(mut gravity_temp_P, NUM_STATES, f32, 0.0); # let mut filter = RegularKalmanBuilder::new::( # gravity_A, # gravity_x, # gravity_P, # gravity_Q, # gravity_temp_x, # gravity_temp_P, # ); # // Observation buffers. # impl_buffer_z!(mut gravity_z, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_H!(mut gravity_H, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); # impl_buffer_R!(mut gravity_R, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_y!(mut gravity_y, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_S!(mut gravity_S, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_K!(mut gravity_K, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); # // Observation temporaries. # impl_buffer_temp_S_inv!(mut gravity_temp_S_inv, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_temp_HP!(mut gravity_temp_HP, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); # impl_buffer_temp_PHt!(mut gravity_temp_PHt, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_temp_KHP!(mut gravity_temp_KHP, NUM_STATES, f32, 0.0); # let mut measurement = RegularObservationBuilder::new::( # gravity_H, # gravity_z, # gravity_R, # gravity_y, # gravity_S, # gravity_K, # gravity_temp_S_inv, # gravity_temp_HP, # gravity_temp_PHt, # gravity_temp_KHP, # ); # const REAL_DISTANCE: &[f32] = &[0.0, 0.0, 0.0]; # const OBSERVATION_ERROR: &[f32] = &[0.0, 0.0, 0.0]; for t in 0..REAL_DISTANCE.len() { // Prediction. filter.predict(); // Measure ... let m = REAL_DISTANCE[t] + OBSERVATION_ERROR[t]; measurement.measurement_vector_mut().apply(|z| z[0] = m); // Update. filter.correct(&mut measurement); } ``` -------------------------------- ### Example Usage of KalmanFilterBuilder Source: https://docs.rs/minikalman/latest/minikalman/extended/builder/struct.KalmanFilterBuilder.html Demonstrates how to create a KalmanFilterBuilder, build a filter, and initialize an observation measurement. This example requires specifying the number of states, controls, and observations. ```rust use minikalman::extended::builder::KalmanFilterBuilder; const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 2; const NUM_OBSERVATIONS: usize = 5; let builder = KalmanFilterBuilder::::default(); let mut filter = builder.build(); let mut measurement = builder.observations().build::(); ``` -------------------------------- ### Example Usage of size_buffer_temp_x Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_temp_x.html Demonstrates how to use the size_buffer_temp_x macro to get the buffer size for a given number of states. Ensure NUM_STATES is defined. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_temp_x!(NUM_STATES), 3); ``` -------------------------------- ### Example Usage of size_buffer_sigma_observed Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_sigma_observed.html Demonstrates how to use the size_buffer_sigma_observed macro with constant values for the number of observations and states. This example asserts that for 2 observations and 3 states, the resulting buffer size is 14. ```rust const NUM_OBSERVATIONS: usize = 2; const NUM_STATES: usize = 3; assert_eq!(size_buffer_sigma_observed!(NUM_OBSERVATIONS, NUM_STATES), 14); ``` -------------------------------- ### Example: Initialize KalmanFilterBuilder and build a filter Source: https://docs.rs/minikalman/latest/minikalman/unscented/builder/struct.KalmanFilterBuilder.html Demonstrates how to create a `KalmanFilterBuilder` and then use it to build an `UnscentedKalman` filter. The number of states and sigma points are defined as constants. ```rust use minikalman::unscented::builder::KalmanFilterBuilder; const NUM_STATES: usize = 3; const NUM_SIGMA: usize = 2 * NUM_STATES + 1; let builder = KalmanFilterBuilder::::default(); let mut filter = builder.build::(); ``` -------------------------------- ### Example Usage of size_buffer_Q_direct Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_Q_direct.html Demonstrates how to use the size_buffer_Q_direct macro to determine the buffer size for a system with 3 states. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_Q_direct!(NUM_STATES), 9); ``` -------------------------------- ### KalmanFilterBuilder::build() Example Source: https://docs.rs/minikalman/latest/minikalman/regular/builder/struct.KalmanFilterBuilder.html Demonstrates how to use KalmanFilterBuilder to create a new Kalman filter instance. It also shows how to initialize control and measurement builders. ```rust use minikalman::regular::builder::KalmanFilterBuilder; const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 2; const NUM_OBSERVATIONS: usize = 5; let builder = KalmanFilterBuilder::::default(); let mut filter = builder.build(); let mut control = builder.controls().build::(); let mut measurement = builder.observations().build::(); ``` -------------------------------- ### Example Usage of size_buffer_sigma_points Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_sigma_points.html Demonstrates how to use the size_buffer_sigma_points macro with a constant number of states. Ensure the NUM_STATES is defined. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_sigma_points!(NUM_STATES), 21); ``` -------------------------------- ### Extended Kalman Filter Nonlinear Prediction and Correction Example Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/extended.rs.html Demonstrates the nonlinear prediction and correction steps of an Extended Kalman Filter. Requires setup of system and observation buffers, and linearization of state and measurement Jacobians (marked with TODOs). ```rust # #![allow(non_snake_case)] use minikalman::prelude::*; use minikalman::extended::*; # const NUM_STATES: usize = 3; # const NUM_CONTROLS: usize = 0; # const NUM_OBSERVATIONS: usize = 1; # // System buffers. # impl_buffer_x!(mut gravity_x, NUM_STATES, f32, 0.0); # impl_buffer_A!(mut gravity_A, NUM_STATES, f32, 0.0); # impl_buffer_P!(mut gravity_P, NUM_STATES, f32, 0.0); # impl_buffer_Q_direct!(mut gravity_Q, NUM_STATES, f32, 0.0); # # // Filter temporaries. # impl_buffer_temp_x!(mut gravity_temp_x, NUM_STATES, f32, 0.0); # impl_buffer_temp_P!(mut gravity_temp_P, NUM_STATES, f32, 0.0); # # let mut filter = ExtendedKalmanBuilder::new::( # gravity_A, # gravity_x, # gravity_P, # gravity_Q, # gravity_temp_x, # gravity_temp_P, # ); # # // Observation buffers. # impl_buffer_z!(mut gravity_z, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_H!(mut gravity_H, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); # impl_buffer_R!(mut gravity_R, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_y!(mut gravity_y, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_S!(mut gravity_S, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_K!(mut gravity_K, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); # # // Observation temporaries. # impl_buffer_temp_S_inv!(mut gravity_temp_S_inv, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_temp_HP!(mut gravity_temp_HP, NUM_OBSERVATIONS, NUM_STATES, f32, 0.0); # impl_buffer_temp_PHt!(mut gravity_temp_PHt, NUM_STATES, NUM_OBSERVATIONS, f32, 0.0); # impl_buffer_temp_KHP!(mut gravity_temp_KHP, NUM_STATES, f32, 0.0); # # let mut measurement = ExtendedObservationBuilder::new::( # gravity_H, # gravity_z, # gravity_R, # gravity_y, # gravity_S, # gravity_K, # gravity_temp_S_inv, # gravity_temp_HP, # gravity_temp_PHt, # gravity_temp_KHP, # ); # # const REAL_DISTANCE: &[f32] = &[0.0, 0.0, 0.0]; # const OBSERVATION_ERROR: &[f32] = &[0.0, 0.0, 0.0]; # for t in 0..REAL_DISTANCE.len() { // TODO: update the state Jacobian // Prediction. filter.predict_nonlinear(|current, next| { // Any arbitrary state transition. next[0] = current[0] + current[1].cos(); next[1] = current[1] + current[1].sin(); }); // Measure ... let m = REAL_DISTANCE[t] + OBSERVATION_ERROR[t]; // TODO: update the measurement Jacobian // Apply a measurement of the unchanged state. filter.correct_nonlinear(&mut measurement, |state, observation| { // Any arbitrary observation. observation[0] = state[0].cos() * state[1]; }); } ``` -------------------------------- ### state_transition_jacobian Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/extended.rs.html Gets a reference to the state transition matrix A/F, or its Jacobian. In the context of Extended Kalman Filters, when updating using `correct_nonlinear`, this matrix is treated as the Jacobian of the state transition matrix, i.e., the derivative of the state transition matrix with respect to the state vector. See `predict_nonlinear` for usage examples. ```APIDOC ## state_transition_jacobian ### Description Gets a reference to the state transition matrix A/F, or its Jacobian. For Extended Kalman Filters, this is treated as the Jacobian of the state transition matrix during nonlinear corrections. ### Method `&self` ### Returns A reference to the state transition matrix `A`. ``` -------------------------------- ### state_transition_jacobian_mut Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/extended.rs.html Gets a mutable reference to the state transition matrix A/F, or its Jacobian. This matrix describes how the state vector evolves from one time step to the next in the absence of control inputs. For Extended Kalman Filters, when updating using `correct_nonlinear`, this matrix is treated as the Jacobian of the state transition matrix. See `predict_nonlinear` for usage examples. ```APIDOC ## state_transition_jacobian_mut ### Description Gets a mutable reference to the state transition matrix A/F, or its Jacobian. For Extended Kalman Filters, this is treated as the Jacobian of the state transition matrix during nonlinear corrections. ### Method `&mut self` ### Returns A mutable reference to the state transition matrix `A`. ``` -------------------------------- ### Get element function for DirectProcessNoiseCovarianceMatrixMutBuffer Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.DirectProcessNoiseCovarianceMatrixBufferOwnedType.html Gets a matrix element at the specified row and column. Requires the element type `T` to be `Copy`. ```rust fn get(&self, row: usize, column: usize) -> T where T: Copy, ``` -------------------------------- ### Example Usage of size_buffer_x Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_x.html Demonstrates how to use the size_buffer_x macro with a constant number of states to assert the expected buffer size. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_x!(NUM_STATES), 3); ``` -------------------------------- ### Get row copy function for DirectProcessNoiseCovarianceMatrixMutBuffer Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.DirectProcessNoiseCovarianceMatrixBufferOwnedType.html Gets a copy of a matrix row into the provided slice. Requires the element type `T` to be `Copy`. ```rust fn get_row_copy(&self, row: usize, row_data: &mut [T]) where T: Copy, ``` -------------------------------- ### Get column copy function for DirectProcessNoiseCovarianceMatrixMutBuffer Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.DirectProcessNoiseCovarianceMatrixBufferOwnedType.html Gets a copy of a matrix column into the provided slice. Requires the element type `T` to be `Copy`. ```rust fn get_column_copy(&self, column: usize, col_data: &mut [T]) where T: Copy, ``` -------------------------------- ### Example Usage of size_buffer_sigma_weights Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_sigma_weights.html Demonstrates how to use the size_buffer_sigma_weights macro with a constant number of states to assert the correct buffer size. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_sigma_weights!(NUM_STATES), 7); ``` -------------------------------- ### Get Measurement Noise Covariance Reference (Trait Impl) Source: https://docs.rs/minikalman/latest/minikalman/regular/builder/type.KalmanFilterObservationType.html Implementation of the KalmanFilterMeasurementNoiseCovariance trait to get a reference to the measurement noise covariance matrix. ```rust fn measurement_noise_covariance( &self, ) -> &Self::MeasurementNoiseCovarianceMatrix ``` -------------------------------- ### Build and Operate Regular Kalman Filter Source: https://docs.rs/minikalman/latest/index.html Example of setting up and running a regular Kalman filter using the KalmanFilterBuilder. This is suitable for systems with linear dynamics and observations. Ensure 'std' or 'alloc' features are enabled. ```rust use minikalman::regular::builder::KalmanFilterBuilder; use minikalman::prelude::MatrixMut; const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 2; const NUM_OBSERVATIONS: usize = 1; let builder = KalmanFilterBuilder::::default(); let mut filter = builder.build(); let mut control = builder.controls().build::(); let mut measurement = builder.observations().build::(); // Set up the system dynamics, control matrices, observation matrices, ... // Filter! loop { // Update your control vector(s). control.control_vector_mut().apply(|u| { u[0] = 0.0; u[1] = 1.0; }); // Update your measurement vectors. measurement.measurement_vector_mut().apply(|z| { z[0] = 42.0; }); // Update prediction (without controls). filter.predict(); // Apply any controls to the prediction. filter.control(&mut control); // Apply any measurements. filter.correct(&mut measurement); // Access the state let state = filter.state_vector(); let covariance = filter.estimate_covariance(); } ``` -------------------------------- ### new_with Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/struct.KalmanGainMatrixBufferBuilder.html Builds a new `KalmanGainMatrixBuffer` that owns its data, initializing it with a specified value. ```APIDOC ## new_with ### Description Builds a new `KalmanGainMatrixBuffer` that owns its data. ### Signature ```rust pub fn new_with(&self, init: T) -> KalmanGainMatrixBufferOwnedType where T: Copy, ``` ### Example ```rust use minikalman::buffers::types::KalmanGainMatrixBuffer; use minikalman::prelude::* let buffer = BufferBuilder::kalman_gain_K::<3, 5>().new_with(0.0); let buffer: KalmanGainMatrixBuffer<3, 5, f32, _> = buffer; assert_eq!(buffer.len(), 15); ``` ``` -------------------------------- ### KalmanFilterBuilder Default Example Source: https://docs.rs/minikalman/latest/minikalman/unscented/builder/struct.KalmanFilterObservationBuilder.html Demonstrates how to create a new KalmanFilterBuilder and build an observation using it. This requires specifying the number of states, sigma points, and observations. ```rust use minikalman::unscented::builder::KalmanFilterBuilder; const NUM_STATES: usize = 3; const NUM_SIGMA: usize = 2 * NUM_STATES + 1; const NUM_OBSERVATIONS: usize = 2; let builder = KalmanFilterBuilder::::default(); let mut measurement = builder.observations().build::(); ``` -------------------------------- ### type_id Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.TemporaryKHPMatrixBuffer.html Gets the `TypeId` of `self`. ```APIDOC ## type_id ### Description Gets the `TypeId` of `self`. ### Signature `fn type_id(&self) -> TypeId` ``` -------------------------------- ### UKF Constructor and Parameter Initialization Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/unscented.rs.html Demonstrates the `new` constructor for the `UnscentedKalman` filter, showing how to initialize it with various types and set initial alpha, beta, and kappa values. ```rust let filter: UnscentedKalman< 3, 7, f32, Dummy, Dummy, Dummy, Dummy, Dummy, Dummy, Dummy, Dummy, > = UnscentedKalman::new( Dummy::default(), Dummy::default(), Dummy::default(), Dummy::default(), Dummy::default(), Dummy::default(), Dummy::default(), Dummy::default(), 1.0, 2.0, 0.5, ); assert_eq!(filter.alpha(), 1.0); assert_eq!(filter.beta(), 2.0); assert_eq!(filter.kappa(), 0.5); ``` -------------------------------- ### Example: Creating a static mut buffer Source: https://docs.rs/minikalman/latest/minikalman/macro.impl_buffer_P.html Demonstrates how to use the impl_buffer_P macro to create a `static mut` binding for an estimate covariance matrix buffer. It asserts the buffer's length and initial value. ```rust const NUM_STATES: usize = 3; impl_buffer_P!(static mut P, NUM_STATES, f32, 0.0); unsafe { assert_eq!(P.len(), 9); assert_eq!(P[0], 0.0_f32); } ``` -------------------------------- ### ControlProcessNoiseCovarianceMatrixMutBuffer::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.ControlProcessNoiseCovarianceMatrixMutBuffer.html Gets a matrix element. ```APIDOC ## ControlProcessNoiseCovarianceMatrixMutBuffer::get ### Description Gets a matrix element. ### Trait `Matrix` ### Signature ```rust fn get(&self, row: usize, column: usize) -> T where T: Copy ``` ### Parameters * `row`: The row index. * `column`: The column index. ### Returns The matrix element at the specified row and column. ``` -------------------------------- ### Example Usage of size_buffer_K Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_K.html Demonstrates how to use the size_buffer_K macro to determine the buffer size for a Kalman gain matrix. Ensure the NUM_STATES and NUM_OBSERVATIONS are defined. ```rust const NUM_STATES: usize = 3; const NUM_OBSERVATIONS: usize = 1; assert_eq!(size_buffer_K!(NUM_STATES, NUM_OBSERVATIONS), 3); ``` -------------------------------- ### EstimateCovarianceMatrixBuffer::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.EstimateCovarianceMatrixBuffer.html Gets a matrix element. ```APIDOC ## fn get(&self, row: usize, column: usize) -> T Gets a matrix element Read more ``` -------------------------------- ### ControlMatrixMutBuffer::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.ControlMatrixBufferOwnedType.html Gets a matrix element. ```APIDOC ## fn get(&self, row: usize, column: usize) -> T Gets a matrix element. ``` -------------------------------- ### Example: Creating a static mut BQ Matrix Buffer Source: https://docs.rs/minikalman/latest/src/minikalman/static_macros.rs.html Demonstrates how to use the `impl_buffer_temp_BQ!` macro to create a static mutable binding for a BQ matrix. ```rust # use minikalman::prelude::*; const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 2; impl_buffer_temp_BQ!(static mut TBQ, NUM_STATES, NUM_CONTROLS, f32, 0.0); unsafe { assert_eq!(TBQ.len(), 6); assert_eq!(TBQ[0], 0.0_f32); } ``` -------------------------------- ### Example Usage of impl_buffer_Q_control Source: https://docs.rs/minikalman/latest/minikalman/macro.impl_buffer_Q_control.html Demonstrates how to use the impl_buffer_Q_control macro to create a static mutable binding for the Q matrix. This is useful for initializing the control process noise covariance matrix. ```rust const NUM_CONTROLS: usize = 2; impl_buffer_Q_control!(static mut Q, NUM_CONTROLS, f32, 0.0); unsafe { assert_eq!(Q.len(), 4); assert_eq!(Q[0], 0.0_f32); } ``` -------------------------------- ### SigmaObservedMatrixBuffer::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.SigmaObservedMatrixBufferOwnedType.html Gets a matrix element. ```APIDOC ### `Matrix::get` ```rust fn get(&self, row: usize, column: usize) -> T where T: Copy ``` Gets a matrix element. ``` -------------------------------- ### Matrix::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.ControlProcessNoiseCovarianceMatrixBufferOwnedType.html Gets a matrix element. ```APIDOC ## `get` ```rust fn get(&self, row: usize, column: usize) -> T where T: Copy ``` Gets a matrix element. ``` -------------------------------- ### UKF Kalman Filter Builder Example Source: https://docs.rs/minikalman/latest/src/minikalman/kalman_builder/unscented.rs.html Demonstrates the construction of an Unscented Kalman Filter using the builder pattern. This test verifies the filter's state and sigma point count. ```rust #[test] fn ukf_kalman_builder() { let builder = KalmanFilterBuilder::::default(); let filter = builder.build::(); assert_eq!(filter.states(), NUM_STATES); assert_eq!(filter.num_sigma_points(), NUM_SIGMA); accept_filter(filter); } ``` -------------------------------- ### Example Usage of size_buffer_R Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_R.html Demonstrates how to use the size_buffer_R macro with a constant number of observations to assert the expected buffer size. ```rust const NUM_OBSERVATIONS: usize = 1; assert_eq!(size_buffer_R!(NUM_OBSERVATIONS), 1); ``` -------------------------------- ### UnscentedObservation::measurement_vector Source: https://docs.rs/minikalman/latest/minikalman/unscented/struct.UnscentedObservation.html Gets a reference to the measurement vector. ```APIDOC ## UnscentedObservation::measurement_vector ### Description Gets a reference to the measurement vector. ### Returns - &Z - A reference to the measurement vector. ``` -------------------------------- ### Example usage of size_buffer_temp_P macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_temp_P.html Demonstrates how to use the size_buffer_temp_P macro with a constant number of states to assert the expected buffer size. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_temp_P!(NUM_STATES), 9); ``` -------------------------------- ### control_vector Source: https://docs.rs/minikalman/latest/minikalman/regular/builder/type.KalmanFilterControlType.html Gets a reference to the control vector u. ```APIDOC ## fn control_vector(&self) -> &Self::ControlVector Gets a reference to the control vector u. ``` -------------------------------- ### new Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/struct.KalmanGainMatrixBufferBuilder.html Builds a new `KalmanGainMatrixBuffer` that owns its data. This method initializes the buffer with default values. ```APIDOC ## new ### Description Builds a new `KalmanGainMatrixBuffer` that owns its data. ### Signature ```rust pub fn new(&self) -> KalmanGainMatrixBufferOwnedType where T: Copy + Default, ``` ### Example ```rust use minikalman::buffers::types::KalmanGainMatrixBuffer; use minikalman::prelude::* let buffer = BufferBuilder::kalman_gain_K::<3, 5>().new(); let buffer: KalmanGainMatrixBuffer<3, 5, f32, _> = buffer; assert_eq!(buffer.len(), 15); ``` ``` -------------------------------- ### control_vector Source: https://docs.rs/minikalman/latest/minikalman/regular/builder/type.KalmanFilterControlType.html Gets a reference to the control vector u. ```APIDOC ## `control_vector` ### Description Gets a reference to the control vector u. The control vector contains the external inputs to the system that can influence its state. These inputs might include forces, accelerations, or other actuations applied to the system. ### Signature ```rust pub fn control_vector(&self) -> &U ``` ``` -------------------------------- ### Example Usage of size_buffer_z Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_z.html Demonstrates how to use the size_buffer_z macro with a constant number of observations to assert the expected buffer size. ```rust const NUM_OBSERVATIONS: usize = 1; assert_eq!(size_buffer_z!(NUM_OBSERVATIONS), 1); ``` -------------------------------- ### measurement_vector Source: https://docs.rs/minikalman/latest/minikalman/extended/builder/type.KalmanFilterObservationType.html Gets a reference to the measurement vector z. ```APIDOC ## fn measurement_vector(&self) -> &Self::MeasurementVector ### Description Gets a reference to the measurement vector z. ``` -------------------------------- ### Example Usage of size_buffer_B Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_B.html Demonstrates how to use the size_buffer_B macro with constant values for states and controls. Asserts the expected buffer size. ```rust const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 1; assert_eq!(size_buffer_B!(NUM_STATES, NUM_CONTROLS), 3); ``` -------------------------------- ### measurement_vector Source: https://docs.rs/minikalman/latest/minikalman/extended/builder/type.KalmanFilterObservationType.html Gets a reference to the measurement vector z. ```APIDOC ## pub fn measurement_vector(&self) -> &Z Gets a reference to the measurement vector z. ``` -------------------------------- ### Example usage of size_buffer_temp_PHt macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_temp_PHt.html Demonstrates how to use the size_buffer_temp_PHt macro to determine the buffer size for a given number of states and measurements. Ensure NUM_STATES and NUM_OBSERVATIONS are defined. ```rust const NUM_STATES: usize = 3; const NUM_OBSERVATIONS: usize = 1; assert_eq!(size_buffer_temp_PHt!(NUM_STATES, NUM_OBSERVATIONS), 3); ``` -------------------------------- ### ControlProcessNoiseCovarianceMatrixMutBuffer::get_row_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.ControlProcessNoiseCovarianceMatrixMutBuffer.html Gets a copy of a matrix row. ```APIDOC ## ControlProcessNoiseCovarianceMatrixMutBuffer::get_row_copy ### Description Gets a copy of a matrix row. ### Trait `Matrix` ### Signature ```rust fn get_row_copy(&self, row: usize, row_data: &mut [T]) where T: Copy ``` ### Parameters * `row`: The row index. * `row_data`: A mutable slice to store the row data. ``` -------------------------------- ### ControlProcessNoiseCovarianceMatrixMutBuffer::get_column_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.ControlProcessNoiseCovarianceMatrixMutBuffer.html Gets a copy of a matrix column. ```APIDOC ## ControlProcessNoiseCovarianceMatrixMutBuffer::get_column_copy ### Description Gets a copy of a matrix column. ### Trait `Matrix` ### Signature ```rust fn get_column_copy(&self, column: usize, col_data: &mut [T]) where T: Copy ``` ### Parameters * `column`: The column index. * `col_data`: A mutable slice to store the column data. ``` -------------------------------- ### Example: Generate a static mut binding for impl_buffer_u Source: https://docs.rs/minikalman/latest/minikalman/macro.impl_buffer_u.html Demonstrates how to use the impl_buffer_u macro to create a mutable static control vector buffer and verify its initial state and length. ```rust const NUM_CONTROLS: usize = 2; impl_buffer_u!(static mut U, NUM_CONTROLS, f32, 0.0); unsafe { assert_eq!(U.len(), 2); assert_eq!(U[0], 0.0_f32); } ``` -------------------------------- ### DirectProcessNoiseCovarianceMatrixMutBuffer::get_row_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.DirectProcessNoiseCovarianceMatrixMutBuffer.html Gets a copy of a matrix row. ```APIDOC ## DirectProcessNoiseCovarianceMatrixMutBuffer::get_row_copy ### Description Copies the elements of a specified row into a provided mutable slice. ### Signature ```rust fn get_row_copy(&self, row: usize, row_data: &mut [T]) ``` ### Parameters * `row`: The index of the row to retrieve. * `row_data`: A mutable slice to store the copied row data. ``` -------------------------------- ### Example Usage of size_buffer_temp_KHP Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_temp_KHP.html Demonstrates how to use the size_buffer_temp_KHP macro with a constant number of states to assert the expected buffer size. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_temp_KHP!(NUM_STATES), 9); ``` -------------------------------- ### Example Usage of size_buffer_P Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_P.html Demonstrates how to use the size_buffer_P macro to calculate the buffer size for a system with 3 states. The expected output is 9. ```rust const NUM_STATES: usize = 3; assert_eq!(size_buffer_P!(NUM_STATES), 9); ``` -------------------------------- ### DirectProcessNoiseCovarianceMatrixMutBuffer::get_column_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.DirectProcessNoiseCovarianceMatrixMutBuffer.html Gets a copy of a matrix column. ```APIDOC ## DirectProcessNoiseCovarianceMatrixMutBuffer::get_column_copy ### Description Copies the elements of a specified column into a provided mutable slice. ### Signature ```rust fn get_column_copy(&self, column: usize, col_data: &mut [T]) ``` ### Parameters * `column`: The index of the column to retrieve. * `col_data`: A mutable slice to store the copied column data. ``` -------------------------------- ### Initialize System Matrix A Buffer Builder Source: https://docs.rs/minikalman/latest/src/minikalman/buffers/builder.rs.html Use this to create a builder for the system state transition matrix (A). Specify the number of states using the generic parameter `STATES`. ```rust 15 #[allow(non_snake_case)] 16 #[doc(alias = "system_state_transition_A")] 17 pub fn system_matrix_A() -> StateTransitionMatrixBufferBuilder { 18 StateTransitionMatrixBufferBuilder 19 } 20 ``` -------------------------------- ### EstimateCovarianceMatrixBuffer::get_row_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.EstimateCovarianceMatrixBuffer.html Gets a copy of a matrix row. ```APIDOC ## fn get_row_copy(&self, row: usize, row_data: &mut [T]) Gets a copy of a matrix row Read more ``` -------------------------------- ### Example Usage of size_buffer_temp_BQ Macro Source: https://docs.rs/minikalman/latest/minikalman/macro.size_buffer_temp_BQ.html Demonstrates how to use the size_buffer_temp_BQ macro to determine the buffer size for a temporary BxQ matrix. Ensure NUM_STATES and NUM_CONTROLS are defined. ```rust const NUM_STATES: usize = 3; const NUM_CONTROLS: usize = 1; assert_eq!(size_buffer_temp_BQ!(NUM_STATES, NUM_CONTROLS), 3); ``` -------------------------------- ### EstimateCovarianceMatrixBuffer::get_column_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/types/struct.EstimateCovarianceMatrixBuffer.html Gets a copy of a matrix column. ```APIDOC ## fn get_column_copy(&self, column: usize, col_data: &mut [T]) Gets a copy of a matrix column Read more ``` -------------------------------- ### Initialize Control Process Noise Covariance Q Buffer Builder Source: https://docs.rs/minikalman/latest/src/minikalman/buffers/builder.rs.html Use this to create a builder for the control process noise covariance matrix (Q). Specify the number of controls using the generic parameter `CONTROLS`. ```rust 45 #[allow(non_snake_case)] 46 #[doc(alias = "control_covariance_Q")] 47 pub fn control_process_noise_covariance_Q( 48 ) -> ControlProcessNoiseCovarianceMatrixBufferBuilder { 49 ControlProcessNoiseCovarianceMatrixBufferBuilder 50 } 51 ``` -------------------------------- ### StateVectorBuffer::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.StateVectorBufferOwnedType.html Gets a matrix element from the StateVectorBuffer. ```APIDOC #### `fn get(&self, row: usize, column: usize) -> T` where T: Copy, Gets a matrix element. ``` -------------------------------- ### ControlVectorBuffer::get Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.ControlVectorBufferOwnedType.html Gets a matrix element from ControlVectorBuffer. ```APIDOC #### fn get(&self, row: usize, column: usize) -> T where T: Copy, Gets a matrix element. ``` -------------------------------- ### new Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/struct.TemporaryPHtMatrixBufferBuilder.html Builds a new `TemporaryPHTMatrixBuffer` that owns its data, initialized with default values. ```APIDOC ## new ### Description Builds a new `TemporaryPHTMatrixBuffer` that owns its data. ### Signature ```rust pub fn new(&self) -> TemporaryPHtMatrixBufferOwnedType where T: Copy + Default, ``` ### Example ```rust use minikalman::buffers::types::TemporaryPHTMatrixBuffer; use minikalman::prelude::* let buffer = BufferBuilder::temp_PHt::<3, 5>().new(); let buffer: TemporaryPHTMatrixBuffer<3, 5, f32, _> = buffer; assert_eq!(buffer.len(), 15); ``` ``` -------------------------------- ### Kalman Filter Initialization and State Checks Source: https://docs.rs/minikalman/latest/src/minikalman/kalman/regular.rs.html Demonstrates the creation of a test Kalman filter and basic assertions on its state and covariance after initialization and prediction steps. This includes checking the state vector for zeros and verifying specific values in the estimate covariance matrix. ```rust use crate::prelude::*; use assert_float_eq::*; let mut example = crate::test_filter::create_test_filter(1.0); // The estimate covariance still is scalar. assert!(example .filter .estimate_covariance() .inspect(|mat| (0..3).into_iter().all(|i| { mat.get_at(i, i) == 0.1 }))); // Since our initial state is zero, any number of prediction steps keeps the filter unchanged. for _ in 0..10 { example.filter.predict(); } // All states are zero. assert!(example .filter .state_vector() .as_ref() .iter() .all(|&x| x == 0.0)); // The estimate covariance has changed. example.filter.estimate_covariance().inspect(|mat| { assert_f32_near!(mat.get_at(0, 0), 260.1); assert_f32_near!(mat.get_at(1, 1), 10.1); assert_f32_near!(mat.get_at(2, 2), 0.1); }); ``` -------------------------------- ### ControlMatrixMutBuffer::get_row_copy Source: https://docs.rs/minikalman/latest/minikalman/buffers/builder/type.ControlMatrixBufferOwnedType.html Gets a copy of a matrix row. ```APIDOC ## fn get_row_copy(&self, row: usize, row_data: &mut [T]) Gets a copy of a matrix row. ```