agentic_robotics_rt/
lib.rs

1//! ROS3 Real-Time Execution
2//!
3//! Dual runtime architecture combining Tokio (soft RT) and RTIC (hard RT)
4
5pub mod executor;
6pub mod scheduler;
7pub mod latency;
8
9pub use executor::{ROS3Executor, Priority, Deadline};
10pub use scheduler::PriorityScheduler;
11pub use latency::LatencyTracker;
12
13use std::time::Duration;
14
15/// Real-time task priority levels
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
17pub enum RTPriority {
18    /// Lowest priority (background tasks)
19    Background = 0,
20    /// Low priority
21    Low = 1,
22    /// Normal priority
23    Normal = 2,
24    /// High priority
25    High = 3,
26    /// Critical priority (hard real-time)
27    Critical = 4,
28}
29
30impl From<u8> for RTPriority {
31    fn from(value: u8) -> Self {
32        match value {
33            0 => RTPriority::Background,
34            1 => RTPriority::Low,
35            2 => RTPriority::Normal,
36            3 => RTPriority::High,
37            _ => RTPriority::Critical,
38        }
39    }
40}
41
42impl From<RTPriority> for u8 {
43    fn from(priority: RTPriority) -> Self {
44        priority as u8
45    }
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_priority_conversion() {
54        let priority = RTPriority::High;
55        let value: u8 = priority.into();
56        assert_eq!(value, 3);
57
58        let converted: RTPriority = value.into();
59        assert_eq!(converted, RTPriority::High);
60    }
61}