Skip to content
Snippets Groups Projects

Relative encoder ticks

Merged Samuel Tardieu requested to merge relative-encoder-ticks into main
Files
2
@@ -2,6 +2,7 @@ use color_eyre::eyre::Context;
use std::{thread, time::Duration};
use tele0592::{Controller as _, Device as _};
#[allow(clippy::too_many_lines, deprecated)] // deprecated needed for c.get_encoder_ticks()
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let mut c = rppal::i2c::I2c::with_bus(8).with_context(|| "opening I²C bus")?;
@@ -70,6 +71,20 @@ fn main() -> color_eyre::Result<()> {
println!("- Check that the raw encoder ticks are not reset after being read");
assert_eq!(c.get_raw_encoder_ticks()?, (left, right));
println!("- Check that relative and absolute encoder values are synchronized");
let mut relative = c.new_relative()?;
c.set_motor_speed(-40, 40)?;
thread::sleep(Duration::from_millis(200));
c.standby()?;
thread::sleep(Duration::from_millis(1000)); // Let some time to stop
assert_eq!(
c.get_encoder_ticks()?,
c.get_relative_encoder_ticks(&mut relative)?
);
println!("- Check that relative encoder values are updated correctly");
assert_eq!(c.get_relative_encoder_ticks(&mut relative)?, (0, 0));
println!("- Check that PID coefficients can be set and read");
c.set_pid_coefficients(0.0, 0.0, 0.0)?;
assert_eq!(c.get_pid_coefficients()?, (0.0, 0.0, 0.0));
@@ -117,5 +132,6 @@ fn main() -> color_eyre::Result<()> {
thread::sleep(Duration::from_millis(1500)); // Let some time to stop
let (left, right) = c.get_encoder_ticks()?;
assert!(left > 0 && right < 0);
Ok(())
}
Loading