Roboshark / Mbed 2 deprecated IrSensorDistanceMessureFornt

Dependencies:   mbed

Fork of IrSensorDistanceMessure by Roboshark

Revision:
0:a49ea5211c34
Child:
1:8184ab7e4395
diff -r 000000000000 -r a49ea5211c34 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 06 10:31:08 2018 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+ 
+ //Distandce Messure IR Sensor
+ //Meas = f(s)
+ 
+AnalogIn analog_value(PC_3);
+AnalogIn analog_value2(PC_5);
+
+    const float PR1 = 3.4734*0.000000001;    //Koeffizienten
+    const float PR2 = -7.1846*0.000001;
+    const float  PR3 = 0.0055;
+    const float PR4 = -1.9304;
+    const float PR5 = 301.2428;
+    const float PL1 = 3.4734*0.000000001;
+    const float PL2 = -7.1846*0.000001;
+    const float PL3 = 0.0055;
+    const float  PL4 = -1.9304;
+    const float  PL5 = 301.2428;
+    float disL;
+    float disR;
+    int roundL;
+    int roundR;
+    
+int main() {
+    float measL;
+    float measR;
+    printf("\nDistance Test Sensoren Rechts und Links\n");
+    printf("misst die Distanz vom Wagenrad bis Objekt\n");
+    wait(1.5);
+    
+    while(1) {
+        measR = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+        measR = measR * 1000; // Change the value to be in the 0 to 1000 range
+        disR = PR1*pow(measR,4)+PR2*pow(measR,3)+PR3*pow(measR,2)+PR4*measR+PR5; //disR = f(measR)
+        roundR = disR*100;
+        disR = roundR/100.0-10.0;
+        
+        printf("Distanz R = %f\n", disR);
+      
+        
+        measL = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+        measL = measL * 1000; // Change the value to be in the 0 to 1000 range
+        disL = PL1*pow(measL,4)+PL2*pow(measL,3)+PL3*pow(measL,2)+PL4*measL+PL5; //disL = f(measL)
+        roundL = disL*100;
+        disL = roundL/100.0-10.0;
+        
+        printf("Distanz L = %f\n", disL);
+        
+        wait(0.7); // 1 s
+    }
+}