Cube_Mini_Solution

Dependencies:   mbed QEI MPU6050 BLE_API nRF51822 MCP4725 eMPL_MPU6050

Committer:
BoulusAJ
Date:
Fri May 29 15:40:58 2020 +0000
Revision:
18:3b1aa67e11ca
Parent:
0:8e87cdf07037
Version May 29, 2020

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BoulusAJ 0:8e87cdf07037 1 #include "LinearCharacteristics.h"
BoulusAJ 0:8e87cdf07037 2
BoulusAJ 0:8e87cdf07037 3 using namespace std;
BoulusAJ 0:8e87cdf07037 4
BoulusAJ 0:8e87cdf07037 5 LinearCharacteristics::LinearCharacteristics(float gain,float offset){ // standard lin characteristics
BoulusAJ 0:8e87cdf07037 6 this->gain = gain;
BoulusAJ 0:8e87cdf07037 7 this->offset = offset;
BoulusAJ 0:8e87cdf07037 8 this->ulim = 999999.0;
BoulusAJ 0:8e87cdf07037 9 this->llim = -999999.0;
BoulusAJ 0:8e87cdf07037 10 }
BoulusAJ 0:8e87cdf07037 11
BoulusAJ 0:8e87cdf07037 12 LinearCharacteristics::LinearCharacteristics(float xmin,float xmax, float ymin, float ymax){ // standard lin characteristics
BoulusAJ 0:8e87cdf07037 13 this->gain = (ymax - ymin)/(xmax - xmin);
BoulusAJ 0:8e87cdf07037 14 this->offset = xmax - ymax/this->gain;
BoulusAJ 0:8e87cdf07037 15 this->ulim = 999999.0;
BoulusAJ 0:8e87cdf07037 16 this->llim = -999999.0;
BoulusAJ 0:8e87cdf07037 17
BoulusAJ 0:8e87cdf07037 18 }
BoulusAJ 0:8e87cdf07037 19 LinearCharacteristics::LinearCharacteristics(float xmin,float xmax, float ymin, float ymax,float ll, float ul){ // standard lin characteristics
BoulusAJ 0:8e87cdf07037 20 this->gain = (ymax - ymin)/(xmax - xmin);
BoulusAJ 0:8e87cdf07037 21 this->offset = xmax - ymax/this->gain;
BoulusAJ 0:8e87cdf07037 22 this->llim = ll;
BoulusAJ 0:8e87cdf07037 23 this->ulim = ul;
BoulusAJ 0:8e87cdf07037 24
BoulusAJ 0:8e87cdf07037 25 }
BoulusAJ 0:8e87cdf07037 26
BoulusAJ 0:8e87cdf07037 27 LinearCharacteristics::~LinearCharacteristics() {}
BoulusAJ 0:8e87cdf07037 28
BoulusAJ 0:8e87cdf07037 29
BoulusAJ 0:8e87cdf07037 30 float LinearCharacteristics::evaluate(float x)
BoulusAJ 0:8e87cdf07037 31 {
BoulusAJ 0:8e87cdf07037 32 float dum = this->gain*(x - this->offset);
BoulusAJ 0:8e87cdf07037 33 if(dum > this->ulim)
BoulusAJ 0:8e87cdf07037 34 dum = this->ulim;
BoulusAJ 0:8e87cdf07037 35 if(dum < this->llim)
BoulusAJ 0:8e87cdf07037 36 dum = this->llim;
BoulusAJ 0:8e87cdf07037 37 return dum;
BoulusAJ 0:8e87cdf07037 38 }
BoulusAJ 0:8e87cdf07037 39
BoulusAJ 0:8e87cdf07037 40 void LinearCharacteristics::setup(float xmin,float xmax, float ymin, float ymax){ // standard lin characteristics
BoulusAJ 0:8e87cdf07037 41 this->gain = (ymax - ymin)/(xmax - xmin);
BoulusAJ 0:8e87cdf07037 42 this->offset = xmax - ymax/this->gain;
BoulusAJ 0:8e87cdf07037 43 this->ulim = 999999.0;
BoulusAJ 0:8e87cdf07037 44 this->llim = -999999.0;
BoulusAJ 0:8e87cdf07037 45 }
BoulusAJ 0:8e87cdf07037 46 void LinearCharacteristics::setup(float xmin,float xmax, float ymin, float ymax,float ll, float ul){ // standard lin characteristics
BoulusAJ 0:8e87cdf07037 47 this->gain = (ymax - ymin)/(xmax - xmin);
BoulusAJ 0:8e87cdf07037 48 this->offset = xmax - ymax/this->gain;
BoulusAJ 0:8e87cdf07037 49 this->llim = ll;
BoulusAJ 0:8e87cdf07037 50 this->ulim = ul;
BoulusAJ 0:8e87cdf07037 51 }
BoulusAJ 0:8e87cdf07037 52