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.
Fork of Micromouse by
IRSensor.cpp
- Committer:
- Helvis
- Date:
- 2018-04-20
- Revision:
- 3:076dd7ec7eb4
- Parent:
- 1:2b5f79285a3e
- Child:
- 10:84534846e1f1
File content as of revision 3:076dd7ec7eb4:
#include <cmath>
#include "IRSensor.h"
using namespace std;
IRSensor::IRSensor(AnalogIn& distance) :
distance(distance){}
IRSensor::~IRSensor() {}
float IRSensor::readL() {
//Links B2
float a1 = -4.474f*pow(10.0f,4.0f);
float a2 = 8.415f*pow(10.0f,4.0f);
float a3 = -6.279f*pow(10.0f,4.0f);
float a4 = 2.36f*pow(10.0f,4.0f);
float a5 = -4670.0f;
float a6 = 445.1f;
//float d2 = a1*pow(distance,5) + a2*pow(distance,4) + a3*pow(distance,3) + a4*pow(distance,2) + a5*distance + a6;
float d2 = 10.2817f*(1/(pow(distance,1.212121f)));
return d2;
}
float IRSensor::readR(){
//Rechts B1
float b1 = -1.079f*pow(10.0f,4.0f);
float b2 = 2.404f*pow(10.0f,4.0f);
float b3 = -2.179f*pow(10.0f,4.0f);
float b4 = 1.012f*pow(10.0f,4.0f);
float b5 = -2519.0f;
float b6 = 310.8f;
//float d1 = b1*pow(distance,5) + b2*pow(distance,4) + b3*pow(distance,3) + b4*pow(distance,2) + b5*distance + b6;
float d1 = 11.6037f*(1/(pow(distance,1.111111f)));
return d1;
}
float IRSensor::readC(){
//Vorne B4
double c1 = -2.352f*pow(10.0f,4.0f);
double c2 = 5.44f*pow(10.0f,4.0f);
double c3 = -4.955f*pow(10.0f,4.0f);
double c4 = 2.268f*pow(10.0f,4.0f);
double c5 = -5538.0f;
double c6 = 690.5f;
//double d4 = c1*pow(distance,5) + c2*pow(distance,4) + c3*pow(distance,3) + c4*pow(distance,2) + c5*distance + c6;
//float d4 = distance;
float d4 = 28.053f*(1.0f/distance);
return d4;
}
//float IRSensor::readB(){}
