Roboshark / Mbed 2 deprecated SensorsTest3

Dependencies:   mbed

Committer:
ahlervin
Date:
Fri Apr 20 09:16:34 2018 +0000
Revision:
1:3396e2b3a62b
Parent:
0:608fcd3255ca
Sensoren auslesen 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ahlervin 0:608fcd3255ca 1
ahlervin 0:608fcd3255ca 2 //Implementation IR Sensoren
ahlervin 0:608fcd3255ca 3 // V04.18
ahlervin 0:608fcd3255ca 4 // V. Ahlers
ahlervin 0:608fcd3255ca 5
ahlervin 0:608fcd3255ca 6 #include <cmath>
ahlervin 0:608fcd3255ca 7 #include "IRSensor.h"
ahlervin 0:608fcd3255ca 8
ahlervin 0:608fcd3255ca 9 using namespace std;
ahlervin 0:608fcd3255ca 10 const float IRSensor :: PR1 = 3.4734*0.000000001; //Koeffizienten
ahlervin 0:608fcd3255ca 11 const float IRSensor :: PR2 = -7.1846*0.000001;
ahlervin 0:608fcd3255ca 12 const float IRSensor :: PR3 = 0.0055;
ahlervin 0:608fcd3255ca 13 const float IRSensor :: PR4 = -1.9304;
ahlervin 0:608fcd3255ca 14 const float IRSensor :: PR5 = 301.2428;
ahlervin 0:608fcd3255ca 15 const float IRSensor :: PL1 = 3.4734*0.000000001;
ahlervin 0:608fcd3255ca 16 const float IRSensor :: PL2 = -7.1846*0.000001;
ahlervin 0:608fcd3255ca 17 const float IRSensor :: PL3 = 0.0055;
ahlervin 0:608fcd3255ca 18 const float IRSensor :: PL4 = -1.9304;
ahlervin 0:608fcd3255ca 19 const float IRSensor :: PL5 = 301.2428;
ahlervin 0:608fcd3255ca 20 const float IRSensor :: PF1 = 6.1767f*pow(10.0f,-10);
ahlervin 0:608fcd3255ca 21 const float IRSensor :: PF2 = -1.9975f*pow(10.0f,-6);
ahlervin 0:608fcd3255ca 22 const float IRSensor :: PF3 = 0.0024f;
ahlervin 0:608fcd3255ca 23 const float IRSensor :: PF4 = -1.3299f;
ahlervin 0:608fcd3255ca 24 const float IRSensor :: PF5 = 351.1557f;
ahlervin 0:608fcd3255ca 25
ahlervin 0:608fcd3255ca 26
ahlervin 0:608fcd3255ca 27
ahlervin 0:608fcd3255ca 28 // IR Sensor Right
ahlervin 1:3396e2b3a62b 29 IRSensor::IRSensor(AnalogIn& IrRight, AnalogIn& IrLeft, AnalogIn& IrFront) : IrRight(IrRight), IrLeft(IrLeft), IrFront(IrFront){}
ahlervin 0:608fcd3255ca 30
ahlervin 0:608fcd3255ca 31 IRSensor::~IRSensor(){}
ahlervin 0:608fcd3255ca 32
ahlervin 0:608fcd3255ca 33 float IRSensor::readR() {
ahlervin 0:608fcd3255ca 34
ahlervin 0:608fcd3255ca 35 measR = IrRight.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
ahlervin 0:608fcd3255ca 36 measR = measR * 1000; // Change the value to be in the 0 to 1000 range
ahlervin 0:608fcd3255ca 37 disR = PR1*pow(measR,4)+PR2*pow(measR,3)+PR3*pow(measR,2)+PR4*measR+PR5; //disR = f(measR)
ahlervin 0:608fcd3255ca 38
ahlervin 0:608fcd3255ca 39 return disR;
ahlervin 0:608fcd3255ca 40 }
ahlervin 0:608fcd3255ca 41
ahlervin 0:608fcd3255ca 42 float IRSensor::readL(){
ahlervin 0:608fcd3255ca 43
ahlervin 0:608fcd3255ca 44 measL = IrLeft.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
ahlervin 0:608fcd3255ca 45 measL = measL * 1000; // Change the value to be in the 0 to 1000 range
ahlervin 0:608fcd3255ca 46 disL = PL1*pow(measL,4)+PL2*pow(measL,3)+PL3*pow(measL,2)+PL4*measL+PL5; //disL = f(measL)
ahlervin 0:608fcd3255ca 47
ahlervin 0:608fcd3255ca 48 return disL;
ahlervin 0:608fcd3255ca 49 }
ahlervin 0:608fcd3255ca 50
ahlervin 0:608fcd3255ca 51 float IRSensor::readF(){
ahlervin 0:608fcd3255ca 52
ahlervin 0:608fcd3255ca 53 measF = IrFront.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
ahlervin 0:608fcd3255ca 54 measF = measF * 1000; // Change the value to be in the 0 to 1000 range
ahlervin 0:608fcd3255ca 55 disF = PF1*pow(measF,4)+PF2*pow(measF,3)+PF3*pow(measF,2)+PF4*measF+PF5; //disF = f(measF)
ahlervin 0:608fcd3255ca 56
ahlervin 0:608fcd3255ca 57 return disF;
ahlervin 0:608fcd3255ca 58 }