sfbsg
Dependencies: mbed
LinearCharacteristics.cpp@0:8ab621116ccd, 2018-04-03 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 03 15:17:11 2018 +0000
- Revision:
- 0:8ab621116ccd
fg
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:8ab621116ccd | 1 | #include "LinearCharacteristics.h" |
borlanic | 0:8ab621116ccd | 2 | |
borlanic | 0:8ab621116ccd | 3 | using namespace std; |
borlanic | 0:8ab621116ccd | 4 | |
borlanic | 0:8ab621116ccd | 5 | LinearCharacteristics::LinearCharacteristics(float k, float offset, float min, float max) // standard lin characteristics |
borlanic | 0:8ab621116ccd | 6 | { |
borlanic | 0:8ab621116ccd | 7 | this -> k = k; |
borlanic | 0:8ab621116ccd | 8 | this -> offset = offset; |
borlanic | 0:8ab621116ccd | 9 | this -> min = min; |
borlanic | 0:8ab621116ccd | 10 | this -> max = max; |
borlanic | 0:8ab621116ccd | 11 | // ... |
borlanic | 0:8ab621116ccd | 12 | } |
borlanic | 0:8ab621116ccd | 13 | |
borlanic | 0:8ab621116ccd | 14 | LinearCharacteristics::~LinearCharacteristics(){} |
borlanic | 0:8ab621116ccd | 15 | |
borlanic | 0:8ab621116ccd | 16 | float LinearCharacteristics::trans(float input) |
borlanic | 0:8ab621116ccd | 17 | { |
borlanic | 0:8ab621116ccd | 18 | |
borlanic | 0:8ab621116ccd | 19 | output = k*input + offset; |
borlanic | 0:8ab621116ccd | 20 | |
borlanic | 0:8ab621116ccd | 21 | if(output >= max) { |
borlanic | 0:8ab621116ccd | 22 | output = max; |
borlanic | 0:8ab621116ccd | 23 | } |
borlanic | 0:8ab621116ccd | 24 | if(output <= min) { |
borlanic | 0:8ab621116ccd | 25 | output = min; |
borlanic | 0:8ab621116ccd | 26 | } |
borlanic | 0:8ab621116ccd | 27 | return output; |
borlanic | 0:8ab621116ccd | 28 | } |
borlanic | 0:8ab621116ccd | 29 |