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