Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/aegis_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ aegis_real aegis_fusion4_get_variance(const AegisFusion4* fusion);
*/
aegis_real aegis_fusion4_get_sensor_health(const AegisFusion4* fusion, uint8_t sensor_id);

/**
* @brief Checks if a sensor is currently quarantined by automated FDIR.
*
* @param fusion Pointer to fusion engine.
* @param sensor_id Unique sensor ID.
* @return 1 if quarantined, 0 if active/nominal, -1 if invalid pointer or sensor not found.
*/
int aegis_fusion4_is_sensor_quarantined(const AegisFusion4* fusion, uint8_t sensor_id);

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 13 additions & 0 deletions src/eskf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,19 @@ impl ErrorStateKalmanFilter {
Ok(())
}

/// Fuses scalar 1D altitude observation (e.g. Barometric Altimeter or LiDAR/Radar).
pub fn update_altimeter(
&mut self,
altitude: Real,
noise_var: Real,
gate_sigma: Option<Real>,
) -> Result<(), FilterError> {
let y_z = altitude - self.state.position.z;
let mut h_z = [0.0; 15];
h_z[2] = 1.0;
self.update_scalar(y_z, h_z, noise_var, gate_sigma)
}

/// Fuses 3-axis magnetometer reading for yaw/heading correction against reference geomagnetic vector.
pub fn update_magnetometer(
&mut self,
Expand Down
19 changes: 19 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,22 @@ pub unsafe extern "C" fn aegis_fusion4_get_sensor_health(
.sensor_health(sensor_id)
.unwrap_or(Real::NAN)
}

/// Returns whether a sensor is currently quarantined (1 = quarantined, 0 = active, -1 = not found / error).
///
/// # Safety
/// Caller must ensure `fusion` points to a valid `AegisFusion4` or null.
#[no_mangle]
pub unsafe extern "C" fn aegis_fusion4_is_sensor_quarantined(
fusion: *const AegisFusion4,
sensor_id: u8,
) -> i32 {
if fusion.is_null() {
return -1;
}
match (*fusion).inner.is_sensor_quarantined(sensor_id) {
Some(true) => 1,
Some(false) => 0,
None => -1,
}
}
33 changes: 27 additions & 6 deletions src/fusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,32 @@ impl<const N: usize> MultiSensorFusion1D<N> {

/// Returns the active health score of a sensor by ID.
pub fn sensor_health(&self, sensor_id: u8) -> Option<Real> {
for s in self.sensors.iter().flatten() {
if s.id == sensor_id {
return Some(s.health_score);
}
}
None
self.sensors
.iter()
.flatten()
.find(|s| s.id == sensor_id)
.map(|s| s.health_score)
}

/// Returns whether a sensor is currently quarantined by ID.
pub fn is_sensor_quarantined(&self, sensor_id: u8) -> Option<bool> {
self.sensors
.iter()
.flatten()
.find(|s| s.id == sensor_id)
.map(|s| s.is_quarantined)
}

/// Returns a reference to a registered sensor by ID.
pub fn sensor(&self, sensor_id: u8) -> Option<&SensorSource> {
self.sensors.iter().flatten().find(|s| s.id == sensor_id)
}

/// Returns a mutable reference to a registered sensor by ID.
pub fn sensor_mut(&mut self, sensor_id: u8) -> Option<&mut SensorSource> {
self.sensors
.iter_mut()
.flatten()
.find(|s| s.id == sensor_id)
}
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pub mod robust;
pub mod stats;
pub mod unscented;

pub use common::{FilterError, Real, DEFAULT_MAX_CONDITION_NUMBER, DEFAULT_OUTLIER_GATE_SIGMA};
pub use common::{
FilterError, FloatOps, Real, DEFAULT_MAX_CONDITION_NUMBER, DEFAULT_OUTLIER_GATE_SIGMA,
};
pub use eskf::{
ErrorStateKalmanFilter, EskfNoiseParameters, EskfNominalState, Quaternion, Vector3,
EARTH_GRAVITY_Z_UP,
Expand Down
Loading
Loading