|
2 | 2 | /// |
3 | 3 | /// The API uses progressive disclosure: |
4 | 4 | /// - `Scheduler::new()` — lightweight, no syscalls |
5 | | -/// - Builder methods opt in to features: `.realtime()`, `.with_blackbox()`, `.tick_hz()` |
| 5 | +/// - `SchedulerConfig` fields opt in to features: RT, BlackBox, safety monitor |
6 | 6 | /// - Presets bundle common configurations: `deploy()`, `safety_critical()`, `deterministic()` |
7 | 7 | use horus_core::scheduling::{config::SchedulerConfig, Scheduler}; |
8 | 8 |
|
@@ -39,33 +39,38 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { |
39 | 39 | println!(); |
40 | 40 |
|
41 | 41 | // ======================================================================== |
42 | | - // Pattern 3: Builder — compose exactly what you need |
| 42 | + // Pattern 3: Config — compose exactly what you need |
43 | 43 | // ======================================================================== |
44 | | - println!("Pattern 3: Builder Composition"); |
45 | | - println!("------------------------------"); |
| 44 | + println!("Pattern 3: Config Composition"); |
| 45 | + println!("-----------------------------"); |
46 | 46 |
|
| 47 | + let mut config = SchedulerConfig::standard(); |
| 48 | + config.realtime.rt_scheduling_class = true; |
| 49 | + config.monitoring.black_box_enabled = true; |
| 50 | + config.monitoring.black_box_size_mb = 8; |
47 | 51 | let _scheduler = Scheduler::new() |
48 | | - .realtime() // RT priority + memory lock + CPU pin |
49 | | - .with_blackbox(8) // 8MB flight recorder |
| 52 | + .with_config(config) |
50 | 53 | .tick_hz(1000.0) // 1kHz control loop |
51 | 54 | .with_name("CustomRobot"); |
52 | 55 |
|
53 | | - println!("[OK] Custom builder composition"); |
| 56 | + println!("[OK] Custom config composition"); |
54 | 57 | println!(" RT: enabled, BlackBox: 8MB, Rate: 1kHz\n"); |
55 | 58 |
|
56 | 59 | // ======================================================================== |
57 | | - // Pattern 4: Config Preset (advanced) |
| 60 | + // Pattern 4: Config Preset + extras |
58 | 61 | // ======================================================================== |
59 | | - println!("Pattern 4: Config Preset"); |
60 | | - println!("------------------------"); |
| 62 | + println!("Pattern 4: Config Preset + Extras"); |
| 63 | + println!("---------------------------------"); |
61 | 64 |
|
| 65 | + let mut config = SchedulerConfig::hard_realtime(); |
| 66 | + config.realtime.safety_monitor = true; |
| 67 | + config.realtime.max_deadline_misses = 3; |
62 | 68 | let _scheduler = Scheduler::new() |
63 | | - .with_config(SchedulerConfig::hard_realtime()) |
| 69 | + .with_config(config) |
64 | 70 | .with_capacity(128) |
65 | | - .with_safety_monitor(3) |
66 | 71 | .with_name("HardRT"); |
67 | 72 |
|
68 | | - println!("[OK] hard_realtime config preset"); |
| 73 | + println!("[OK] hard_realtime config preset + safety monitor"); |
69 | 74 | println!(" WCET enforcement, 10ms watchdog, panic on deadline miss\n"); |
70 | 75 |
|
71 | 76 | // ======================================================================== |
@@ -123,10 +128,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { |
123 | 128 | println!(" Scheduler::hard_realtime() Strict deadlines"); |
124 | 129 | println!(" Scheduler::deterministic() Reproducible execution"); |
125 | 130 | println!(); |
126 | | - println!(" .realtime() Opt-in RT priority + memory lock + CPU pin"); |
127 | | - println!(" .with_blackbox(N) Opt-in N MB flight recorder"); |
128 | | - println!(" .tick_hz(Hz) Set global tick rate"); |
129 | 131 | println!(" .with_config(C) Apply a SchedulerConfig preset"); |
| 132 | + println!(" .tick_hz(Hz) Set global tick rate"); |
| 133 | + println!(" .with_name(S) Name the scheduler instance"); |
| 134 | + println!(" .with_capacity(N) Pre-allocate node slots"); |
130 | 135 |
|
131 | 136 | Ok(()) |
132 | 137 | } |
0 commit comments