quadrature-decoder

Crates.ioquadrature-decoder
lib.rsquadrature-decoder
version0.1.1
sourcesrc
created_at2024-05-20 22:03:05.279551
updated_at2024-06-05 08:00:17.365431
descriptionPure logic-level implementations of quadrature decoders with support for full-, half- an quad-stepping.
homepagehttps://github.com/regexident/quadrature
repositoryhttps://github.com/regexident/quadrature
max_upload_size
id1246220
size80,177
Vincent Esche (regexident)

documentation

https://docs.rs/quadrature

README

quadrature-decoder

Crates.io Crates.io Crates.io docs.rs

Pure logic-level implementations of quadrature decoders with support for full-, half- an quad-stepping.


Incremental Decoder

use quadrature_decoder::{FullStep, IncrementalDecoder};

let mut decoder: IncrementalDecoder<...> = Default::default();

// Update the decoder with pulse trains `a` and `b` and handle the result:
match decoder.update(a, b) {
    Ok(Some(change)) => println!("Change detected: {change:?}."),
    Ok(None) => println!("No change detected."),
    Err(error) => println!("Error detected: {error:?}."),
}

// Or, if you only care about correctly detected changes:
if let Some(change) = decoder.update(a, b).unwrap_or_default() {
    println!("Change detected: {change:?}.")
}

println!("Decoder is at counter: {:?}.", decoder.counter());

See the examples directory for a more comprehensive example.

Indexed Incremental Decoder

An indexed decoder resets its counter whenever a raising edge is detected on the z pulse train.

use quadrature_decoder::{IndexedIncrementalDecoder};

let mut decoder: IndexedIncrementalDecoder<...> = Default::default();

// Update the decoder with pulse trains `a`, `b` and `z` and handle the result:
match decoder.update(a, b, z) {
    Ok(Some(change)) => println!("Change detected: {change:?}."),
    Ok(None) => println!("No change detected."),
    Err(error) => println!("Error detected: {error:?}."),
}

// Or, if you only care about correctly detected changes:
if let Some(change) = decoder.update(a, b, z).unwrap_or_default() {
    println!("Change detected: {change:?}.")
}

println!("Decoder is at counter: {:?}.", decoder.counter());

See the examples directory for a more comprehensive example.

Decoding Strategies

Full-step Decoding

A full-step decoder is able to detect up to 1 change(s) per quadrature cycle.

use quadrature_decoder::{FullStep, IncrementalDecoder};

let mut decoder: IncrementalDecoder<FullStep> = Default::default();

Half-step Decoding

A full-step decoder is able to detect up to 2 change(s) per quadrature cycle.

use quadrature_decoder::{HalfStep, IncrementalDecoder};

let mut decoder: IncrementalDecoder<HalfStep> = Default::default();

Quad-step Decoding

A full-step decoder is able to detect up to 4 change(s) per quadrature cycle.

use quadrature_decoder::{QuadStep, IncrementalDecoder};

let mut decoder: IncrementalDecoder<QuadStep> = Default::default();

Documentation

Please refer to the documentation on docs.rs.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.

Commit count: 35

cargo fmt