Michael Ernst Peter / Mbed OS Test_GPS

Dependencies:   Eigen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LinearCharacteristics.cpp Source File

LinearCharacteristics.cpp

00001 #include "LinearCharacteristics.h"
00002 
00003 LinearCharacteristics::LinearCharacteristics(float gain, float offset)
00004 {
00005     setup(gain, offset);
00006 }
00007 
00008 LinearCharacteristics::LinearCharacteristics(float x0, float x1, float y0, float y1)
00009 {
00010     setup(x0, x1, y0, y1);
00011 }
00012 
00013 LinearCharacteristics::LinearCharacteristics(float x0, float x1, float y0, float y1, float yMin, float yMax)
00014 {
00015     setup(x0, x1, y0, y1, yMin, yMax);
00016 }
00017 
00018 LinearCharacteristics::~LinearCharacteristics() {}
00019 
00020 float LinearCharacteristics::evaluate(float x)
00021 {
00022     float y = this->gain*(x - this->offset);
00023     if(y > this->yMax)
00024         y = this->yMax;
00025     if(y < this->yMin)
00026         y = this->yMin;
00027     return y;
00028 }
00029 
00030 void LinearCharacteristics::setup(float gain, float offset)
00031 {
00032     this->gain = gain;
00033     this->offset = offset;
00034     this->yMin = -999999.0;
00035     this->yMax =  999999.0;
00036 }
00037 
00038 void LinearCharacteristics::setup(float x0, float x1, float y0, float y1)
00039 {
00040     this->gain = (y1 - y0)/(x1 - x0);
00041     this->offset = x1 - y1/this->gain;
00042     this->yMin = -999999.0;
00043     this->yMax =  999999.0;
00044 }
00045 
00046 void LinearCharacteristics::setup(float x0,float x1, float y0, float y1, float yMin, float yMax)
00047 {
00048     this->gain = (y1 - y0)/(x1 - x0);
00049     this->offset = x1 - y1/this->gain;
00050     this->yMin = yMin;
00051     this->yMax = yMax;
00052 }
00053 
00054 void LinearCharacteristics::correctExistingOffset(float y_offset)
00055 {
00056     if(gain > 0.0) this->offset = this->offset + 1.0/(this->gain)*y_offset;
00057 }
00058