![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Prototyp V2
Dependencies: PM2_Libary
mapping.cpp@54:86a90ce4e412, 2022-04-20 (annotated)
- Committer:
- lupomic
- Date:
- Wed Apr 20 08:58:46 2022 +0200
- Revision:
- 54:86a90ce4e412
- Parent:
- 49:c2ebc11520f9
mapping new
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lupomic | 54:86a90ce4e412 | 1 | #include "math.h" |
lupomic | 49:c2ebc11520f9 | 2 | |
lupomic | 49:c2ebc11520f9 | 3 | double mapping(float adc_value_mV){ |
lupomic | 49:c2ebc11520f9 | 4 | double distance = 0.0f; //distance in mm |
lupomic | 49:c2ebc11520f9 | 5 | double infY =360 , supY = 2360; //Window for sensor values |
lupomic | 49:c2ebc11520f9 | 6 | double voltage_mV = adc_value_mV; |
lupomic | 54:86a90ce4e412 | 7 | double p1 = -1.127 * pow(10, -14), p2 = 8.881 * pow(10, -11), p3 = -2.76 * pow(10, -7), p4 = 0.0004262, p5 = -0.3363, p6 = 120.1 ; //faktoren für polynomkurve -> von matlab exportiert |
lupomic | 49:c2ebc11520f9 | 8 | if(voltage_mV > infY && voltage_mV < supY){ |
lupomic | 54:86a90ce4e412 | 9 | distance = p1 * pow(voltage_mV, 5) + p2 * pow(voltage_mV, 4) + p3 * pow(voltage_mV, 3) + p4 * pow(voltage_mV, 2) + p5 * voltage_mV + p6; |
lupomic | 49:c2ebc11520f9 | 10 | } |
lupomic | 49:c2ebc11520f9 | 11 | return (distance); |
lupomic | 49:c2ebc11520f9 | 12 | } |
lupomic | 54:86a90ce4e412 | 13 |