diff --git a/Cargo.lock b/Cargo.lock index 19583712666d8bbffb37bc57abac1a9ad6d0f950..0b7acd10c0c295b57848d1d3d304a8f4d4198469 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,10 +1,3 @@ -[[package]] -name = "Rorientation" -version = "0.1.0" -dependencies = [ - "image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "adler32" version = "1.0.2" @@ -213,6 +206,13 @@ dependencies = [ "rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rorientation" +version = "0.1.0" +dependencies = [ + "image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "scoped_threadpool" version = "0.1.8" diff --git a/Cargo.toml b/Cargo.toml index 1568cc112d81109a1bf3ca48797bac2f8f183043..c8e2825ea31f6672aee316d2e98b25afa0fd5d23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "Rorientation" +name = "rorientation" version = "0.1.0" authors = ["Robert Hedman <robert.hedman@mac.com>"] diff --git a/src/main.rs b/src/main.rs index c7a91fb34dfb8f2e265ac6b7389872a70fe25725..fe5e69dfc309c643faea8e2eec74ea26d56d130b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,22 @@ use std::thread; use std::sync::mpsc; +use std::time; + + +// should the map matrix be two dim array of const size, vecs of dynamic, or what? + const ROWS: usize = 50; const COLS: usize = 100; fn main() { - let map = [[0u32; ROWS]; COLS]; + let mut map = [[0u32; ROWS]; COLS]; + map[0][0] = 3; + + println!("{}, {}", map[0][0], map[0][1]); - let (requestLocationTX, requestLocationRX): (mpsc::Sender<bool>, mpsc::Receiver<bool>) = mpsc::channel(); - let (sendLocationTX, sendLocationRX): (mpsc::Sender<(i32, i32)>, mpsc::Receiver<(i32, i32)>) = mpsc::channel(); + let (request_location_tx, request_location_rx): (mpsc::Sender<bool>, mpsc::Receiver<bool>) = mpsc::channel(); + let (send_location_tx, send_location_rx): (mpsc::Sender<(i32, i32)>, mpsc::Receiver<(i32, i32)>) = mpsc::channel(); // location tracker let tracker = thread::spawn(move || { @@ -16,47 +24,60 @@ fn main() { let mut pos: (i32, i32) = (0,0); loop { // get encoder data from arduino + let mut t: i32 = 0; + for _ in 0..1000 { + t = t+1; + }; + for _ in 0..1000 { + t = t-1; + }; // update local variables // check if position is requested - match requestLocationRX.try_recv() { + match request_location_rx.try_recv() { Ok(msg) => { if msg == false { println!("tracker got stop signal."); break; }; - sendLocationTX.send(pos).unwrap(); + send_location_tx.send(pos).unwrap(); pos.0 += 1; }, - Err(e) => { + Err(_) => { //println!("Error: {}, on recieving side.", e); //thread::sleep_ms(100); + pos.1 += 1; }, }; }; + println!("tracker exiting with local pos: {:?}", pos); }); // mapper (gets lidar data, requests position and updates its map.) let mapper = thread::spawn(move || { println!("mapper started."); // create empty map - let mut pos: (i32, i32) = (0,0); + let mut pos: (i32, i32); //= (0,0); loop { // request position data - requestLocationTX.send(true).unwrap(); - pos = sendLocationRX.recv().unwrap(); - println!("mapper pos: {:?} ",pos); + request_location_tx.send(true).unwrap(); + pos = send_location_rx.recv().unwrap(); + if pos.0 % 1000 == 0 { + println!("mapper pos: {:?} ",pos); + }; + // request lidar data // update map - if pos.0 == 100 { + if pos.0 == 1000000 { println!("mapper done."); - requestLocationTX.send(false).unwrap(); + request_location_tx.send(false).unwrap(); break; } + //thread::sleep(time::Duration::new(0,50*1000000)); // from ms to ns };