Prototyp V2

Dependencies:   PM2_Libary

Branch:
lupo
Revision:
35:f02adb2c2b8a
Parent:
34:9f779e91168e
Child:
36:6116ce98080d
--- a/main.cpp	Sun Apr 10 19:40:59 2022 +0200
+++ b/main.cpp	Wed Apr 13 09:40:22 2022 +0200
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "PM2_Libary.h"
 #include <cstdint>
+#include "mapping.cpp"
 
 // logical variable main task
 bool do_execute_main_task = false;  // this variable will be toggled via the user button (blue button) to or not to execute the main task
@@ -97,38 +98,6 @@
     
     return 0;
 }
-//pow function is here so we dont have to use the math.h library
-//it takes 2 arguments the base can be any negative or positive floating point number the power has to be a hos to be an "integer" defined as a double
-double powerx(double base, double pow2){
-    double result = -1;
-    double power = pow2;
-    double basis = base;
-    result = 1;
-    //handling negative exponents
-    if(power<0){
-        for(double i=1; i<=(power*(-1.0)); i++) {
-            result *= basis;
-        }
-        result = 1.0/result;
-    }
-    //handling positive exponents
-    else{
-    for(double i=1; i<=power; i++){
-    result *= basis;}}
-
-    return result;
-    }
-
-double mapping(float adc_value_mV){
-    double distance = 0.0f; //distance in mm
-    double infY =360 , supY = 2360; //Window for sensor values
-    double voltage_mV = adc_value_mV;
-    double p1 = -1.127*powerx(10,-14), p2 = 8.881*powerx(10,-11), p3 = -2.76*powerx(10,-7), p4 = 0.0004262, p5 = -0.3363, p6 = 120.1 ; //faktoren für polynomkurve -> von matlab exportiert
-    if(voltage_mV > infY && voltage_mV < supY){
-        distance = p1*powerx(voltage_mV,5) + p2*powerx(voltage_mV,4) + p3*powerx(voltage_mV,3) + p4*powerx(voltage_mV,2) + p5*voltage_mV + p6;
-    }
-    return (distance);
-}
 
 
 int main(void)
@@ -144,8 +113,8 @@
 
          ir_distance_mV = 1.0e3f * ir_analog_in.read() * 3.3f;
         
-        // printf("test pow function 2 ^ 2 %lf\n",powerx(2,2));
-         //printf("test mapping function %f\n", mapping(ir_distance_mV));
+        printf("test pow function 2 ^ 2 %lf\n",powerx(2,2));
+        printf("test mapping function %f\n", mapping(ir_distance_mV));
 
          //printf("IR sensor (mV): %3.3f\n", ir_distance_mV);
         
@@ -166,7 +135,7 @@
              break;
         case 4: Drive(PositionBackOff);
             printf("Case 4: Position Right(rot): %3.3f;    Position Left (rot): %3.3f\n",
-           positionController_M_right.getRotation(),positionController_M_left.getRotation());
+            positionController_M_right.getRotation(),positionController_M_left.getRotation());
             //   ToNextFunction+=1;
             break;
         case 5: LiftUp(degArmStart);