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