From d4efdb945572f3b29059be6e261dce5d8b8b07be Mon Sep 17 00:00:00 2001
From: Robert Hedman <robert.hedman@mac.com>
Date: Mon, 20 Nov 2017 20:09:14 +0100
Subject: [PATCH] Sync, before ip stuff

---
 Cargo.lock  | 14 +++++++-------
 Cargo.toml  |  2 +-
 src/main.rs | 45 +++++++++++++++++++++++++++++++++------------
 3 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 1958371..0b7acd1 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 1568cc1..c8e2825 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 c7a91fb..fe5e69d 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
         };
 
         
-- 
GitLab