pub struct Watchdog { /* private fields */ }Expand description
A deadman timer: it expires unless fed often enough, catching a stalled controller or link.
Autonomy assumes a stream of fresh commands. If that stream stops, because the controller hung
or the radio dropped, the last command must not run forever. A watchdog counts the time since it
was last fed and reports expiry once that exceeds its timeout; the caller feeds it each time a
fresh command arrives. It accumulates a supplied dt rather than reading a clock, so it works
the same on a microcontroller with no wall time.
§Examples
use pamoja_kit::Watchdog;
let mut dog = Watchdog::new(0.5); // expire after 0.5 s of silence
dog.feed();
assert!(!dog.update(0.3)); // 0.3 s since feeding: still alive
assert!(dog.update(0.3)); // 0.6 s total: expired
dog.feed(); // a fresh command revives it
assert!(!dog.is_expired());Implementations§
Source§impl Watchdog
impl Watchdog
Sourcepub fn update(&mut self, dt: f32) -> bool
pub fn update(&mut self, dt: f32) -> bool
Advances the timer by dt and returns whether it has expired.
§Arguments
dt- the time since the previous update; its magnitude is used. One that is not a finite number means the time is unknown, and the watchdog expires until it is fed, since silence of unknown length is not safe to assume short.
§Returns
true if the watchdog is now expired.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Returns whether the watchdog is currently expired.
§Returns
true if the time since feeding exceeds the timeout.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Watchdog
impl RefUnwindSafe for Watchdog
impl Send for Watchdog
impl Sync for Watchdog
impl Unpin for Watchdog
impl UnsafeUnpin for Watchdog
impl UnwindSafe for Watchdog
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more