Counter

Trait Counter 

Source
pub trait Counter {
    type Reader: CountReader;
    type Resolution;
    type Measure;

    // Required methods
    fn update_count_state(
        &mut self,
        count: <Self::Reader as CountReader>::RawData,
    ) -> Result<(), <Self::Reader as CountReader>::ReadErr>;
    fn read_count_state(&self) -> &<Self::Reader as CountReader>::RawData;
    fn try_update_count(
        &mut self,
    ) -> Result<(), <Self::Reader as CountReader>::ReadErr>;
    fn try_read_measure(
        &self,
    ) -> Result<Self::Measure, <Self::Reader as CountReader>::ReadErr>;
    fn measure_count_state(&self) -> Self::Measure;
    fn try_update_and_measure(
        &mut self,
        count: &<Self::Reader as CountReader>::RawData,
    ) -> Result<Self::Measure, <Self::Reader as CountReader>::ReadErr>;
    fn measure_count(
        count: &<Self::Reader as CountReader>::RawData,
    ) -> Self::Measure;

    // Provided method
    fn direct_measure(    ) -> Result<Self::Measure, <Self::Reader as CountReader>::ReadErr> { ... }
}
Expand description

Encapsulates the types and operations assosciated with a count-oriented driver.

Required Associated Types§

Source

type Reader: CountReader

Source

type Resolution

Encapsulates the magnitude of what is being measured for each count.

E.g.:

  • (typenum::U1, typenum::U10000) for a 10khz oscilator.
  • a 1024 PPR AB encoder has tau/4096 resolution, ~= 1/652 radians: (typenum::U1, typenum::U652)
Source

type Measure

Encapsulates what is being measured. Some possible measures:

  • Degrees
  • arc-seconds
  • Radians
  • Milliseconds
  • Meters

E.g.


// Basic, short-life 1khz resolution time-measure
struct MilliSeconds(u32);

// a 1024ppr encoder has log_2(1024 * 4) = 12 bits of information.
// Fixing the fractional measure to be 12 bits encapsulates this precision.
// A typical valve rarely makes a full rotation, so the smaller bit-count
// does not matter, and 16 bits is the smallest that can hold 12 fractional bits.
//
// We use Tau in its name, because we are thinking in terms of full-rotations,
// and `Tau` radians is one full rotation
struct ValveTau(discrete_count::re_exports::fixed::types::I6F12);

// Advanced manufacturing equipment might need rotary stages that need to track
// up to 2^16 rotations, with pricesion up to 2^-16 radians.
struct RotaryStageTau(discrete_count::re_exports::fixed::types::I16F16);

// Encapsulate 32-bit POSIX timestamps
struct Seconds(u32);

// Encapsulate 64-bit POSIX timestamps
struct BigSeconds(u64);

Required Methods§

Source

fn update_count_state( &mut self, count: <Self::Reader as CountReader>::RawData, ) -> Result<(), <Self::Reader as CountReader>::ReadErr>

Source

fn read_count_state(&self) -> &<Self::Reader as CountReader>::RawData

Source

fn try_update_count( &mut self, ) -> Result<(), <Self::Reader as CountReader>::ReadErr>

Updates the internal count state.

§Errors

If the internal count-read errors out, the implementation should return an error, and not update the count.

Source

fn try_read_measure( &self, ) -> Result<Self::Measure, <Self::Reader as CountReader>::ReadErr>

Reads the count, applying scale to read measure.

§Errors

If the internal count-read errors out, the implementation should return an error.

Source

fn measure_count_state(&self) -> Self::Measure

Source

fn try_update_and_measure( &mut self, count: &<Self::Reader as CountReader>::RawData, ) -> Result<Self::Measure, <Self::Reader as CountReader>::ReadErr>

Derive the magnitude being measured. E.g.

let stage_rotation = Count::measure(&stage, stage.try_read_measure()?);
let rotation_count = stage_rotation.int();
let rotation_angle = stage_rotation.frac();
Source

fn measure_count( count: &<Self::Reader as CountReader>::RawData, ) -> Self::Measure

Provided Methods§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§