use super::AIRBORNE_HEIGHT_M;
use crate::VehicleState;
use crate::estimation::wind::{WindConfig, WindEstimate, WindEstimator};
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub(crate) struct HoverWind {
estimator: WindEstimator,
ground_altitude_m: Option<f32>,
paused: bool,
}
impl HoverWind {
pub(crate) fn update(&mut self, dt: f32, config: &WindConfig, state: &VehicleState) {
if !self.paused && self.airborne(state) {
self.estimator.update(dt, config, state);
}
}
pub(crate) fn prime(&mut self, state: &VehicleState) {
if !self.airborne(state) {
self.ground_altitude_m = Some(state.position_m.z).filter(|z| z.is_finite());
self.estimator.reset();
}
}
pub(crate) fn set_paused(&mut self, paused: bool) {
self.paused = paused;
}
pub(crate) fn estimate(&self) -> Option<WindEstimate> {
self.estimator.estimate()
}
fn airborne(&self, state: &VehicleState) -> bool {
self.ground_altitude_m
.is_some_and(|ground_m| state.position_m.z > ground_m + AIRBORNE_HEIGHT_M)
}
}