Expand description
Safe idiomatic Rust API for the PX4 EKF2 navigation filter.
§Quick start
use ekf2::{Ekf, types::ImuSample};
let mut ekf = Ekf::new().expect("EKF allocation failed");
// Feed IMU data at 100 Hz
for i in 0..1000_u64 {
let ts_us = i * 10_000; // 10 ms → 100 Hz
let sample = ImuSample::new(
ts_us,
[0.0, 0.0, 0.01], // tiny yaw rate
[0.0, 0.0, -9.81*0.01], // gravity
0.01,
0.01,
);
ekf.set_imu_data(&sample);
let _ = ekf.update();
}
if ekf.attitude_valid() {
let q = ekf.quaternion();
println!("q = [{:.4}, {:.4}, {:.4}, {:.4}]", q[0], q[1], q[2], q[3]);
}§Feature flags
Each sensor type is guarded by a Cargo feature (defaults: gnss,
magnetometer, barometer). See
ekf2-sys for the full table.
§Memory model
Ekf::new creates the heap-owned C++ object using Rust’s global
allocator. Ekf::new_in and Ekf::with_config_in accept any allocator-api2
allocator. The selected allocator is passed to C++ as per-instance callbacks
and is used for the object and all of its owned dynamic storage.
§no_std
This crate does not depend on std. Ekf::new uses the target’s global
allocator, while Ekf::new_in accepts a custom allocator.
Re-exports§
pub use ekf::Ekf;pub use ekf::EkfConfig;pub use error::EkfError;pub use params::BaroControl;pub use params::ControlStatus;pub use params::ExternalVisionControl;pub use params::FaultStatus;pub use params::FlowGyroSource;pub use params::GnssCheckControl;pub use params::GnssCheckFailStatus;pub use params::GnssControl;pub use params::GnssFixType;pub use params::GnssMode;pub use params::HeightReference;pub use params::ImuControl;pub use params::InformationEventStatus;pub use params::MagCheckControl;pub use params::MagDeclinationControl;pub use params::MagFusionType;pub use params::OpticalFlowControl;pub use params::PositionReference;pub use params::RangeControl;pub use params::SolnStatus;
Modules§
- ekf
- Heap-allocated PX4 EKF2 filter handle.
- error
- Error types for the EKF2 Rust API.
- params
- Safe wrapper around EKF2 runtime parameters.
- types
- Sensor sample types.
Structs§
- AidSource1d
- 1-D aid source (baro height, range height, airspeed, sideslip, …)
- AidSource2d
- 2-D aid source (GNSS position, optical flow, EV position, …) Note: observation uses double precision (lat/lon).
- AidSource3d
- 3-D aid source (GNSS velocity, magnetometer, EV velocity, gravity, …)
- Bias
Estimator Status - Scalar bias-estimator diagnostic status.
- Global
Origin - WGS-84 origin used by the EKF for local↔global position conversion.
Enums§
- Height
Sensor - Active primary height sensor reference.
- Position
Frame - Position reference frame for external vision samples.
- Velocity
Frame - Velocity reference frame for external vision samples.