Skip to content
Snippets Groups Projects
Commit d4efdb94 authored by Robert Hedman's avatar Robert Hedman
Browse files

Sync, before ip stuff

parent d39b2d6e
No related branches found
No related tags found
No related merge requests found
[[package]]
name = "Rorientation"
version = "0.1.0"
dependencies = [
"image 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "adler32" name = "adler32"
version = "1.0.2" version = "1.0.2"
...@@ -213,6 +206,13 @@ dependencies = [ ...@@ -213,6 +206,13 @@ dependencies = [
"rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "scoped_threadpool" name = "scoped_threadpool"
version = "0.1.8" version = "0.1.8"
......
[package] [package]
name = "Rorientation" name = "rorientation"
version = "0.1.0" version = "0.1.0"
authors = ["Robert Hedman <robert.hedman@mac.com>"] authors = ["Robert Hedman <robert.hedman@mac.com>"]
......
use std::thread; use std::thread;
use std::sync::mpsc; 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 ROWS: usize = 50;
const COLS: usize = 100; const COLS: usize = 100;
fn main() { fn main() {
let map = [[0u32; ROWS]; COLS]; let mut map = [[0u32; ROWS]; COLS];
map[0][0] = 3;
let (requestLocationTX, requestLocationRX): (mpsc::Sender<bool>, mpsc::Receiver<bool>) = mpsc::channel(); println!("{}, {}", map[0][0], map[0][1]);
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 // location tracker
let tracker = thread::spawn(move || { let tracker = thread::spawn(move || {
...@@ -16,47 +24,60 @@ fn main() { ...@@ -16,47 +24,60 @@ fn main() {
let mut pos: (i32, i32) = (0,0); let mut pos: (i32, i32) = (0,0);
loop { loop {
// get encoder data from arduino // 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 // update local variables
// check if position is requested // check if position is requested
match requestLocationRX.try_recv() { match request_location_rx.try_recv() {
Ok(msg) => { Ok(msg) => {
if msg == false { if msg == false {
println!("tracker got stop signal."); println!("tracker got stop signal.");
break; break;
}; };
sendLocationTX.send(pos).unwrap(); send_location_tx.send(pos).unwrap();
pos.0 += 1; pos.0 += 1;
}, },
Err(e) => { Err(_) => {
//println!("Error: {}, on recieving side.", e); //println!("Error: {}, on recieving side.", e);
//thread::sleep_ms(100); //thread::sleep_ms(100);
pos.1 += 1;
}, },
}; };
}; };
println!("tracker exiting with local pos: {:?}", pos);
}); });
// mapper (gets lidar data, requests position and updates its map.) // mapper (gets lidar data, requests position and updates its map.)
let mapper = thread::spawn(move || { let mapper = thread::spawn(move || {
println!("mapper started."); println!("mapper started.");
// create empty map // create empty map
let mut pos: (i32, i32) = (0,0); let mut pos: (i32, i32); //= (0,0);
loop { loop {
// request position data // request position data
requestLocationTX.send(true).unwrap(); request_location_tx.send(true).unwrap();
pos = sendLocationRX.recv().unwrap(); pos = send_location_rx.recv().unwrap();
if pos.0 % 1000 == 0 {
println!("mapper pos: {:?} ",pos); println!("mapper pos: {:?} ",pos);
};
// request lidar data // request lidar data
// update map // update map
if pos.0 == 100 { if pos.0 == 1000000 {
println!("mapper done."); println!("mapper done.");
requestLocationTX.send(false).unwrap(); request_location_tx.send(false).unwrap();
break; break;
} }
//thread::sleep(time::Duration::new(0,50*1000000)); // from ms to ns
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment