Skip to main content

Quadrature

Struct Quadrature 

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

Decodes a quadrature (A/B) encoder into a running tick count.

An incremental encoder reports motion as two square waves a quarter-cycle apart; their order of change tells direction. Feeding successive A/B readings to update returns the per-step direction and accumulates a signed count, the foundation for wheel odometry. Pair it with a QuadratureScale to turn that count into metres.

§Examples

use pamoja_kit::Quadrature;

let mut enc = Quadrature::new();
// One full cycle forward: 00 -> 01 -> 11 -> 10 -> 00, one tick each.
for &(a, b) in &[(false, true), (true, true), (true, false), (false, false)] {
    assert_eq!(enc.update(a, b), 1);
}
assert_eq!(enc.count(), 4);

Implementations§

Source§

impl Quadrature

Source

pub fn new() -> Self

Creates a decoder assuming both channels start low.

§Returns

A decoder with a zero count.

Source

pub fn starting(a: bool, b: bool) -> Self

Creates a decoder seeded with the encoder’s current channel levels.

Seeding the initial state avoids a spurious first tick when the encoder does not happen to rest with both channels low.

§Arguments
  • a - the current A channel level.
  • b - the current B channel level.
§Returns

A decoder with a zero count and the given starting state.

Source

pub fn update(&mut self, a: bool, b: bool) -> i8

Feeds the latest channel levels and returns the tick delta.

§Arguments
  • a - the latest A channel level.
  • b - the latest B channel level.
§Returns

+1 or -1 for a step in either direction, or 0 for no change or an illegal jump.

Source

pub fn count(&self) -> i64

Returns the accumulated signed tick count.

§Returns

The running count.

Source

pub fn reset(&mut self)

Resets the count to zero, keeping the current channel state.

Trait Implementations§

Source§

impl Clone for Quadrature

Source§

fn clone(&self) -> Quadrature

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 Quadrature

Source§

impl Debug for Quadrature

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Quadrature

Source§

fn default() -> Quadrature

Returns the “default value” for a type. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.