マザー 20151028 XBOX-XBEE
Dependencies: mbed
Fork of Nucleo_PS3_Jikken_XBOX by
main.cpp@11:1ca2498815c9, 2015-09-19 (annotated)
- Committer:
- nodoame
- Date:
- Sat Sep 19 02:11:33 2015 +0000
- Revision:
- 11:1ca2498815c9
- Parent:
- 9:489a085d1703
- Child:
- 12:6445a3c3d34c
20150919; ?????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nodoame | 0:dc587be179e9 | 1 | #include "mbed.h" |
nodoame | 0:dc587be179e9 | 2 | #include "math.h" |
nodoame | 0:dc587be179e9 | 3 | #define M_PI 3.1415926535897932384626433832795 |
nodoame | 0:dc587be179e9 | 4 | #define trigL 0 |
nodoame | 0:dc587be179e9 | 5 | #define trigR 1 |
nodoame | 0:dc587be179e9 | 6 | #define btL 2 |
nodoame | 0:dc587be179e9 | 7 | #define btR 3 |
nodoame | 0:dc587be179e9 | 8 | #define btTri 4 |
nodoame | 0:dc587be179e9 | 9 | #define btSph 5 |
nodoame | 0:dc587be179e9 | 10 | #define btCro 6 |
nodoame | 0:dc587be179e9 | 11 | #define btSqa 7 |
nodoame | 5:428b7ac86810 | 12 | #define presUp 0 |
nodoame | 5:428b7ac86810 | 13 | #define presRight 1 |
nodoame | 5:428b7ac86810 | 14 | #define presDown 2 |
nodoame | 5:428b7ac86810 | 15 | #define presLeft 3 |
nodoame | 4:bae4e2d103d4 | 16 | #define devideNum 32 |
nodoame | 4:bae4e2d103d4 | 17 | #define ED 132 |
nodoame | 6:5171a8245b57 | 18 | #define TD 144//208 |
nodoame | 5:428b7ac86810 | 19 | #define EL 134 |
nodoame | 5:428b7ac86810 | 20 | #define TL 200 |
nodoame | 6:5171a8245b57 | 21 | #define TNR 138//204 |
nodoame | 6:5171a8245b57 | 22 | #define TNL 135 |
nodoame | 11:1ca2498815c9 | 23 | #define debugFlag 1 |
nodoame | 11:1ca2498815c9 | 24 | #define stopCount 33 |
nodoame | 0:dc587be179e9 | 25 | |
nodoame | 0:dc587be179e9 | 26 | Serial pc(SERIAL_TX, SERIAL_RX); |
nodoame | 1:a3bfd422ea9e | 27 | //Serial Dev(D8,D2);//コントローラー |
nodoame | 3:c290afbacd1c | 28 | Serial Dev(PC_6,PA_12);//コントローラー |
nodoame | 1:a3bfd422ea9e | 29 | RawSerial Mechanum(D8,D2);//メカナム |
nodoame | 0:dc587be179e9 | 30 | I2C i2c(D14,D15);//sda,scl |
nodoame | 5:428b7ac86810 | 31 | //const int airAddr=0x20; |
nodoame | 0:dc587be179e9 | 32 | const int airAddr=0xA0; |
nodoame | 5:428b7ac86810 | 33 | const int valveAddr=0xC0; |
nodoame | 1:a3bfd422ea9e | 34 | BusOut dI2c(PC_0,PC_1,PC_2,PC_3);//i2cデバッグ |
nodoame | 0:dc587be179e9 | 35 | |
nodoame | 0:dc587be179e9 | 36 | int Bflag = 0; |
nodoame | 0:dc587be179e9 | 37 | DigitalOut myled(LED1);// ,test1(PB_7) ,test2(PA_15) ,test3(PC_13) ,test4(PC_12); |
nodoame | 4:bae4e2d103d4 | 38 | PwmOut Blue(D5),Green(D4),Red(D3); |
nodoame | 4:bae4e2d103d4 | 39 | //PwmOut kRed(A3),kBlue(A1),kGreen(A0); |
nodoame | 4:bae4e2d103d4 | 40 | PwmOut kRed(A3),kBlue(PA_15),kGreen(PB_7); |
nodoame | 5:428b7ac86810 | 41 | #define N 7 |
nodoame | 0:dc587be179e9 | 42 | char DATA[N]; |
nodoame | 0:dc587be179e9 | 43 | void rotate(double setAngle); |
nodoame | 0:dc587be179e9 | 44 | void speed(); |
nodoame | 11:1ca2498815c9 | 45 | int stopCounter=0; |
nodoame | 1:a3bfd422ea9e | 46 | |
nodoame | 5:428b7ac86810 | 47 | void num()//割り込まれたら7回受信 |
nodoame | 0:dc587be179e9 | 48 | { |
nodoame | 0:dc587be179e9 | 49 | if(Dev.getc()==114){ |
nodoame | 0:dc587be179e9 | 50 | //printf("ReceiveCommand\r\n"); |
nodoame | 0:dc587be179e9 | 51 | for(int i = 0 ;i<N ;i++ ) |
nodoame | 0:dc587be179e9 | 52 | { |
nodoame | 0:dc587be179e9 | 53 | DATA[i]=Dev.getc(); |
nodoame | 0:dc587be179e9 | 54 | } |
nodoame | 0:dc587be179e9 | 55 | } |
nodoame | 11:1ca2498815c9 | 56 | stopCounter=0; |
nodoame | 0:dc587be179e9 | 57 | } |
nodoame | 0:dc587be179e9 | 58 | |
nodoame | 0:dc587be179e9 | 59 | bool getBt(int num) |
nodoame | 0:dc587be179e9 | 60 | { |
nodoame | 0:dc587be179e9 | 61 | return (DATA[0]>>num)%2; |
nodoame | 0:dc587be179e9 | 62 | } |
nodoame | 0:dc587be179e9 | 63 | |
nodoame | 5:428b7ac86810 | 64 | bool getPress(int num) |
nodoame | 5:428b7ac86810 | 65 | { |
nodoame | 5:428b7ac86810 | 66 | return (DATA[6]>>num)%2; |
nodoame | 5:428b7ac86810 | 67 | } |
nodoame | 5:428b7ac86810 | 68 | |
nodoame | 0:dc587be179e9 | 69 | double pointToDeg(double y,double x,int threshold)//座標から角度を求める関数thresholdはしきい値 |
nodoame | 0:dc587be179e9 | 70 | { |
nodoame | 0:dc587be179e9 | 71 | if(abs((int)(y-128))<threshold) |
nodoame | 0:dc587be179e9 | 72 | y=128; |
nodoame | 0:dc587be179e9 | 73 | if(abs((int)(x-128))<threshold) |
nodoame | 0:dc587be179e9 | 74 | x=128; |
nodoame | 0:dc587be179e9 | 75 | return atan2(-(y-128),x-128)/M_PI*180;//y軸反転、/PI*180でRadからDeg変換 |
nodoame | 0:dc587be179e9 | 76 | } |
nodoame | 0:dc587be179e9 | 77 | |
nodoame | 0:dc587be179e9 | 78 | double devidePoint(double y,double x,int threshold,float devide) |
nodoame | 0:dc587be179e9 | 79 | { |
nodoame | 0:dc587be179e9 | 80 | double tempX,tempY,dev;//仮のX,Yと分けた角度 |
nodoame | 0:dc587be179e9 | 81 | tempX=(x-128);tempY=(y-128);//それぞれ-128 |
nodoame | 0:dc587be179e9 | 82 | if(abs((int)tempY)<threshold)//しきい値以下なら0にする |
nodoame | 0:dc587be179e9 | 83 | tempY=0; |
nodoame | 0:dc587be179e9 | 84 | if(abs((int)tempX)<threshold) |
nodoame | 0:dc587be179e9 | 85 | tempX=0; |
nodoame | 0:dc587be179e9 | 86 | if(tempX==0&&tempY==0) |
nodoame | 0:dc587be179e9 | 87 | dev=360; |
nodoame | 0:dc587be179e9 | 88 | //printf("X:%lfY:%lfDev:%lf\r\n",tempX,tempY,dev); |
nodoame | 0:dc587be179e9 | 89 | else |
nodoame | 0:dc587be179e9 | 90 | dev=atan2(tempX,-tempY)/M_PI*180;//軸を逆にして代入、Y軸反転 |
nodoame | 0:dc587be179e9 | 91 | return ((dev<0)?(dev+360):(dev))/devide;//分割 |
nodoame | 0:dc587be179e9 | 92 | } |
nodoame | 0:dc587be179e9 | 93 | |
nodoame | 4:bae4e2d103d4 | 94 | int valueForMechanum(int deg,int devide,bool triL,bool triR,bool btSpd) |
nodoame | 0:dc587be179e9 | 95 | { |
nodoame | 0:dc587be179e9 | 96 | bool stpFlag=false,spnFlag=false;//ストップフラグ、スピンフラグ |
nodoame | 0:dc587be179e9 | 97 | int val=0,i;//値、For用 |
nodoame | 0:dc587be179e9 | 98 | for(i=0;i<6;i++){ |
nodoame | 0:dc587be179e9 | 99 | switch(i){ |
nodoame | 0:dc587be179e9 | 100 | case 0: |
nodoame | 4:bae4e2d103d4 | 101 | if(deg!=devide||(triL||triR))//スピンかニュートラル以外なら |
nodoame | 0:dc587be179e9 | 102 | val=1; |
nodoame | 0:dc587be179e9 | 103 | else |
nodoame | 0:dc587be179e9 | 104 | stpFlag=true;//ストップ |
nodoame | 0:dc587be179e9 | 105 | break; |
nodoame | 0:dc587be179e9 | 106 | |
nodoame | 0:dc587be179e9 | 107 | case 1: |
nodoame | 0:dc587be179e9 | 108 | if(stpFlag) |
nodoame | 4:bae4e2d103d4 | 109 | val++; |
nodoame | 0:dc587be179e9 | 110 | else |
nodoame | 0:dc587be179e9 | 111 | val+=btSpd;//スピード |
nodoame | 0:dc587be179e9 | 112 | break; |
nodoame | 0:dc587be179e9 | 113 | |
nodoame | 0:dc587be179e9 | 114 | case 2: |
nodoame | 0:dc587be179e9 | 115 | if(triL||triR){//トリガーのどちらかがONなら |
nodoame | 0:dc587be179e9 | 116 | val++; |
nodoame | 0:dc587be179e9 | 117 | spnFlag=true;//スピンフラグON |
nodoame | 0:dc587be179e9 | 118 | } |
nodoame | 0:dc587be179e9 | 119 | break; |
nodoame | 0:dc587be179e9 | 120 | |
nodoame | 0:dc587be179e9 | 121 | case 5: |
nodoame | 4:bae4e2d103d4 | 122 | val=val<<2;//5bit目から7bit目へ |
nodoame | 0:dc587be179e9 | 123 | if(spnFlag)//トリガーのどちらかの値 |
nodoame | 0:dc587be179e9 | 124 | val+=(triL)?1:0; |
nodoame | 4:bae4e2d103d4 | 125 | else if(!stpFlag)//ジョイスティックの値 |
nodoame | 0:dc587be179e9 | 126 | val+=deg; |
nodoame | 0:dc587be179e9 | 127 | break; |
nodoame | 0:dc587be179e9 | 128 | } |
nodoame | 0:dc587be179e9 | 129 | if(i<5) |
nodoame | 0:dc587be179e9 | 130 | val=val<<1; |
nodoame | 0:dc587be179e9 | 131 | } |
nodoame | 0:dc587be179e9 | 132 | //printf("val:%ddeg:%dtrigL:%dtrigR:%dbtSp:%d\r\n",val,deg,triL,triR,btSpd); |
nodoame | 0:dc587be179e9 | 133 | return val; |
nodoame | 0:dc587be179e9 | 134 | } |
nodoame | 0:dc587be179e9 | 135 | |
nodoame | 0:dc587be179e9 | 136 | void detectPole() |
nodoame | 0:dc587be179e9 | 137 | { |
nodoame | 9:489a085d1703 | 138 | bool btFlag=false,scFlag=false; |
nodoame | 5:428b7ac86810 | 139 | int vector=TD; |
nodoame | 4:bae4e2d103d4 | 140 | Blue=0.0f;Green=0.0f,Red=0.8f; |
nodoame | 9:489a085d1703 | 141 | double deg=32; |
nodoame | 0:dc587be179e9 | 142 | while(true) |
nodoame | 0:dc587be179e9 | 143 | { |
nodoame | 4:bae4e2d103d4 | 144 | //スイッチが押された時 |
nodoame | 5:428b7ac86810 | 145 | if(((int)DATA[1]&12)==12&&!btFlag){ |
nodoame | 5:428b7ac86810 | 146 | wait(0.001f); |
nodoame | 5:428b7ac86810 | 147 | Mechanum.putc(64); |
nodoame | 4:bae4e2d103d4 | 148 | btFlag=true; |
nodoame | 4:bae4e2d103d4 | 149 | Blue=0.0f;Green=0.8f;Red=0; |
nodoame | 9:489a085d1703 | 150 | vector=64; |
nodoame | 4:bae4e2d103d4 | 151 | } |
nodoame | 11:1ca2498815c9 | 152 | |
nodoame | 11:1ca2498815c9 | 153 | //方向選択 |
nodoame | 9:489a085d1703 | 154 | else if((int)deg==devideNum) |
nodoame | 9:489a085d1703 | 155 | { |
nodoame | 9:489a085d1703 | 156 | deg=devidePoint((double)DATA[3],(double)DATA[2],15,360/devideNum); |
nodoame | 9:489a085d1703 | 157 | pc.printf("deg%lf\r\n",deg); |
nodoame | 9:489a085d1703 | 158 | if((int)deg!=devideNum){ |
nodoame | 9:489a085d1703 | 159 | vector=(deg<17)?(TNL):(TNR); |
nodoame | 9:489a085d1703 | 160 | pc.printf("vector%d\r\n",vector); |
nodoame | 9:489a085d1703 | 161 | scFlag=true; |
nodoame | 9:489a085d1703 | 162 | } |
nodoame | 9:489a085d1703 | 163 | } |
nodoame | 4:bae4e2d103d4 | 164 | //レーザーが反応した時 |
nodoame | 9:489a085d1703 | 165 | else if(!(int)(DATA[1]&0x02)&&btFlag&&scFlag/*!((int)DATA[1]&2==2)&&btFlag*/){ |
nodoame | 4:bae4e2d103d4 | 166 | vector=64; |
nodoame | 0:dc587be179e9 | 167 | break; |
nodoame | 0:dc587be179e9 | 168 | } |
nodoame | 4:bae4e2d103d4 | 169 | |
nodoame | 0:dc587be179e9 | 170 | Mechanum.putc(vector); |
nodoame | 0:dc587be179e9 | 171 | wait(0.001f); |
nodoame | 0:dc587be179e9 | 172 | } |
nodoame | 4:bae4e2d103d4 | 173 | btFlag=false; |
nodoame | 5:428b7ac86810 | 174 | Blue=0;Green=0;Red=0; |
nodoame | 0:dc587be179e9 | 175 | } |
nodoame | 0:dc587be179e9 | 176 | |
nodoame | 0:dc587be179e9 | 177 | |
nodoame | 5:428b7ac86810 | 178 | bool shotToDenziben(char reg, char data ,int size,int addr) |
nodoame | 0:dc587be179e9 | 179 | { |
nodoame | 5:428b7ac86810 | 180 | char REG[2] = {reg,size}; |
nodoame | 5:428b7ac86810 | 181 | char DATA[2]={data,0}; |
nodoame | 5:428b7ac86810 | 182 | bool A = i2c.write(addr,REG,2); |
nodoame | 5:428b7ac86810 | 183 | A|= i2c.write(addr,DATA,size); |
nodoame | 1:a3bfd422ea9e | 184 | return A; |
nodoame | 0:dc587be179e9 | 185 | } |
nodoame | 0:dc587be179e9 | 186 | |
nodoame | 5:428b7ac86810 | 187 | char getshot(char reg) |
nodoame | 5:428b7ac86810 | 188 | { |
nodoame | 5:428b7ac86810 | 189 | char input=0; |
nodoame | 5:428b7ac86810 | 190 | char DATA[2] = {reg,1}; |
nodoame | 5:428b7ac86810 | 191 | i2c.write(airAddr,DATA,2); |
nodoame | 5:428b7ac86810 | 192 | wait(0.005f); |
nodoame | 5:428b7ac86810 | 193 | i2c.read(airAddr,&input,1); |
nodoame | 5:428b7ac86810 | 194 | return input; |
nodoame | 5:428b7ac86810 | 195 | } |
nodoame | 5:428b7ac86810 | 196 | |
nodoame | 4:bae4e2d103d4 | 197 | int main() { |
nodoame | 0:dc587be179e9 | 198 | pc.baud(230400); |
nodoame | 0:dc587be179e9 | 199 | Dev.baud(921600); |
nodoame | 0:dc587be179e9 | 200 | Mechanum.baud(230400); |
nodoame | 5:428b7ac86810 | 201 | DigitalIn bt(USER_BUTTON); |
nodoame | 0:dc587be179e9 | 202 | Dev.attach(num,Serial::RxIrq);//受信割り込み設定 |
nodoame | 1:a3bfd422ea9e | 203 | Green=0;Blue=0;Red=0; |
nodoame | 3:c290afbacd1c | 204 | DigitalOut l(PB_2); |
nodoame | 3:c290afbacd1c | 205 | int sqf=0; |
nodoame | 0:dc587be179e9 | 206 | double deg; |
nodoame | 0:dc587be179e9 | 207 | int val; |
nodoame | 1:a3bfd422ea9e | 208 | i2c.frequency(400000); |
nodoame | 4:bae4e2d103d4 | 209 | Blue=0.8f;Green=0; |
nodoame | 4:bae4e2d103d4 | 210 | kGreen=0.8f; |
nodoame | 5:428b7ac86810 | 211 | bool obonFlag=false,pLeftF=false,pRightF=false,btCrF=false; |
nodoame | 0:dc587be179e9 | 212 | |
nodoame | 0:dc587be179e9 | 213 | while(true) |
nodoame | 5:428b7ac86810 | 214 | { |
nodoame | 4:bae4e2d103d4 | 215 | Blue=0.8f;Green=0;Red=0; |
nodoame | 5:428b7ac86810 | 216 | |
nodoame | 5:428b7ac86810 | 217 | //ポール検出モード |
nodoame | 0:dc587be179e9 | 218 | if(getBt(btTri)&&getBt(btSph)){ |
nodoame | 0:dc587be179e9 | 219 | detectPole(); |
nodoame | 0:dc587be179e9 | 220 | //printf("DetectMode\r\n"); |
nodoame | 0:dc587be179e9 | 221 | } |
nodoame | 3:c290afbacd1c | 222 | |
nodoame | 5:428b7ac86810 | 223 | //射出 |
nodoame | 5:428b7ac86810 | 224 | if(getBt(btL)&&obonFlag){ |
nodoame | 5:428b7ac86810 | 225 | kRed=shotToDenziben(0x02,39,1,airAddr); |
nodoame | 5:428b7ac86810 | 226 | wait(0.1f); |
nodoame | 5:428b7ac86810 | 227 | kRed=0; |
nodoame | 5:428b7ac86810 | 228 | } |
nodoame | 5:428b7ac86810 | 229 | |
nodoame | 5:428b7ac86810 | 230 | //射出 |
nodoame | 5:428b7ac86810 | 231 | if(getBt(btR)&&obonFlag){ |
nodoame | 5:428b7ac86810 | 232 | kRed=shotToDenziben(0x02,23,1,airAddr); |
nodoame | 5:428b7ac86810 | 233 | wait(0.1f); |
nodoame | 3:c290afbacd1c | 234 | //printf("shot:%d\r\n",i2cS=i2c.write(airAddr,cmd,2)); |
nodoame | 3:c290afbacd1c | 235 | //i2c.write(airAddr,cmd,2); |
nodoame | 4:bae4e2d103d4 | 236 | kRed=0; |
nodoame | 3:c290afbacd1c | 237 | } |
nodoame | 3:c290afbacd1c | 238 | |
nodoame | 5:428b7ac86810 | 239 | //射出 |
nodoame | 5:428b7ac86810 | 240 | if(getBt(btTri)&&obonFlag){ |
nodoame | 5:428b7ac86810 | 241 | kRed=shotToDenziben(0x02,15,1,airAddr); |
nodoame | 5:428b7ac86810 | 242 | wait(0.1f); |
nodoame | 4:bae4e2d103d4 | 243 | kRed=0; |
nodoame | 3:c290afbacd1c | 244 | } |
nodoame | 3:c290afbacd1c | 245 | |
nodoame | 5:428b7ac86810 | 246 | //バルブ開放 |
nodoame | 5:428b7ac86810 | 247 | if(getPress(presLeft)&&pLeftF){ |
nodoame | 5:428b7ac86810 | 248 | pLeftF=false; |
nodoame | 5:428b7ac86810 | 249 | kRed=shotToDenziben(7,1,1,valveAddr); |
nodoame | 5:428b7ac86810 | 250 | } |
nodoame | 5:428b7ac86810 | 251 | else if(!getPress(presLeft)) |
nodoame | 5:428b7ac86810 | 252 | pLeftF=true; |
nodoame | 5:428b7ac86810 | 253 | |
nodoame | 5:428b7ac86810 | 254 | //バルブ開放 |
nodoame | 5:428b7ac86810 | 255 | if(getPress(presRight)&&pRightF){ |
nodoame | 5:428b7ac86810 | 256 | pRightF=false; |
nodoame | 5:428b7ac86810 | 257 | kRed=shotToDenziben(8,1,1,valveAddr); |
nodoame | 0:dc587be179e9 | 258 | } |
nodoame | 5:428b7ac86810 | 259 | else if(!getPress(presRight)) |
nodoame | 5:428b7ac86810 | 260 | pRightF=true; |
nodoame | 0:dc587be179e9 | 261 | |
nodoame | 5:428b7ac86810 | 262 | //バルブ開放 |
nodoame | 5:428b7ac86810 | 263 | if(getBt(btCro)&&btCrF){ |
nodoame | 5:428b7ac86810 | 264 | btCrF=false; |
nodoame | 5:428b7ac86810 | 265 | kRed=shotToDenziben(9,1,1,valveAddr); |
nodoame | 5:428b7ac86810 | 266 | } |
nodoame | 5:428b7ac86810 | 267 | else if(!getBt(btCro)) |
nodoame | 5:428b7ac86810 | 268 | btCrF=true; |
nodoame | 5:428b7ac86810 | 269 | |
nodoame | 5:428b7ac86810 | 270 | |
nodoame | 5:428b7ac86810 | 271 | //レーザーポインタ |
nodoame | 3:c290afbacd1c | 272 | if(getBt(btSqa)&&sqf){ |
nodoame | 3:c290afbacd1c | 273 | sqf=0; |
nodoame | 3:c290afbacd1c | 274 | l=!l; |
nodoame | 4:bae4e2d103d4 | 275 | kBlue=!kBlue; |
nodoame | 0:dc587be179e9 | 276 | } |
nodoame | 3:c290afbacd1c | 277 | else if(!getBt(btSqa)) |
nodoame | 3:c290afbacd1c | 278 | sqf=1; |
nodoame | 3:c290afbacd1c | 279 | |
nodoame | 5:428b7ac86810 | 280 | //タッチセンサ |
nodoame | 4:bae4e2d103d4 | 281 | if(((int)DATA[1]&12)==12) |
nodoame | 4:bae4e2d103d4 | 282 | Blue=0.0f;Green=0.8f;Red=0; |
nodoame | 4:bae4e2d103d4 | 283 | |
nodoame | 5:428b7ac86810 | 284 | //お盆回し |
nodoame | 5:428b7ac86810 | 285 | if(getPress(presUp)){ |
nodoame | 5:428b7ac86810 | 286 | kRed=shotToDenziben(0x02,7,1,airAddr); |
nodoame | 5:428b7ac86810 | 287 | wait(0.1); |
nodoame | 5:428b7ac86810 | 288 | obonFlag=true; |
nodoame | 5:428b7ac86810 | 289 | kRed=0; |
nodoame | 5:428b7ac86810 | 290 | } |
nodoame | 5:428b7ac86810 | 291 | else if(getPress(presDown)){ |
nodoame | 5:428b7ac86810 | 292 | kRed=shotToDenziben(0x02,0,1,airAddr); |
nodoame | 5:428b7ac86810 | 293 | wait(0.1); |
nodoame | 5:428b7ac86810 | 294 | obonFlag=false; |
nodoame | 5:428b7ac86810 | 295 | kRed=0; |
nodoame | 5:428b7ac86810 | 296 | } |
nodoame | 5:428b7ac86810 | 297 | |
nodoame | 4:bae4e2d103d4 | 298 | deg=devidePoint((double)DATA[3],(double)DATA[2],15,360/devideNum); |
nodoame | 4:bae4e2d103d4 | 299 | val=valueForMechanum(deg,devideNum,getBt(trigL),getBt(trigR),getBt(btSph)); |
nodoame | 11:1ca2498815c9 | 300 | |
nodoame | 11:1ca2498815c9 | 301 | //一定時間通信してないと停止 |
nodoame | 11:1ca2498815c9 | 302 | if(stopCounter>stopCount) |
nodoame | 11:1ca2498815c9 | 303 | val=64; |
nodoame | 11:1ca2498815c9 | 304 | else |
nodoame | 11:1ca2498815c9 | 305 | stopCounter++; |
nodoame | 0:dc587be179e9 | 306 | Mechanum.putc(val); |
nodoame | 0:dc587be179e9 | 307 | wait(0.03f); |
nodoame | 11:1ca2498815c9 | 308 | do{ |
nodoame | 11:1ca2498815c9 | 309 | if(!debugFlag) |
nodoame | 11:1ca2498815c9 | 310 | break; |
nodoame | 11:1ca2498815c9 | 311 | pc.printf("val:%d\r\n",val); |
nodoame | 11:1ca2498815c9 | 312 | //printf("%lf:%d:%d\r\n",deg,(int)DATA[3],(int)DATA[2]); |
nodoame | 11:1ca2498815c9 | 313 | //printf("%d\r\n",(int)DATA[0]); |
nodoame | 11:1ca2498815c9 | 314 | //pc.printf("DATA[1]%d\r\n",(int)(DATA[1]&0x02)); |
nodoame | 11:1ca2498815c9 | 315 | //printf("deg:%lfX1:%d:bt%ddeg:%lfval:%d\r\n",deg,(int)DATA[1],getBt(btSqa),deg,val); |
nodoame | 11:1ca2498815c9 | 316 | }while(false); |
nodoame | 0:dc587be179e9 | 317 | } |
nodoame | 0:dc587be179e9 | 318 | } |