Skip to main content

rust_gnc/control/
failsafe.rs

1//! # Failsafe System
2//! 
3//! Monitors the health of the system and triggers emergency responses.
4
5#[derive(Debug, PartialEq, Clone, Copy)]
6pub enum FailsafeLevel {
7    None,       // All systems nominal
8    // Warning,    // Low battery or weak signal (Alert only)
9    Land,       // Critical failure, immediate controlled descent
10    Kill,       // Total failure, stop motors immediately (Safety)
11}
12
13pub struct FailsafeMonitor {
14    last_heartbeat: f32, // Timestamp of last valid input
15    timeout_threshold: f32,
16}
17
18impl FailsafeMonitor {
19    pub fn new(timeout: f32) -> Self {
20        Self {
21            last_heartbeat: 0.0,
22            timeout_threshold: timeout,
23        }
24    }
25
26    /// Evaluates system health based on current time.
27    pub fn check(&self, current_time: f32) -> FailsafeLevel {
28        if current_time - self.last_heartbeat > self.timeout_threshold {
29            FailsafeLevel::Land
30        } else {
31            FailsafeLevel::None
32        }
33    }
34
35    pub fn feed_heartbeat(&mut self, current_time: f32) {
36        self.last_heartbeat = current_time;
37    }
38}