diff --git a/src/main.rs b/src/main.rs index 845340a4349405197cedbde96bd5dd98eb46fab8..b5d6d463f63dd266d35eb725e77723a93cfba681 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,10 @@ use std::net::TcpListener; extern crate serial; use std::io; use std::time::Duration; -use std::io::prelude::*; +//use std::io::prelude::*; use serial::prelude::*; -use std::str; +//use std::str; // should the map matrix be two dim array of const size, vecs of dynamic, or what? @@ -34,7 +34,7 @@ fn main() { thread::sleep(time::Duration::new(1,0)); loop { match stream.read_exact(&mut message) { - Ok(msg) => {println!("server got: {} {}", message[0], message[1]); + Ok(_) => {println!("server got: {} {}", message[0], message[1]); let written_size = stream.write(&[69 as u8, 96 as u8]); println!("server wrote {:?} to stream.", written_size); }, @@ -59,25 +59,21 @@ fn main() { let tracker = thread::spawn(move || { println!("Tracker started."); - let mut serialBuf: [u8; 8] = [0; 8]; + let mut serial_buf: [u8; 8] = [0; 8]; let device = String::from("/dev/cu.usbmodem41"); let mut port = serial::open(&device).unwrap(); interact(&mut port).unwrap(); - let mut L: i32 = 0; - let mut R: i32 = 0; let mut pos: (i32, i32) = (0,0); loop { // get encoder data from arduino and update local variables - match port.read_exact(&mut serialBuf){ + match port.read_exact(&mut serial_buf){ Ok(_) => { - L = freq_to_distance( ( ((serialBuf[0] as u32) << 24) + ((serialBuf[1] as u32) << 16) + ((serialBuf[2] as u32) << 8) + (serialBuf[3] as u32) ) as i32); - R = freq_to_distance( ( ((serialBuf[4] as u32) << 24) + ((serialBuf[5] as u32) << 16) + ((serialBuf[6] as u32) << 8) + (serialBuf[7] as u32) ) as i32); - print!("L: {}, ", L); - println!("R: {}", R); - pos.0 += L; - pos.1 += R; + pos.0 = freq_to_distance( ( ((serial_buf[0] as u32) << 24) + ((serial_buf[1] as u32) << 16) + ((serial_buf[2] as u32) << 8) + (serial_buf[3] as u32) ) as i32); + pos.1 = freq_to_distance( ( ((serial_buf[4] as u32) << 24) + ((serial_buf[5] as u32) << 16) + ((serial_buf[6] as u32) << 8) + (serial_buf[7] as u32) ) as i32); + print!("L: {}, ", pos.0); + println!("R: {}", pos.1); }, Err(e) => { println!("Could not read all bytes: {:?}", e); @@ -116,7 +112,7 @@ fn main() { // set up connection to lidar let mut stream = TcpStream::connect("127.0.0.1:8080").unwrap(); - let mut lidarBuf: [u8; 2] = [0; 2]; + let mut lidar_buf: [u8; 2] = [0; 2]; // main loop for this thread loop { @@ -133,9 +129,9 @@ fn main() { let stream_write_response = stream.write(&[65 as u8, 66 as u8]); println!("mapper wrote {:?} to stream.", stream_write_response); - match stream.read_exact(&mut lidarBuf){ + match stream.read_exact(&mut lidar_buf){ Ok(_) => { - println!("mapper got {}, {}, from lidar.", lidarBuf[0], lidarBuf[1]); + println!("mapper got {}, {}, from lidar.", lidar_buf[0], lidar_buf[1]); }, Err(e) => { println!("Could not read all bytes: {:?}", e); @@ -169,7 +165,6 @@ fn main() { // pathfinder, takes a map and returns a list of nodes to aim for when driving // This will be a function for mapper to call. - // }