Skip to main content

SafetyGate

Struct SafetyGate 

Source
pub struct SafetyGate { /* private fields */ }
Expand description

The single gate every motion command passes through, composing e-stop, watchdog, and limits.

This is the one call a control loop makes to drive safely: feed it the desired motion and the time step, and it returns what is actually safe to command. It stops hard (commands zero and forgets its motion history, so resuming eases from rest) whenever the e-stop is engaged or the watchdog has expired; otherwise it returns the desired motion bounded by the Limits. Call feed whenever a fresh command arrives to keep the watchdog satisfied.

§Examples

use pamoja_kit::{Limits, SafetyGate, Twist};

let limits = Limits::new(1.0, 2.0, 0.5, 4.0);
let mut gate = SafetyGate::new(limits, 0.2); // stop if unfed for 0.2 s

gate.feed();
let cmd = gate.command(Twist::planar(1.0, 0.0), 0.1);
assert!((cmd.vx - 0.05).abs() < 1e-6); // eased on, acceleration-limited

gate.engage_estop();
assert_eq!(gate.command(Twist::planar(1.0, 0.0), 0.1), Twist::zero());

Implementations§

Source§

impl SafetyGate

Source

pub fn new(limits: Limits, watchdog_timeout: f32) -> Self

Creates a gate from motion limits and a watchdog timeout.

§Arguments
  • limits - the speed and acceleration bounds for normal motion.
  • watchdog_timeout - the allowed silence before the gate stops the robot.
§Returns

The gate, cleared and freshly fed.

Source

pub fn feed(&mut self)

Feeds the watchdog; call this whenever a fresh command arrives.

Source

pub fn engage_estop(&mut self)

Engages the latching emergency stop.

Source

pub fn reset_estop(&mut self)

Clears the emergency stop.

Source

pub fn is_stopped(&self) -> bool

Returns whether the gate is currently forcing a stop.

§Returns

true if the e-stop is engaged or the watchdog has expired.

Source

pub fn command(&mut self, desired: Twist, dt: f32) -> Twist

Returns the safe command for a desired motion over a time step.

§Arguments
  • desired - the requested body motion.
  • dt - the time since the previous call.
§Returns

Twist::zero when stopped, otherwise the desired motion bounded by the limits.

Trait Implementations§

Source§

impl Clone for SafetyGate

Source§

fn clone(&self) -> SafetyGate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SafetyGate

Source§

impl Debug for SafetyGate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.