今までのジョイスティックの入力を段階分けしていた方式から、アナログ値をできる限りそのまま使用する方式に変更しました。

Dependencies:   mbed-rtos mbed

Fork of ControlMain2017 by albatross

Branch:
?????
Revision:
44:7b6f627a31da
Parent:
43:2d8bffac06cd
Child:
45:df3b45a8cecc
--- a/ValueProcessor.cpp	Fri Apr 28 10:21:00 2017 +0000
+++ b/ValueProcessor.cpp	Fri Apr 28 15:23:22 2017 +0000
@@ -15,6 +15,20 @@
     neutralDiff = 0;
 }
 
+//中央の値の幅を増やします
+int ValueProcess::WidenNeutral(int phased)
+{
+    int AddNeutral = ADDITIONALPHASE / 2;
+    int neutralPhase = (PHASE_NUM + 5)/2.0;
+    if(neutralPhase - AddNeutral<=phased && phased <= neutralPhase +AddNeutral)
+        phased += AddNeutral;
+    else if(phased < neutralPhase - AddNeutral)
+        phased += AddNeutral;
+    else if(neutralPhase +AddNeutral<phased)
+        phased -= AddNeutral;
+    return phased;
+}
+
 void ValueProcess::setMaxAndMin(InputType it,float value)
 {
     if(it == enumPitch) {
@@ -100,16 +114,17 @@
 //値をint型の段階に分ける
 int ValueProcess::PhaseFloat(float value,float max,float min)
 {
-    float PhaseWidth = (max - min) / PHASE_NUM;
+    int tempPhase = PHASE_NUM + ADDITIONALPHASE;          //ここで足す値は偶数
+    float PhaseWidth = (max - min) / tempPhase;
     if(value< max&& value > min) {
-        for(int i = 1; i <= PHASE_NUM; i++) {
+        for(int i = 1; i <= tempPhase; i++) {
             if(value < min + PhaseWidth * i&& value > min + PhaseWidth * (i - 1) )
                 return i;
         }
     } else  if(value <= min)
         return 1;
     else if(value>=max)
-        return PHASE_NUM;
+        return tempPhase;
 }
 
 float ValueProcess::SetRollPitchRacio(float pitch,float roll)
@@ -150,10 +165,12 @@
 
     float FormatedRoll_R = Format2Range(SetRollPitchRacio(MatchedPitch,MatchedRoll),SetRollPitchRacio(pitchNeutral + pitchUpperDiff,rollNeutral + rollUpperDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff,rollNeutral + rollLowerDiff));
 
-    *input_R =PhaseFloat(FormatedRoll_R,SetRollPitchRacio(pitchNeutral + pitchUpperDiff,rollNeutral + rollUpperDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff,rollNeutral + rollLowerDiff));
+    int phased_R =PhaseFloat(FormatedRoll_R,SetRollPitchRacio(pitchNeutral + pitchUpperDiff,rollNeutral + rollUpperDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff,rollNeutral + rollLowerDiff));
+    *input_R = WidenNeutral(phased_R);
+    float FormatedRoll_L = Format2Range(SetRollPitchRacio(MatchedPitch, - MatchedRoll),SetRollPitchRacio(pitchNeutral + pitchUpperDiff,-rollNeutral - rollLowerDiff),SetRollPitchRacio(pitchNeutral  +pitchLowerDiff, - rollNeutral - rollUpperDiff));
+    int phased_L = PhaseFloat(FormatedRoll_L,SetRollPitchRacio(pitchNeutral + pitchUpperDiff ,- rollNeutral - rollLowerDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff ,- rollNeutral - rollUpperDiff));
+    *input_L = WidenNeutral(phased_L);
 
-    float FormatedRoll_L = Format2Range(SetRollPitchRacio(MatchedPitch, - MatchedRoll),SetRollPitchRacio(pitchNeutral + pitchUpperDiff,-rollNeutral - rollLowerDiff),SetRollPitchRacio(pitchNeutral  +pitchLowerDiff, - rollNeutral - rollUpperDiff));
-    *input_L = PhaseFloat(FormatedRoll_L,SetRollPitchRacio(pitchNeutral + pitchUpperDiff ,- rollNeutral - rollLowerDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff ,- rollNeutral - rollUpperDiff));
     if(*input_R < 1)
         *input_R = 1;
     else if(*input_R > PHASE_NUM)