Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:9e4b9c339ea2, committed 2019-04-11
- 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
diff -r 2b691d200d6f -r 9e4b9c339ea2 main.cpp
--- 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);
}
}
diff -r 2b691d200d6f -r 9e4b9c339ea2 rplidar/RPlidar.cpp
--- 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;
}
diff -r 2b691d200d6f -r 9e4b9c339ea2 rplidar/rplidar.h
--- 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: