SRA codes

Dependencies:   BufferedSerial

Files at this revision

API Documentation at this revision

Comitter:
LuisRA
Date:
Thu Apr 11 13:15:55 2019 +0000
Parent:
0:2b691d200d6f
Commit message:
thread now samples every 2ms. Only saves 1 measurement now (the most recent)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
rplidar/RPlidar.cpp Show annotated file Show diff for this revision Revisions of this file
rplidar/rplidar.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 09 17:53:31 2019 +0000
+++ b/main.cpp	Thu Apr 11 13:15:55 2019 +0000
@@ -32,8 +32,9 @@
         // poll for measurements. Returns -1 if no new measurements are available. returns 0 if found one.
         if(lidar.pollSensorData(&data) == 0)
         {
+            //if(data.angle < 5.0 && data.angle > -5.0)
             pc.printf("%f\t%f\t%d\t%c\n", data.distance, data.angle, data.quality, data.startBit);
         }
-       wait(0.1); 
+       //wait(0.02); 
     }
 }
--- a/rplidar/RPlidar.cpp	Tue Apr 09 17:53:31 2019 +0000
+++ b/rplidar/RPlidar.cpp	Thu Apr 11 13:15:55 2019 +0000
@@ -52,10 +52,15 @@
     while(1)
     {   
     
+        mutex_measurements.lock();
         while (IS_OK(pollPoint()))
-        {              
+        {    
+            
+            currentMeasurement_fromThread = getCurrentPoint();
+            newMeasurement = 1;
+               
           
-            if(!mail_box.full())
+            /*if(!mail_box.full())
             {            
                 struct RPLidarMeasurement current = getCurrentPoint();
                 struct RPLidarMeasurement *mail = mail_box.alloc();
@@ -95,9 +100,10 @@
                 }
                 
 
-            }
+            }*/
         }
-        wait(0.02);
+        mutex_measurements.unlock();    
+        wait_us(2000);
     }   
 
     
@@ -109,7 +115,22 @@
 */
 int32_t RPLidar::pollSensorData(struct RPLidarMeasurement *_data)
 {
-    osEvent evt = mail_box.get();
+    
+    mutex_measurements.lock();
+    if(newMeasurement)
+    {
+        //currentMeasurement_fromThread = getCurrentPoint();
+        _data->distance = currentMeasurement_fromThread.distance;
+        _data->angle = currentMeasurement_fromThread.angle;
+        _data->quality = currentMeasurement_fromThread.quality;
+        _data->startBit = currentMeasurement_fromThread.startBit;
+        newMeasurement = 0;
+        mutex_measurements.unlock();    
+        return 0;
+    }
+    mutex_measurements.unlock();    
+    
+    /*osEvent evt = mail_box.get();
     if (evt.status == osEventMail) {
         
         struct RPLidarMeasurement *mail = (struct RPLidarMeasurement*)evt.value.p;
@@ -123,7 +144,7 @@
 
         
 
-    }
+    }*/
     
     return -1;
 }
--- a/rplidar/rplidar.h	Tue Apr 09 17:53:31 2019 +0000
+++ b/rplidar/rplidar.h	Thu Apr 11 13:15:55 2019 +0000
@@ -99,9 +99,13 @@
     
      //Thread *thread_p;
     Thread thread;
-    Mail<struct RPLidarMeasurement, 100> mail_box; //
+    //Mail<struct RPLidarMeasurement, 100> mail_box; //
+    Mutex mutex_measurements;
     bool useThread;
     
+    struct RPLidarMeasurement currentMeasurement_fromThread;
+    bool newMeasurement;
+    
     u_result pollPoint();
     //Serial *pc;
 protected: