![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
今までのジョイスティックの入力を段階分けしていた方式から、アナログ値をできる限りそのまま使用する方式に変更しました。
Fork of ControlMain2017 by
main.cpp@32:60af346703d3, 2017-03-23 (annotated)
- Committer:
- YusukeWakuta
- Date:
- Thu Mar 23 15:59:46 2017 +0000
- Revision:
- 32:60af346703d3
- Parent:
- 31:3a6be197e98f
- Child:
- 33:d54dacb7a0aa
3?25?TF?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YusukeWakuta | 13:79eb74eb86c4 | 1 | //中央 |
YusukeWakuta | 0:b1290ca6c4a2 | 2 | |
YusukeWakuta | 0:b1290ca6c4a2 | 3 | #include "mbed.h" |
tsumagari | 10:b7159feb11fd | 4 | #define WAIT_LOOP_TIME 0.001 |
tsumagari | 9:c32999b4d2f9 | 5 | #define YOKUTAN_DATAS_NUM 7 |
YusukeWakuta | 32:60af346703d3 | 6 | #define INPUT_DATAS_NUM 7 //ここは1倍とまでしかCANでは一度に送れないため、8以下。そして、翼端コードと数字を合わせる必要あり。 |
YusukeWakuta | 0:b1290ca6c4a2 | 7 | #define SEND_DATAS_CAN_ID 100 |
tsumagari | 8:dbc8c87dac78 | 8 | #define SEND_DATAS_TIME 0.5 |
tsumagari | 8:dbc8c87dac78 | 9 | #define THRESHOLD_OH_VALUE 0.14 |
YusukeWakuta | 15:c5ade23e5de4 | 10 | #define SAMPLE_INTERVAL 0.05 |
YusukeWakuta | 0:b1290ca6c4a2 | 11 | |
YusukeWakuta | 29:8bff47ab602d | 12 | #define PHASE_NUM 13 //奇数にしてください |
YusukeWakuta | 24:72f9cb6e9440 | 13 | #define SUM_UP_NUM 10.0 |
YusukeWakuta | 29:8bff47ab602d | 14 | #define PITCHPERROLL 1.5 |
YusukeWakuta | 19:6387e3f02b37 | 15 | /* |
YusukeWakuta | 19:6387e3f02b37 | 16 | roll入力とピッチ入力だとピッチの方が1.5倍効くように |
YusukeWakuta | 19:6387e3f02b37 | 17 | */ |
YusukeWakuta | 18:31722545ecf1 | 18 | |
tsumagari | 9:c32999b4d2f9 | 19 | //-----------------------------------(resetInterrupt def) |
tsumagari | 9:c32999b4d2f9 | 20 | extern "C" void mbed_reset(); |
YusukeWakuta | 13:79eb74eb86c4 | 21 | InterruptIn resetPin(p22); |
tsumagari | 9:c32999b4d2f9 | 22 | Timer resetTimeCount; |
YusukeWakuta | 15:c5ade23e5de4 | 23 | void resetInterrupt() |
YusukeWakuta | 15:c5ade23e5de4 | 24 | { |
YusukeWakuta | 15:c5ade23e5de4 | 25 | while(resetPin) { |
tsumagari | 9:c32999b4d2f9 | 26 | resetTimeCount.start(); |
tsumagari | 9:c32999b4d2f9 | 27 | if(resetTimeCount.read()>3) mbed_reset(); |
tsumagari | 9:c32999b4d2f9 | 28 | } |
tsumagari | 9:c32999b4d2f9 | 29 | resetTimeCount.reset(); |
tsumagari | 9:c32999b4d2f9 | 30 | } |
tsumagari | 9:c32999b4d2f9 | 31 | //------------------------------------------------------- |
tsumagari | 9:c32999b4d2f9 | 32 | |
taurin | 6:7484315ba88a | 33 | CAN can_R(p30,p29); |
taurin | 6:7484315ba88a | 34 | CAN can_L(p9,p10); |
YusukeWakuta | 14:ffe9460922cb | 35 | Serial toKeikiSerial(p28,p27); |
tsumagari | 7:59ddbe239835 | 36 | Serial pc(USBTX,USBRX); |
tsumagari | 10:b7159feb11fd | 37 | AnalogIn rollPin(p15); |
YusukeWakuta | 31:3a6be197e98f | 38 | AnalogIn pitchPin(p18); |
YusukeWakuta | 13:79eb74eb86c4 | 39 | DigitalIn drug_R(p14); |
YusukeWakuta | 31:3a6be197e98f | 40 | DigitalIn drug_L(p17); |
YusukeWakuta | 25:12408563540d | 41 | DigitalOut led1(LED1); |
YusukeWakuta | 25:12408563540d | 42 | DigitalOut led2(LED2); |
YusukeWakuta | 15:c5ade23e5de4 | 43 | DigitalOut led4(LED4); |
YusukeWakuta | 15:c5ade23e5de4 | 44 | DigitalOut led3(LED3); |
tsumagari | 9:c32999b4d2f9 | 45 | //Ticker sendDatasTicker; |
YusukeWakuta | 0:b1290ca6c4a2 | 46 | |
taurin | 4:4a13dd263a7b | 47 | char yokutanDatas_R[YOKUTAN_DATAS_NUM]; |
taurin | 4:4a13dd263a7b | 48 | char yokutanDatas_L[YOKUTAN_DATAS_NUM]; |
tsumagari | 10:b7159feb11fd | 49 | char inputDatas_R[INPUT_DATAS_NUM]; |
tsumagari | 10:b7159feb11fd | 50 | char inputDatas_L[INPUT_DATAS_NUM]; |
YusukeWakuta | 24:72f9cb6e9440 | 51 | |
YusukeWakuta | 25:12408563540d | 52 | float rollNeutral = 0.739; |
YusukeWakuta | 25:12408563540d | 53 | float rollUpperDiff = 0; |
YusukeWakuta | 25:12408563540d | 54 | float rollLowerDiff = 0; |
YusukeWakuta | 24:72f9cb6e9440 | 55 | |
YusukeWakuta | 25:12408563540d | 56 | float pitchNeutral = 0.468 ;//1って書いた方 |
YusukeWakuta | 25:12408563540d | 57 | float pitchUpperDiff = 0; |
YusukeWakuta | 25:12408563540d | 58 | float pitchLowerDiff = 0; |
YusukeWakuta | 24:72f9cb6e9440 | 59 | float neutralDiff; |
YusukeWakuta | 0:b1290ca6c4a2 | 60 | |
YusukeWakuta | 3:0e66ce2ab2fb | 61 | CANMessage recmsg_R; |
YusukeWakuta | 3:0e66ce2ab2fb | 62 | CANMessage recmsg_L; |
YusukeWakuta | 0:b1290ca6c4a2 | 63 | |
YusukeWakuta | 25:12408563540d | 64 | enum InputType { |
YusukeWakuta | 26:745735b0479d | 65 | enumRoll, |
YusukeWakuta | 26:745735b0479d | 66 | enumPitch |
YusukeWakuta | 25:12408563540d | 67 | }; |
YusukeWakuta | 25:12408563540d | 68 | |
YusukeWakuta | 24:72f9cb6e9440 | 69 | void setNeutral() |
YusukeWakuta | 24:72f9cb6e9440 | 70 | { |
YusukeWakuta | 24:72f9cb6e9440 | 71 | float rollSum; |
YusukeWakuta | 24:72f9cb6e9440 | 72 | float pitchSum; |
YusukeWakuta | 25:12408563540d | 73 | |
YusukeWakuta | 24:72f9cb6e9440 | 74 | for(int i = 0; i < SUM_UP_NUM; i++) { |
YusukeWakuta | 24:72f9cb6e9440 | 75 | rollSum += rollPin.read(); |
YusukeWakuta | 24:72f9cb6e9440 | 76 | pitchSum += pitchPin.read(); |
YusukeWakuta | 24:72f9cb6e9440 | 77 | } |
YusukeWakuta | 25:12408563540d | 78 | rollNeutral = rollSum / SUM_UP_NUM; |
YusukeWakuta | 25:12408563540d | 79 | pitchNeutral = pitchSum / SUM_UP_NUM; |
YusukeWakuta | 26:745735b0479d | 80 | |
YusukeWakuta | 26:745735b0479d | 81 | neutralDiff = pitchNeutral - rollNeutral; //ピッチの初期値の方がい小さいと仮定 |
YusukeWakuta | 26:745735b0479d | 82 | rollNeutral += neutralDiff; |
YusukeWakuta | 30:eb7b7af1070a | 83 | rollUpperDiff = 0; |
YusukeWakuta | 25:12408563540d | 84 | } |
YusukeWakuta | 25:12408563540d | 85 | |
YusukeWakuta | 25:12408563540d | 86 | void setMaxAndMin(InputType it,float value) |
YusukeWakuta | 25:12408563540d | 87 | { |
YusukeWakuta | 26:745735b0479d | 88 | if(it == enumPitch) { |
YusukeWakuta | 25:12408563540d | 89 | if(value >pitchNeutral + pitchUpperDiff) |
YusukeWakuta | 25:12408563540d | 90 | pitchUpperDiff = value - pitchNeutral; |
YusukeWakuta | 26:745735b0479d | 91 | else if(value < rollNeutral + pitchLowerDiff) |
YusukeWakuta | 26:745735b0479d | 92 | pitchLowerDiff = value - pitchNeutral; |
YusukeWakuta | 26:745735b0479d | 93 | return; |
YusukeWakuta | 26:745735b0479d | 94 | } else if(it == enumRoll) { |
YusukeWakuta | 25:12408563540d | 95 | if(value >rollNeutral + rollUpperDiff) |
YusukeWakuta | 25:12408563540d | 96 | rollUpperDiff = value - rollNeutral; |
YusukeWakuta | 26:745735b0479d | 97 | else if(value < rollNeutral + rollLowerDiff) |
YusukeWakuta | 26:745735b0479d | 98 | rollLowerDiff = value -rollNeutral ; |
YusukeWakuta | 26:745735b0479d | 99 | return; |
YusukeWakuta | 25:12408563540d | 100 | } |
YusukeWakuta | 24:72f9cb6e9440 | 101 | } |
YusukeWakuta | 24:72f9cb6e9440 | 102 | |
YusukeWakuta | 20:d4951f491642 | 103 | //ジョイスティックの中間値から上と下の幅を合わせます。値を取得するたびに呼び出してください。範囲は広い方に合わせる物とします |
YusukeWakuta | 26:745735b0479d | 104 | float MatchUpperAndLower(InputType it, float max,float min,float neutral,float value) |
YusukeWakuta | 18:31722545ecf1 | 105 | { |
YusukeWakuta | 20:d4951f491642 | 106 | float Upper = max- neutral; |
YusukeWakuta | 20:d4951f491642 | 107 | float Lower = neutral - min; |
YusukeWakuta | 25:12408563540d | 108 | |
YusukeWakuta | 26:745735b0479d | 109 | if(it == enumRoll) { |
YusukeWakuta | 25:12408563540d | 110 | if(Upper > Lower) { |
YusukeWakuta | 25:12408563540d | 111 | if(value < neutral) { |
YusukeWakuta | 32:60af346703d3 | 112 | value = neutral + ((value - neutral) * (Upper / Lower)); |
YusukeWakuta | 31:3a6be197e98f | 113 | rollLowerDiff = -rollUpperDiff; |
YusukeWakuta | 25:12408563540d | 114 | } |
YusukeWakuta | 25:12408563540d | 115 | } else { |
YusukeWakuta | 25:12408563540d | 116 | if(value > neutral) { |
YusukeWakuta | 25:12408563540d | 117 | value = neutral + ((value - neutral) * (Lower / Upper)); |
YusukeWakuta | 31:3a6be197e98f | 118 | rollUpperDiff = -rollLowerDiff; |
YusukeWakuta | 25:12408563540d | 119 | } |
YusukeWakuta | 20:d4951f491642 | 120 | } |
YusukeWakuta | 25:12408563540d | 121 | return value; |
YusukeWakuta | 26:745735b0479d | 122 | } else if(it == enumPitch) { |
YusukeWakuta | 25:12408563540d | 123 | if(Upper > Lower) { |
YusukeWakuta | 25:12408563540d | 124 | if(value < neutral) { |
YusukeWakuta | 32:60af346703d3 | 125 | value = neutral + ((value -neutral) * (Upper / Lower)); |
YusukeWakuta | 31:3a6be197e98f | 126 | pitchLowerDiff = -pitchUpperDiff; |
YusukeWakuta | 25:12408563540d | 127 | } |
YusukeWakuta | 25:12408563540d | 128 | } else { |
YusukeWakuta | 25:12408563540d | 129 | if(value > neutral) { |
YusukeWakuta | 25:12408563540d | 130 | value = neutral + ((value - neutral) * (Lower / Upper)); |
YusukeWakuta | 31:3a6be197e98f | 131 | pitchUpperDiff= -pitchLowerDiff; |
YusukeWakuta | 25:12408563540d | 132 | } |
YusukeWakuta | 20:d4951f491642 | 133 | } |
YusukeWakuta | 25:12408563540d | 134 | return value; |
YusukeWakuta | 27:1af92a603532 | 135 | } else return value; |
YusukeWakuta | 18:31722545ecf1 | 136 | } |
YusukeWakuta | 18:31722545ecf1 | 137 | |
YusukeWakuta | 21:9b1f5123f4a8 | 138 | //範囲外に値がない場合にエラーが発生するので範囲内に収める |
YusukeWakuta | 21:9b1f5123f4a8 | 139 | float Format2Range(float value,float max,float min) |
YusukeWakuta | 18:31722545ecf1 | 140 | { |
YusukeWakuta | 18:31722545ecf1 | 141 | float result; |
YusukeWakuta | 21:9b1f5123f4a8 | 142 | |
YusukeWakuta | 18:31722545ecf1 | 143 | if(value > max) |
YusukeWakuta | 18:31722545ecf1 | 144 | result= max; |
YusukeWakuta | 18:31722545ecf1 | 145 | else if(value < min) |
YusukeWakuta | 18:31722545ecf1 | 146 | result = min; |
YusukeWakuta | 18:31722545ecf1 | 147 | else |
YusukeWakuta | 18:31722545ecf1 | 148 | result = value; |
YusukeWakuta | 18:31722545ecf1 | 149 | return result; |
YusukeWakuta | 18:31722545ecf1 | 150 | } |
YusukeWakuta | 18:31722545ecf1 | 151 | |
YusukeWakuta | 21:9b1f5123f4a8 | 152 | //値をint型の段階に分ける |
YusukeWakuta | 18:31722545ecf1 | 153 | int PhaseFloat(float value,float max,float min) |
YusukeWakuta | 18:31722545ecf1 | 154 | { |
YusukeWakuta | 18:31722545ecf1 | 155 | float PhaseWidth = (max - min) / PHASE_NUM; |
YusukeWakuta | 18:31722545ecf1 | 156 | if(value< max&& value > min) { |
YusukeWakuta | 18:31722545ecf1 | 157 | for(int i = 1; i <= PHASE_NUM; i++) { |
YusukeWakuta | 18:31722545ecf1 | 158 | if(value < min + PhaseWidth * i&& value > min + PhaseWidth * (i - 1) ) |
YusukeWakuta | 18:31722545ecf1 | 159 | return i; |
YusukeWakuta | 18:31722545ecf1 | 160 | } |
YusukeWakuta | 18:31722545ecf1 | 161 | } else if(value <= min) |
YusukeWakuta | 27:1af92a603532 | 162 | return 1; |
YusukeWakuta | 18:31722545ecf1 | 163 | else if(value>=max) |
YusukeWakuta | 18:31722545ecf1 | 164 | return PHASE_NUM; |
YusukeWakuta | 18:31722545ecf1 | 165 | } |
YusukeWakuta | 18:31722545ecf1 | 166 | |
YusukeWakuta | 30:eb7b7af1070a | 167 | float SetRollPitchRacio(float pitch,float roll) |
YusukeWakuta | 30:eb7b7af1070a | 168 | { |
YusukeWakuta | 30:eb7b7af1070a | 169 | return (roll + pitch * PITCHPERROLL) / (1.0 + PITCHPERROLL); |
YusukeWakuta | 29:8bff47ab602d | 170 | } |
YusukeWakuta | 29:8bff47ab602d | 171 | |
YusukeWakuta | 15:c5ade23e5de4 | 172 | void InputControlValues() |
YusukeWakuta | 15:c5ade23e5de4 | 173 | { |
YusukeWakuta | 26:745735b0479d | 174 | setMaxAndMin(enumRoll, rollPin.read()); |
YusukeWakuta | 26:745735b0479d | 175 | setMaxAndMin(enumPitch, pitchPin.read()); |
YusukeWakuta | 26:745735b0479d | 176 | |
YusukeWakuta | 30:eb7b7af1070a | 177 | // pc.printf("rollN:%f rollMax:%f rollMin:%f pitchN:%f pitchMax:%f pitchUpper:%f pitchMin:%f pitchLo:%f raw:%f\r\n",rollNeutral,rollNeutral+rollUpperDiff,rollNeutral+rollLowerDiff,pitchNeutral,pitchNeutral+pitchUpperDiff,pitchUpperDiff,pitchNeutral+pitchLowerDiff,pitchLowerDiff,pitchPin.read()); |
YusukeWakuta | 32:60af346703d3 | 178 | float MatchedRoll = MatchUpperAndLower(enumRoll, rollNeutral + rollUpperDiff,rollNeutral + rollLowerDiff,rollNeutral,rollPin.read() + neutralDiff); |
YusukeWakuta | 26:745735b0479d | 179 | float MatchedPitch = MatchUpperAndLower(enumPitch, pitchNeutral + pitchUpperDiff,pitchNeutral + pitchLowerDiff,pitchNeutral,pitchPin.read()); |
YusukeWakuta | 32:60af346703d3 | 180 | //pc.printf("Rollmax:%f value:%f Min:%f" ,); |
YusukeWakuta | 32:60af346703d3 | 181 | float FormatedRoll_R = Format2Range(SetRollPitchRacio(MatchedPitch,MatchedRoll),SetRollPitchRacio(pitchNeutral + pitchUpperDiff,rollNeutral + rollUpperDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff,rollNeutral + rollLowerDiff)); |
YusukeWakuta | 29:8bff47ab602d | 182 | *(int *)inputDatas_R =PhaseFloat(FormatedRoll_R,SetRollPitchRacio(pitchNeutral + pitchUpperDiff,rollNeutral + rollUpperDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff,rollNeutral + rollLowerDiff)); |
YusukeWakuta | 24:72f9cb6e9440 | 183 | |
YusukeWakuta | 29:8bff47ab602d | 184 | float FormatedRoll_L = Format2Range(SetRollPitchRacio(MatchedPitch, - MatchedRoll),SetRollPitchRacio(pitchNeutral + pitchUpperDiff,-rollNeutral - rollLowerDiff),SetRollPitchRacio(pitchNeutral +pitchLowerDiff, - rollNeutral - rollUpperDiff)); |
YusukeWakuta | 27:1af92a603532 | 185 | //pc.printf("matched:%f max:%f min:%f\n\r",(MatchedPitch - MatchedRoll) / 2.0,(pitchNeutral +pitchLowerDiff - rollNeutral - rollUpperDiff) / 2.0,(pitchNeutral + pitchUpperDiff-rollNeutral - rollLowerDiff) / 2.0); |
YusukeWakuta | 29:8bff47ab602d | 186 | *(int *)inputDatas_L = PhaseFloat(FormatedRoll_L,SetRollPitchRacio(pitchNeutral + pitchUpperDiff ,- rollNeutral - rollLowerDiff),SetRollPitchRacio(pitchNeutral + pitchLowerDiff ,- rollNeutral - rollUpperDiff)); |
YusukeWakuta | 27:1af92a603532 | 187 | //pc.printf("Format:%f max:%f min:%f\n\r",FormatedRoll_L,(pitchNeutral + pitchUpperDiff - rollNeutral - rollLowerDiff) / 2.0,(pitchNeutral + pitchLowerDiff - rollNeutral - rollUpperDiff) / 2.0); |
YusukeWakuta | 28:056287cb001c | 188 | if(*(int *)inputDatas_R < 1) |
YusukeWakuta | 28:056287cb001c | 189 | *(int *)inputDatas_R = 1; |
YusukeWakuta | 28:056287cb001c | 190 | else if(*(int *)inputDatas_R > PHASE_NUM) |
YusukeWakuta | 28:056287cb001c | 191 | *(int *)inputDatas_R = PHASE_NUM; |
YusukeWakuta | 28:056287cb001c | 192 | if(*(int *)inputDatas_L < 1) |
YusukeWakuta | 28:056287cb001c | 193 | *(int *)inputDatas_L = 1 ; |
YusukeWakuta | 28:056287cb001c | 194 | else if(*(int *)inputDatas_L > PHASE_NUM) |
YusukeWakuta | 28:056287cb001c | 195 | *(int *)inputDatas_L =PHASE_NUM; |
YusukeWakuta | 16:336e8b102555 | 196 | |
YusukeWakuta | 32:60af346703d3 | 197 | pc.printf("DR :%d DL:%d input_R:%d input_L:%d\n\r",drug_R.read(),drug_L.read(),*(int *)inputDatas_R,*(int *)inputDatas_L); |
YusukeWakuta | 31:3a6be197e98f | 198 | inputDatas_R[sizeof(int)+ 2] = (char)drug_R; |
YusukeWakuta | 15:c5ade23e5de4 | 199 | led4 =! led4; |
YusukeWakuta | 26:745735b0479d | 200 | // pc.printf("%c",*(char *)inputDatas_R[4]); |
YusukeWakuta | 15:c5ade23e5de4 | 201 | //pc.printf("%c",(char)drug_R); |
YusukeWakuta | 31:3a6be197e98f | 202 | inputDatas_L[sizeof(int)+2] = (char)drug_L; |
YusukeWakuta | 31:3a6be197e98f | 203 | // pc.printf("eruron:%f drug:%f\n\r,",); |
YusukeWakuta | 0:b1290ca6c4a2 | 204 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 205 | |
YusukeWakuta | 15:c5ade23e5de4 | 206 | void SendDatas() |
YusukeWakuta | 15:c5ade23e5de4 | 207 | { |
tsumagari | 10:b7159feb11fd | 208 | can_R.write(CANMessage(SEND_DATAS_CAN_ID, inputDatas_R, INPUT_DATAS_NUM)); |
tsumagari | 10:b7159feb11fd | 209 | can_L.write(CANMessage(SEND_DATAS_CAN_ID, inputDatas_L, INPUT_DATAS_NUM)); |
tsumagari | 8:dbc8c87dac78 | 210 | toKeikiSerial.putc(';'); |
YusukeWakuta | 15:c5ade23e5de4 | 211 | for(int i = 0; i < YOKUTAN_DATAS_NUM; i++) { |
YusukeWakuta | 31:3a6be197e98f | 212 | |
YusukeWakuta | 0:b1290ca6c4a2 | 213 | toKeikiSerial.putc(yokutanDatas_R[i]); |
YusukeWakuta | 0:b1290ca6c4a2 | 214 | toKeikiSerial.putc(yokutanDatas_L[i]); |
YusukeWakuta | 0:b1290ca6c4a2 | 215 | } |
YusukeWakuta | 15:c5ade23e5de4 | 216 | for(int i = 0; i < INPUT_DATAS_NUM; i++) { |
taurin | 4:4a13dd263a7b | 217 | toKeikiSerial.putc(inputDatas_R[i]); |
taurin | 4:4a13dd263a7b | 218 | toKeikiSerial.putc(inputDatas_L[i]); |
taurin | 4:4a13dd263a7b | 219 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 220 | } |
tsumagari | 8:dbc8c87dac78 | 221 | |
YusukeWakuta | 15:c5ade23e5de4 | 222 | void init() |
YusukeWakuta | 15:c5ade23e5de4 | 223 | { |
tsumagari | 9:c32999b4d2f9 | 224 | //--------------------------------------(resetInterrupt init) |
tsumagari | 9:c32999b4d2f9 | 225 | resetPin.rise(resetInterrupt); |
tsumagari | 9:c32999b4d2f9 | 226 | resetPin.mode(PullDown); |
tsumagari | 9:c32999b4d2f9 | 227 | //----------------------------------------------------------- |
tsumagari | 9:c32999b4d2f9 | 228 | // sendDatasTicker.attach(SendDatas,SEND_DATAS_TIME); |
YusukeWakuta | 15:c5ade23e5de4 | 229 | for(int i = 0; i < INPUT_DATAS_NUM; i++) { |
taurin | 2:9dc7d5f1e910 | 230 | inputDatas_R[i] = 0; |
taurin | 2:9dc7d5f1e910 | 231 | inputDatas_L[i] = 0; |
taurin | 2:9dc7d5f1e910 | 232 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 233 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 234 | |
YusukeWakuta | 15:c5ade23e5de4 | 235 | void receiveDatas() |
YusukeWakuta | 15:c5ade23e5de4 | 236 | { |
YusukeWakuta | 15:c5ade23e5de4 | 237 | if(can_R.read(recmsg_R)) { |
YusukeWakuta | 15:c5ade23e5de4 | 238 | for(int i = 0; i < recmsg_R.len; i++) { |
YusukeWakuta | 0:b1290ca6c4a2 | 239 | yokutanDatas_R[i] = recmsg_R.data[i]; |
YusukeWakuta | 15:c5ade23e5de4 | 240 | // pc.printf("%c",yokutanDatas_R[i]); |
YusukeWakuta | 0:b1290ca6c4a2 | 241 | } |
YusukeWakuta | 25:12408563540d | 242 | led1 = !led1; |
YusukeWakuta | 0:b1290ca6c4a2 | 243 | } |
YusukeWakuta | 15:c5ade23e5de4 | 244 | if(can_L.read(recmsg_L)) { |
YusukeWakuta | 15:c5ade23e5de4 | 245 | for(int i = 0; i < recmsg_L.len; i++) { |
YusukeWakuta | 0:b1290ca6c4a2 | 246 | yokutanDatas_L[i] = recmsg_L.data[i]; |
YusukeWakuta | 15:c5ade23e5de4 | 247 | led3 = !led3; |
YusukeWakuta | 15:c5ade23e5de4 | 248 | // pc.printf("%c",yokutanDatas_L[i]); |
YusukeWakuta | 0:b1290ca6c4a2 | 249 | } |
YusukeWakuta | 25:12408563540d | 250 | led2 = !led2; |
YusukeWakuta | 0:b1290ca6c4a2 | 251 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 252 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 253 | |
YusukeWakuta | 15:c5ade23e5de4 | 254 | int main() |
YusukeWakuta | 15:c5ade23e5de4 | 255 | { |
YusukeWakuta | 0:b1290ca6c4a2 | 256 | init(); |
YusukeWakuta | 24:72f9cb6e9440 | 257 | setNeutral(); |
YusukeWakuta | 15:c5ade23e5de4 | 258 | while(1) { |
tsumagari | 8:dbc8c87dac78 | 259 | InputControlValues(); |
tsumagari | 10:b7159feb11fd | 260 | wait_us(5); |
YusukeWakuta | 0:b1290ca6c4a2 | 261 | receiveDatas(); |
tsumagari | 9:c32999b4d2f9 | 262 | SendDatas(); |
YusukeWakuta | 0:b1290ca6c4a2 | 263 | wait(WAIT_LOOP_TIME); |
YusukeWakuta | 0:b1290ca6c4a2 | 264 | } |
YusukeWakuta | 0:b1290ca6c4a2 | 265 | } |