![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
今までのジョイスティックの入力を段階分けしていた方式から、アナログ値をできる限りそのまま使用する方式に変更しました。
Fork of ControlMain2017 by
Diff: main.cpp
- Branch:
- ?????
- Revision:
- 41:d2d123d7a6fa
- Parent:
- 37:7ce6e87b9c36
- Child:
- 42:6cc53727acc2
diff -r 7ce6e87b9c36 -r d2d123d7a6fa main.cpp --- a/main.cpp Fri Apr 21 10:47:11 2017 +0000 +++ b/main.cpp Sun Apr 23 15:12:59 2017 +0000 @@ -63,11 +63,6 @@ CANMessage recmsg_R; CANMessage recmsg_L; -enum InputType { - enumRoll, - enumPitch -}; - //void tickFusoku(void const * arg){ // while(1){ // fusokuControl = 1; @@ -77,108 +72,11 @@ // } //} -void setNeutral() -{ - float rollSum; - float pitchSum; - - for(int i = 0; i < SUM_UP_NUM; i++) { - rollSum += rollPin.read(); - pitchSum += pitchPin.read(); - } - rollNeutral = rollSum / SUM_UP_NUM; - pitchNeutral = pitchSum / SUM_UP_NUM; - - neutralDiff = pitchNeutral - rollNeutral; //ピッチの初期値の方がい小さいと仮定 - rollNeutral += neutralDiff; - rollUpperDiff = 0; -} -void setMaxAndMin(InputType it,float value) -{ - if(it == enumPitch) { - if(value >pitchNeutral + pitchUpperDiff) - pitchUpperDiff = value - pitchNeutral; - else if(value < rollNeutral + pitchLowerDiff) - pitchLowerDiff = value - pitchNeutral; - return; - } else if(it == enumRoll) { - if(value >rollNeutral + rollUpperDiff) - rollUpperDiff = value - rollNeutral; - else if(value < rollNeutral + rollLowerDiff) - rollLowerDiff = value -rollNeutral ; - return; - } -} -//ジョイスティックの中間値から上と下の幅を合わせます。値を取得するたびに呼び出してください。範囲は広い方に合わせる物とします -float MatchUpperAndLower(InputType it, float max,float min,float neutral,float value) -{ - float Upper = max- neutral; - float Lower = neutral - min; - if(it == enumRoll) { - if(Upper > Lower) { - if(value < neutral) { - value = neutral + ((value - neutral) * (Upper / Lower)); - rollLowerDiff = -rollUpperDiff; - } - } else { - if(value > neutral) { - value = neutral + ((value - neutral) * (Lower / Upper)); - rollUpperDiff = -rollLowerDiff; - } - } - return value; - } else if(it == enumPitch) { - if(Upper > Lower) { - if(value < neutral) { - value = neutral + ((value -neutral) * (Upper / Lower)); - pitchLowerDiff = -pitchUpperDiff; - } - } else { - if(value > neutral) { - value = neutral + ((value - neutral) * (Lower / Upper)); - pitchUpperDiff= -pitchLowerDiff; - } - } - return value; - } else return value; -} -//範囲外に値がない場合にエラーが発生するので範囲内に収める -float Format2Range(float value,float max,float min) -{ - float result; - if(value > max) - result= max; - else if(value < min) - result = min; - else - result = value; - return result; -} - -//値をint型の段階に分ける -int PhaseFloat(float value,float max,float min) -{ - float PhaseWidth = (max - min) / PHASE_NUM; - if(value< max&& value > min) { - for(int i = 1; i <= PHASE_NUM; 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; -} - -float SetRollPitchRacio(float pitch,float roll) -{ - return (roll + pitch * PITCHPERROLL) / (1.0 + PITCHPERROLL); -} void InputControlValues() {