|
| 1 | +use std::{error::Error, thread, time::Duration}; |
| 2 | + |
| 3 | +use rustypot::device::feetech_controller::FeetechFts3215Controller; |
| 4 | +fn main() -> Result<(), Box<dyn Error>> { |
| 5 | + let serialportname: String = "/dev/tty.usbmodem58FA0818161".to_string(); |
| 6 | + let baudrate: u32 = 1_000_000; |
| 7 | + let ids = vec![1, 2]; |
| 8 | + |
| 9 | + let serial_port = serialport::new(serialportname, baudrate) |
| 10 | + .timeout(Duration::from_millis(1000)) |
| 11 | + .open()?; |
| 12 | + println!("serial port opened"); |
| 13 | + |
| 14 | + let mut c = FeetechFts3215Controller::new() |
| 15 | + .with_protocol_v1() |
| 16 | + .with_serial_port(serial_port); |
| 17 | + |
| 18 | + let mut times: Vec<f64> = Vec::new(); |
| 19 | + let duration = Duration::new(5, 0); |
| 20 | + let start_overall = std::time::Instant::now(); |
| 21 | + |
| 22 | + while start_overall.elapsed() < duration { |
| 23 | + let start_time = std::time::Instant::now(); |
| 24 | + let x = c.read_present_position(&ids); |
| 25 | + let elapsed_time = start_time.elapsed(); |
| 26 | + |
| 27 | + println!("present pos: {:?}", x); |
| 28 | + let elapsed_secs = elapsed_time.as_secs_f64(); |
| 29 | + println!("Time taken to read position: {:?}", elapsed_secs); |
| 30 | + |
| 31 | + times.push(elapsed_secs); |
| 32 | + thread::sleep(Duration::from_millis(10)); |
| 33 | + } |
| 34 | + |
| 35 | + let mean = times.iter().sum::<f64>() / times.len() as f64; |
| 36 | + let std_dev = |
| 37 | + (times.iter().map(|&t| (t - mean).powf(2.0)).sum::<f64>() / times.len() as f64).sqrt(); |
| 38 | + |
| 39 | + println!("Mean time: {}", mean); |
| 40 | + println!("Standard deviation time: {}", std_dev); |
| 41 | + |
| 42 | + Ok(()) |
| 43 | +} |
0 commit comments