Skip to content

Commit 8c918e6

Browse files
committed
remove internal API
1 parent 9db7253 commit 8c918e6

64 files changed

Lines changed: 1725 additions & 1661 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

content/docs/advanced-examples.mdx

Lines changed: 54 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl StateMachineNode {
5252
impl Node for StateMachineNode {
5353
fn name(&self) -> &'static str { "StateMachineNode" }
5454

55-
fn init(&mut self, ctx: &mut NodeInfo) -> Result<()> {
56-
ctx.log_info("State machine initialized - starting in IDLE state");
55+
fn init(&mut self) -> Result<()> {
56+
hlog!(info, "State machine initialized - starting in IDLE state");
5757
Ok(())
5858
}
5959

@@ -107,26 +107,22 @@ impl Node for StateMachineNode {
107107

108108
// Log state transitions
109109
if self.state != prev_state {
110-
if let Some(ref mut c) = ctx {
111-
c.log_info(&format!(
112-
"State transition: {:?} -> {:?}",
113-
prev_state, self.state
114-
));
115-
}
110+
hlog!(info, "State transition: {:?} -> {:?}",
111+
prev_state, self.state);
116112
}
117113
}
118114

119-
fn shutdown(&mut self, ctx: &mut NodeInfo) -> Result<()> {
115+
fn shutdown(&mut self) -> Result<()> {
120116
// Ensure robot is stopped
121-
self.cmd_pub.send(CmdVel::zero(), &mut None).ok();
122-
ctx.log_info("State machine shutdown");
117+
self.cmd_pub.send(CmdVel::zero()).ok();
118+
hlog!(info, "State machine shutdown");
123119
Ok(())
124120
}
125121
}
126122

127123
fn main() -> Result<()> {
128124
let mut scheduler = Scheduler::new();
129-
scheduler.add(Box::new(StateMachineNode::new()?), 0, Some(true));
125+
scheduler.add(StateMachineNode::new()?).order(0).done();
130126
scheduler.run()?;
131127
Ok(())
132128
}
@@ -177,8 +173,8 @@ impl EmergencyStopNode {
177173
impl Node for EmergencyStopNode {
178174
fn name(&self) -> &'static str { "EmergencyStop" }
179175

180-
fn init(&mut self, ctx: &mut NodeInfo) -> Result<()> {
181-
ctx.log_info(" Emergency stop system online - CRITICAL priority");
176+
fn init(&mut self) -> Result<()> {
177+
hlog!(info, " Emergency stop system online - CRITICAL priority");
182178
Ok(())
183179
}
184180

@@ -189,25 +185,17 @@ impl Node for EmergencyStopNode {
189185
if let Some(battery) = self.battery_sub.recv() {
190186
if battery.is_critical() { // Below 10%
191187
should_stop = true;
192-
if let Some(ref mut c) = ctx {
193-
c.log_error(&format!(
194-
" CRITICAL: Battery at {:.0}% - EMERGENCY STOP!",
195-
battery.percentage
196-
));
197-
}
188+
hlog!(error, " CRITICAL: Battery at {:.0}% - EMERGENCY STOP!",
189+
battery.percentage);
198190
}
199191
}
200192

201193
// Check obstacle distance
202194
if let Some(min_dist) = self.lidar_sub.recv() {
203195
if min_dist < 0.2 { // 20cm
204196
should_stop = true;
205-
if let Some(ref mut c) = ctx {
206-
c.log_error(&format!(
207-
" CRITICAL: Obstacle at {:.2}m - EMERGENCY STOP!",
208-
min_dist
209-
));
210-
}
197+
hlog!(error, " CRITICAL: Obstacle at {:.2}m - EMERGENCY STOP!",
198+
min_dist);
211199
}
212200
}
213201

@@ -218,10 +206,10 @@ impl Node for EmergencyStopNode {
218206
}
219207
}
220208

221-
fn shutdown(&mut self, ctx: &mut NodeInfo) -> Result<()> {
209+
fn shutdown(&mut self) -> Result<()> {
222210
// Always activate estop on shutdown
223-
self.estop_pub.send(true, &mut None).ok();
224-
ctx.log_warning("Emergency stop system offline");
211+
self.estop_pub.send(true).ok();
212+
hlog!(warn, "Emergency stop system offline");
225213
Ok(())
226214
}
227215
}
@@ -248,8 +236,8 @@ impl MotorController {
248236
impl Node for MotorController {
249237
fn name(&self) -> &'static str { "MotorController" }
250238

251-
fn init(&mut self, ctx: &mut NodeInfo) -> Result<()> {
252-
ctx.log_info("Motor controller online - HIGH priority");
239+
fn init(&mut self) -> Result<()> {
240+
hlog!(info, "Motor controller online - HIGH priority");
253241
Ok(())
254242
}
255243

@@ -258,12 +246,10 @@ impl Node for MotorController {
258246
if let Some(estop) = self.estop_sub.recv() {
259247
if estop != self.estop_active {
260248
self.estop_active = estop;
261-
if let Some(ctx) = ctx {
262-
if estop {
263-
ctx.log_warning("Motors DISABLED - emergency stop active");
264-
} else {
265-
ctx.log_info("Motors ENABLED - emergency stop cleared");
266-
}
249+
if estop {
250+
hlog!(warn, "Motors DISABLED - emergency stop active");
251+
} else {
252+
hlog!(info, "Motors ENABLED - emergency stop cleared");
267253
}
268254
}
269255
}
@@ -277,20 +263,15 @@ impl Node for MotorController {
277263
// Process normal commands
278264
if let Some(cmd) = self.cmd_sub.recv() {
279265
self.motor_pub.send(cmd).ok();
280-
281-
if let Some(ref mut c) = ctx {
282-
c.log_debug(&format!(
283-
"Motors: linear={:.2}, angular={:.2}",
284-
cmd.linear, cmd.angular
285-
));
286-
}
266+
hlog!(debug, "Motors: linear={:.2}, angular={:.2}",
267+
cmd.linear, cmd.angular);
287268
}
288269
}
289270

290-
fn shutdown(&mut self, ctx: &mut NodeInfo) -> Result<()> {
271+
fn shutdown(&mut self) -> Result<()> {
291272
// Stop motors
292-
self.motor_pub.send(CmdVel::zero(), &mut None).ok();
293-
ctx.log_info("Motor controller stopped");
273+
self.motor_pub.send(CmdVel::zero()).ok();
274+
hlog!(info, "Motor controller stopped");
294275
Ok(())
295276
}
296277
}
@@ -313,52 +294,44 @@ impl LoggerNode {
313294
impl Node for LoggerNode {
314295
fn name(&self) -> &'static str { "Logger" }
315296

316-
fn init(&mut self, ctx: &mut NodeInfo) -> Result<()> {
317-
ctx.log_info(" Logger online - BACKGROUND priority");
297+
fn init(&mut self) -> Result<()> {
298+
hlog!(info, " Logger online - BACKGROUND priority");
318299
Ok(())
319300
}
320301

321302
fn tick(&mut self) {
322303
// Log velocity commands
323304
if let Some(cmd) = self.cmd_sub.recv() {
324-
if let Some(ref mut c) = ctx {
325-
c.log_debug(&format!(
326-
"LOG: cmd_vel({:.2}, {:.2})",
327-
cmd.linear, cmd.angular
328-
));
329-
}
305+
hlog!(debug, "LOG: cmd_vel({:.2}, {:.2})",
306+
cmd.linear, cmd.angular);
330307
}
331308

332309
// Log battery state
333310
if let Some(battery) = self.battery_sub.recv() {
334-
if let Some(ref mut c) = ctx {
335-
c.log_debug(&format!(
336-
"LOG: battery({:.1}V, {:.0}%)",
337-
battery.voltage, battery.percentage
338-
));
339-
}
311+
hlog!(debug, "LOG: battery({:.1}V, {:.0}%)",
312+
battery.voltage, battery.percentage);
340313
}
341314

342315
// In production: write to file, database, etc.
343316
}
344317

345-
fn shutdown(&mut self, ctx: &mut NodeInfo) -> Result<()> {
346-
ctx.log_info("Logger stopped");
318+
fn shutdown(&mut self) -> Result<()> {
319+
hlog!(info, "Logger stopped");
347320
Ok(())
348321
}
349322
}
350323

351324
fn main() -> Result<()> {
352325
let mut scheduler = Scheduler::new();
353326

354-
// PRIORITY 0 (Critical): Safety runs FIRST
355-
scheduler.add(Box::new(EmergencyStopNode::new()?), 0, Some(true));
327+
// Order 0 (Critical): Safety runs FIRST
328+
scheduler.add(EmergencyStopNode::new()?).order(0).done();
356329

357-
// PRIORITY 1 (High): Control runs SECOND
358-
scheduler.add(Box::new(MotorController::new()?), 1, Some(true));
330+
// Order 1 (High): Control runs SECOND
331+
scheduler.add(MotorController::new()?).order(1).done();
359332

360-
// PRIORITY 4 (Background): Logging runs LAST
361-
scheduler.add(Box::new(LoggerNode::new()?), 4, Some(true));
333+
// Order 4 (Background): Logging runs LAST
334+
scheduler.add(LoggerNode::new()?).order(4).done();
362335

363336
scheduler.run()?;
364337
Ok(())
@@ -552,8 +525,8 @@ impl TempSensor {
552525
impl Node for TempSensor {
553526
fn name(&self) -> &'static str { "RustTempSensor" }
554527

555-
fn init(&mut self, ctx: &mut NodeInfo) -> Result<()> {
556-
ctx.log_info("Rust sensor online - high performance mode");
528+
fn init(&mut self) -> Result<()> {
529+
hlog!(info, "Rust sensor online - high performance mode");
557530
Ok(())
558531
}
559532

@@ -562,22 +535,20 @@ impl Node for TempSensor {
562535
let temp = 20.0 + (self.counter.sin() * 5.0);
563536
self.temp_pub.send(temp).ok();
564537

565-
if let Some(ref mut c) = ctx {
566-
c.log_debug(&format!("Rust: {:.2}°C", temp));
567-
}
538+
hlog!(debug, "Rust: {:.2}°C", temp);
568539

569540
self.counter += 0.1;
570541
}
571542

572-
fn shutdown(&mut self, ctx: &mut NodeInfo) -> Result<()> {
573-
ctx.log_info("Rust sensor offline");
543+
fn shutdown(&mut self) -> Result<()> {
544+
hlog!(info, "Rust sensor offline");
574545
Ok(())
575546
}
576547
}
577548

578549
fn main() -> Result<()> {
579550
let mut scheduler = Scheduler::new();
580-
scheduler.add(Box::new(TempSensor::new()?), 0, Some(true));
551+
scheduler.add(TempSensor::new()?).order(0).done();
581552
scheduler.run()
582553
}
583554
```
@@ -628,24 +599,22 @@ impl Node for Actuator {
628599

629600
fn tick(&mut self) {
630601
if let Some(cmd) = self.cmd_sub.recv() {
631-
if let Some(ctx) = ctx {
632-
let action = if cmd > 0.5 { "COOLING" } else { "IDLE" };
633-
ctx.log_info(&format!("Actuator: {}", action));
634-
}
602+
let action = if cmd > 0.5 { "COOLING" } else { "IDLE" };
603+
hlog!(info, "Actuator: {}", action);
635604
}
636605
}
637606

638-
fn shutdown(&mut self, ctx: &mut NodeInfo) -> Result<()> {
639-
ctx.log_info("Actuator stopped");
607+
fn shutdown(&mut self) -> Result<()> {
608+
hlog!(info, "Actuator stopped");
640609
Ok(())
641610
}
642611
}
643612

644613
fn main() -> Result<()> {
645614
let mut scheduler = Scheduler::new();
646-
scheduler.add(Box::new(Actuator {
615+
scheduler.add(Actuator {
647616
cmd_sub: Topic::new("actuator_cmd")?,
648-
}), 0, Some(true));
617+
}).order(0).done();
649618
scheduler.run()
650619
}
651620
```

content/docs/advanced/blackbox.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ weight: 30
66

77
# BlackBox Flight Recorder
88

9+
<Callout type="info" title="Do I Need This?">
10+
11+
**For most users: Not initially.** BlackBox is for when you need to understand crashes and failures.
12+
13+
**When this page IS useful:**
14+
- Robot crashes and you need to know what led up to it
15+
- Running long-term deployments and need audit logs
16+
- Investigating intermittent failures
17+
- Compliance requirements for event logging
18+
19+
**Quick answer:** Add BlackBox once your robot runs well. It's like dashcam footage: unnecessary until something goes wrong.
20+
21+
</Callout>
22+
923
The BlackBox flight recorder provides continuous event logging in a circular buffer for post-mortem analysis. Like an aircraft flight recorder, it captures all significant events leading up to failures for debugging and incident investigation.
1024

1125
## Overview

content/docs/advanced/checkpoint.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ weight: 46
66

77
# Checkpoint System
88

9+
<Callout type="info" title="Do I Need This?">
10+
11+
**For most users: Not initially.** Checkpointing is for long-running systems that need recovery.
12+
13+
**When this page IS useful:**
14+
- Robot runs for hours/days and must recover from crashes
15+
- Training ML models and need to save progress
16+
- Complex state that's expensive to rebuild from scratch
17+
18+
**Quick answer:** If restarting your robot is quick and easy, skip this. Add checkpointing when downtime matters.
19+
20+
</Callout>
21+
922
The Checkpoint System provides periodic state snapshots that can be used to recover from crashes or rollback to known-good states. This is essential for long-running robotics applications that need fault tolerance.
1023

1124
## Overview

content/docs/advanced/circuit-breaker.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ weight: 32
66

77
# Circuit Breaker
88

9+
<Callout type="info" title="Do I Need This?">
10+
11+
**For most users: Not initially.** Circuit breakers add resilience but also complexity.
12+
13+
**When this page IS useful:**
14+
- A sensor or node occasionally fails/hangs
15+
- You need graceful degradation when hardware is unreliable
16+
- Building long-running systems that must stay up
17+
18+
**Quick answer:** Start without it. Add circuit breakers when you have specific reliability problems to solve.
19+
20+
</Callout>
21+
922
The circuit breaker pattern prevents cascading failures by temporarily disabling failing nodes. When a node fails repeatedly, the circuit "opens" to stop calling it, giving it time to recover.
1023

1124
## Overview

0 commit comments

Comments
 (0)