Ryo Ogata
/
jumpROBO6_2_1
kairyou sita
Fork of jumpROBO6_2 by
Revision 1:b81c22891370, committed 2013-10-20
- Comitter:
- OGA
- Date:
- Sun Oct 20 01:39:55 2013 +0000
- Parent:
- 0:4c7c138f3891
- Commit message:
- 10/20;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 4c7c138f3891 -r b81c22891370 main.cpp --- a/main.cpp Sat Oct 19 04:50:26 2013 +0000 +++ b/main.cpp Sun Oct 20 01:39:55 2013 +0000 @@ -1,7 +1,7 @@ //カラーセンサ6つ同時に動かすプログラム //大会用ロボ //ジャンプのプログラムも入ってる -//10月17日に使う +//ジャンプ命令のプログラムを変更 #include "mbed.h" #include "ColorSensor.h" #include "Servo.h" @@ -11,11 +11,17 @@ -int cAve,roboF, jumI; +int cAve[COLOR_NUM] = {0}, roboF, jumI; void tic_sensor() { colorUpdate(1); + + + for(int i=0; i<COLOR_NUM; i++){ + cAve[i] = moving_ave(i, bluep[i]); + } + roboF = robotFront(); jumI = jumpInstruction(roboF); //pc.printf("R:%d G:%d B:%d\n", redp[0], greenp[0], bluep[0]); @@ -117,16 +123,10 @@ uint8_t robotFront()//縄回しロボの正面にいるか { uint8_t threshold = 0; - + for(int i=0; i<COLOR_NUM; i++){ - if(moving_ave(i, bluep[i]) >= 8) threshold++; + if(cAve[i] >= 8) threshold++; } - - - /*for(int i=0; i<COLOR_NUM; i++){ - cAve = moving_ave(i, bluep[i]); - if(cAve >= 8) threshold++; - }*/ if(threshold >= 1){ return 1; @@ -139,10 +139,8 @@ { uint8_t threshold = 0; - if(front == 1){ - for(int i=0; i<COLOR_NUM; i++){ - if(redp[i] >= R_THR) threshold++; - } + for(int i=0; i<COLOR_NUM; i++){ + if((cAve[i] >= 8) && (redp[i] >= R_THR)) threshold++; } if(threshold >= 1){ @@ -210,11 +208,34 @@ }*/ +void jumpAction(uint8_t threshold) +{ + static int jumpFlag; + + + if(sw1 == 0){//フォトインタラプタがオン + jumpFlag = 1; + } + + + if(threshold){ + jumpFlag = 0; + led[0] = 1; led[1] = 1; led[2] = 1; led[3] = 1; + myservo1 = 0; + wait(0.4); + } + + + if(jumpFlag){ + myservo1 = 0.5; led[0] = 1;led[1] = 0; led[2] = 0; led[3] = 0; + } + + +} - - +/* #define SEND_DATA_NUM 7 #define RECEIVE_DATA_NUM 7 @@ -240,7 +261,7 @@ led[4] = 1; } - +*/ @@ -259,11 +280,14 @@ //sw1.mode(PullUp); //init end + myservo1 = 0.1; + while(1) { - SendData0[1] = jumI; + //SendData0[1] = jumI; pc.printf("R:%d G:%d B:%d %t moving_ave():%d %t robotFront():%d %t jumpInstruction():%d\n", redp[2], greenp[2], bluep[2], cAve, roboF, jumI); - //jumpAction(jumI); + + jumpAction(jumI); } }
diff -r 4c7c138f3891 -r b81c22891370 main.h --- a/main.h Sat Oct 19 04:50:26 2013 +0000 +++ b/main.h Sun Oct 20 01:39:55 2013 +0000 @@ -21,18 +21,18 @@ ColorSensor color2(p12, p9, p10, p11, 10); ColorSensor color3(p8, p5, p6, p7, 10); -ColorSensor color4(p24, p21, p22, p23, 10); -ColorSensor color5(p30, p25, p26, p29, 10); -//ColorSensor color4(p26, p23, p24, p25, 10); -//ColorSensor color5(p30, p27, p28, p29, 10); +//ColorSensor color4(p24, p21, p22, p23, 10); +//ColorSensor color5(p30, p25, p26, p29, 10); +ColorSensor color4(p26, p23, p24, p25, 10); +ColorSensor color5(p30, p27, p28, p29, 10); Serial pc(USBTX, USBRX); // tx, rx DigitalOut led[4] = {LED1,LED2,LED3,LED4}; //DigitalOut air[2] = {p7,p8}; -//Servo myservo1(p21); -//DigitalIn sw1(p22); +Servo myservo1(p21); +DigitalIn sw1(p22);