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]]
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"
......
[package]
name = "Rorientation"
name = "rorientation"
version = "0.1.0"
authors = ["Robert Hedman <robert.hedman@mac.com>"]
......
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;
let (requestLocationTX, requestLocationRX): (mpsc::Sender<bool>, mpsc::Receiver<bool>) = mpsc::channel();
let (sendLocationTX, sendLocationRX): (mpsc::Sender<(i32, i32)>, mpsc::Receiver<(i32, i32)>) = mpsc::channel();
println!("{}, {}", map[0][0], map[0][1]);
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();
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
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment