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.
Dependencies: mbed
Fork of IrSensorDistanceMessure by
main.cpp@0:a49ea5211c34, 2018-05-06 (annotated)
- Committer:
- ahlervin
- Date:
- Sun May 06 10:31:08 2018 +0000
- Revision:
- 0:a49ea5211c34
- Child:
- 1:8184ab7e4395
Um das Polynom zu kontrolieren
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ahlervin | 0:a49ea5211c34 | 1 | #include "mbed.h" |
| ahlervin | 0:a49ea5211c34 | 2 | |
| ahlervin | 0:a49ea5211c34 | 3 | //Distandce Messure IR Sensor |
| ahlervin | 0:a49ea5211c34 | 4 | //Meas = f(s) |
| ahlervin | 0:a49ea5211c34 | 5 | |
| ahlervin | 0:a49ea5211c34 | 6 | AnalogIn analog_value(PC_3); |
| ahlervin | 0:a49ea5211c34 | 7 | AnalogIn analog_value2(PC_5); |
| ahlervin | 0:a49ea5211c34 | 8 | |
| ahlervin | 0:a49ea5211c34 | 9 | const float PR1 = 3.4734*0.000000001; //Koeffizienten |
| ahlervin | 0:a49ea5211c34 | 10 | const float PR2 = -7.1846*0.000001; |
| ahlervin | 0:a49ea5211c34 | 11 | const float PR3 = 0.0055; |
| ahlervin | 0:a49ea5211c34 | 12 | const float PR4 = -1.9304; |
| ahlervin | 0:a49ea5211c34 | 13 | const float PR5 = 301.2428; |
| ahlervin | 0:a49ea5211c34 | 14 | const float PL1 = 3.4734*0.000000001; |
| ahlervin | 0:a49ea5211c34 | 15 | const float PL2 = -7.1846*0.000001; |
| ahlervin | 0:a49ea5211c34 | 16 | const float PL3 = 0.0055; |
| ahlervin | 0:a49ea5211c34 | 17 | const float PL4 = -1.9304; |
| ahlervin | 0:a49ea5211c34 | 18 | const float PL5 = 301.2428; |
| ahlervin | 0:a49ea5211c34 | 19 | float disL; |
| ahlervin | 0:a49ea5211c34 | 20 | float disR; |
| ahlervin | 0:a49ea5211c34 | 21 | int roundL; |
| ahlervin | 0:a49ea5211c34 | 22 | int roundR; |
| ahlervin | 0:a49ea5211c34 | 23 | |
| ahlervin | 0:a49ea5211c34 | 24 | int main() { |
| ahlervin | 0:a49ea5211c34 | 25 | float measL; |
| ahlervin | 0:a49ea5211c34 | 26 | float measR; |
| ahlervin | 0:a49ea5211c34 | 27 | printf("\nDistance Test Sensoren Rechts und Links\n"); |
| ahlervin | 0:a49ea5211c34 | 28 | printf("misst die Distanz vom Wagenrad bis Objekt\n"); |
| ahlervin | 0:a49ea5211c34 | 29 | wait(1.5); |
| ahlervin | 0:a49ea5211c34 | 30 | |
| ahlervin | 0:a49ea5211c34 | 31 | while(1) { |
| ahlervin | 0:a49ea5211c34 | 32 | measR = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
| ahlervin | 0:a49ea5211c34 | 33 | measR = measR * 1000; // Change the value to be in the 0 to 1000 range |
| ahlervin | 0:a49ea5211c34 | 34 | disR = PR1*pow(measR,4)+PR2*pow(measR,3)+PR3*pow(measR,2)+PR4*measR+PR5; //disR = f(measR) |
| ahlervin | 0:a49ea5211c34 | 35 | roundR = disR*100; |
| ahlervin | 0:a49ea5211c34 | 36 | disR = roundR/100.0-10.0; |
| ahlervin | 0:a49ea5211c34 | 37 | |
| ahlervin | 0:a49ea5211c34 | 38 | printf("Distanz R = %f\n", disR); |
| ahlervin | 0:a49ea5211c34 | 39 | |
| ahlervin | 0:a49ea5211c34 | 40 | |
| ahlervin | 0:a49ea5211c34 | 41 | measL = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
| ahlervin | 0:a49ea5211c34 | 42 | measL = measL * 1000; // Change the value to be in the 0 to 1000 range |
| ahlervin | 0:a49ea5211c34 | 43 | disL = PL1*pow(measL,4)+PL2*pow(measL,3)+PL3*pow(measL,2)+PL4*measL+PL5; //disL = f(measL) |
| ahlervin | 0:a49ea5211c34 | 44 | roundL = disL*100; |
| ahlervin | 0:a49ea5211c34 | 45 | disL = roundL/100.0-10.0; |
| ahlervin | 0:a49ea5211c34 | 46 | |
| ahlervin | 0:a49ea5211c34 | 47 | printf("Distanz L = %f\n", disL); |
| ahlervin | 0:a49ea5211c34 | 48 | |
| ahlervin | 0:a49ea5211c34 | 49 | wait(0.7); // 1 s |
| ahlervin | 0:a49ea5211c34 | 50 | } |
| ahlervin | 0:a49ea5211c34 | 51 | } |
