![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
2017年度の製作を開始します
Fork of Control_Main_Full_20160608 by
Diff: InputHandler/InputHandler.cpp
- Branch:
- ?????
- Revision:
- 49:87af91607b46
- Child:
- 51:8a579a19a4ff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/InputHandler/InputHandler.cpp Sun Jun 04 13:29:51 2017 +0000 @@ -0,0 +1,89 @@ +#include "InputHandler.h" +#include "mbed.h" + +InputCalc::InputCalc() +{ + rawNeu = 0.0; + rawMax = NORMMIN; + rawMin = NORMMAX; + + shiftedMax = 0.0; + shiftedMin = 0.0; + + NeushiftWidth = 0.0; + upperShiftRate = 0.0; + lowerShiftRate = 0.0; +} + +void InputCalc::setNeutral(float input) +{ + float sum = 0.0; + for (int i = 0; i < NEUTRAL_SUM_NUM ; i++) { + sum += input; + } + rawNeu = sum / NEUTRAL_SUM_NUM; +} + +void InputCalc::setMaxAndMin(double input) +{ + if (input > rawMax) + rawMax = input; + else if (input < rawMin) + rawMin = input; +} + +//入力値の中央値を0とし、その分最大値と最小値をシフトします +void InputCalc::shift2ZeroNeu() +{ + shiftedMax = rawMax - rawNeu; + shiftedMin = rawMin - rawNeu; +} + +//シフトした後の値を-1.0~1.0へと正規化するための比率を取得します +void InputCalc::GetNormRate() +{ + upperShiftRate = 1.0 / shiftedMax; + lowerShiftRate = -1.0 / shiftedMin; +} + +//値を-1.0~1.0へと正規化します +void InputCalc::NormValue(double *input) +{ + *input -= rawNeu; + if (*input > 0.0) + *input *= upperShiftRate; + else if (*input < 0.0) + *input *= lowerShiftRate; +} + +//初期値の分、入力値を0に寄せて、拡大します。 +void InputCalc::WidenNeutral(double *input) +{ + if (-NEUWIDTH < *input&& *input < NEUWIDTH) + *input = 0; + else if (*input < -NEUWIDTH) { + *input += NEUWIDTH; + *input *= WIDENRATE; + } else if (NEUWIDTH < *input) { + *input -= NEUWIDTH; + *input *= WIDENRATE; + } +} + +double InputCalc::CutInvalidInput(double input) +{ + if(input > NORMMAX) + input = NORMMAX; + else if(input < NORMMIN) + input = NORMMIN; +} + +double InputCalc::Processing(double input) +{ + setMaxAndMin(input); + shift2ZeroNeu(); + GetNormRate(); + NormValue(&input); + WidenNeutral(&input); + return CutInvalidInput(input); +} \ No newline at end of file