Basic program for TF Mini LiDar

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
pmic
Date:
Fri Dec 06 10:15:35 2019 +0000
Parent:
4:d60840a04ddc
Commit message:
Small adjustment for testing. Now TFMini is parametrizised for Middle distnace mode.

Changed in this revision

TFmini.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TFmini.cpp	Thu Aug 15 12:54:11 2019 +0000
+++ b/TFmini.cpp	Fri Dec 06 10:15:35 2019 +0000
@@ -17,11 +17,11 @@
 }
 
 float TFmini::readDistance()  {
-    return dist;
+    return (float)dist;
 }
 
 float TFmini::readStrength()  {
-    return strength;
+    return (float)strength;
 }
 
 void TFmini::receive()
--- a/main.cpp	Thu Aug 15 12:54:11 2019 +0000
+++ b/main.cpp	Fri Dec 06 10:15:35 2019 +0000
@@ -8,19 +8,16 @@
 Serial pc(SERIAL_TX, SERIAL_RX);  // serial connection via USB - programmer
 InterruptIn Button(USER_BUTTON);  // User Button
 Ticker  LoopTimer;                // interrupt for control loop
-Timer t;                          // timer to analyse Button
 
 RawSerial uart(PC_10, PC_11);
 TFmini tfmini(uart);
 
-int16_t dist;            // actual distance measurements of LiDAR
-int16_t strength;
-int16_t distOld;         // actual distance measurements of LiDAR
-bool receiveComplete;
+float dist;              // actual distance measurements of LiDAR
+float strength;
 
 int   k;
 bool  doRun;
-float Ts = 0.010f;       // sample time of main loop, 50 Hz
+float Ts = 0.02f;        // sample time of main loop
 float dt;
 Timer twhile;            // timer for time measurement (usage in while(1), without timer attached)
 
@@ -33,15 +30,15 @@
 // -----------------------------------------------------------------------------
 int main()
 {
-    pc.baud(115200);                   // for serial comm.
+    pc.baud(2000000);                   // for serial comm.
     LoopTimer.attach(&updateLoop, Ts); // attach loop to timer interrupt
     Button.fall(&pressed);             // attach key pressed function
     Button.rise(&released);            // attach key pressed function
     k = 0;
-    doRun = true;
+    doRun = false;
     // pt1.reset(0.0f);
-    dist = 0;
-    strength = 0;
+    dist = 0.0f;
+    strength = 0.0f;
     dt = 0.0f;
     twhile.start();
 }
@@ -52,34 +49,25 @@
     float dt = twhile.read();
     twhile.reset();
     
-    k++;
     dist = tfmini();
     strength = tfmini.readStrength();
     if(doRun) {
-        pc.printf("%i %f %i %i \r\n", k, dt, dist, strength);
-        // pc.printf("%i %i %i \r\n", k, dist, strength);
-        receiveComplete = false;
+        pc.printf("%i %f %f %f \r\n", k, dt, dist, strength);
     }
+    k++;
 }
 
 // buttonhandling
 // -----------------------------------------------------------------------------
 // start timer as soon as button is pressed
-void pressed()
-{
-    t.start();
-}
+void pressed() {}
 
 // evaluating statemachine
 void released()
 {
     // toggle state over boolean
-    if(doRun) {
-        k = 0;
-    }
     doRun = !doRun;
-    t.stop();
-    t.reset();
+    k = 0;
 }