ぷるぷるメソッド廃止

This commit is contained in:
Nebel 2012-10-05 21:19:04 +09:00
parent d85e34d742
commit 5c2bf67c5e
3 changed files with 47 additions and 37 deletions

View file

@ -0,0 +1,21 @@
const byte PIN_ROT = 2;
volatile unsigned long counter = 0;
void count(){
static byte rot[2] = {0}; //rot[0]:今の状態, rot[1]:前回の状態
rot[0] = digitalRead(PIN_ROT);
if(rot[0] != rot[1]){
rot[1] = rot[0];
counter++;
}
}
void setup(){
Serial.begin(9600);
pinMode(PIN_ROT, INPUT);
}
void loop(){
count(); //ロータリーエンコーダーの変化を見る
Serial.println(counter);
}

View file

@ -21,13 +21,10 @@
const unsigned long LAP_COUNT = 854; const unsigned long LAP_COUNT = 854;
const unsigned long TARGET_NONE_COUNT = LAP_COUNT/10; const unsigned long TARGET_NONE_COUNT = LAP_COUNT/10;
const int LANCE_ANGLE_PARALLEL1 = 43; //度 const int LANCE_ANGLE_PARALLEL1 = 90 - 43; //度
const int LANCE_ANGLE_PARALLEL2 = 42; const int LANCE_ANGLE_PARALLEL2 = 90 - 34;
const int LANCE_ANGLE_LEFT_VERTICAL = -33; const int LANCE_ANGLE_LEFT_VERTICAL = 90 - 123;
const int LANCE_ANGLE_RIGHT_VERTICAL = 34; const int LANCE_ANGLE_RIGHT_VERTICAL = 90 - 59;
const int LANCE_INTERVAL_DEGREE = 10; //ぷるぷるメソッドのための間隔(度)
const unsigned long LANCE_INTERVAL = 6*LANCE_INTERVAL_DEGREE; //ms
const byte SPEED_DEFAULT = 255; const byte SPEED_DEFAULT = 255;
@ -91,11 +88,11 @@ void trace(byte sensor){
switch(sensor&MASK_MODE_TRACE){ switch(sensor&MASK_MODE_TRACE){
case 0b01000000: case 0b01000000:
handle(-5*HANDLE_KP); handle(-5*HANDLE_KP);
motorMode(GO, GO, 0, SPEED_DEFAULT); motorMode(GO, GO, SPEED_DEFAULT/4, SPEED_DEFAULT/2);
break; break;
case 0b01100000: case 0b01100000:
handle(-4*HANDLE_KP); handle(-4*HANDLE_KP);
motorMode(GO, GO, SPEED_DEFAULT/4, SPEED_DEFAULT); motorMode(GO, GO, SPEED_DEFAULT*0.8, SPEED_DEFAULT);
break; break;
case 0b00100000: case 0b00100000:
handle(-3*HANDLE_KP); handle(-3*HANDLE_KP);
@ -260,12 +257,20 @@ void loop(){
mode = MODE_TRACE; mode = MODE_TRACE;
break; break;
case MODE_TARGET_PARALLEL1: //平行標的1 case MODE_TARGET_PARALLEL1: //平行標的1
lance(LANCE_ANGLE_PARALLEL1); trace(sensor);
mode = MODE_TRACE; lance(LANCE_ANGLE_PARALLEL1-10);
if(counter - modeChangeCounter > 25){
lance(LANCE_ANGLE_PARALLEL1);
mode = MODE_TRACE;
}
break; break;
case MODE_TARGET_PARALLEL2: //平行標的2 case MODE_TARGET_PARALLEL2: //平行標的2
lance(LANCE_ANGLE_PARALLEL2); trace(sensor);
mode = MODE_TRACE; lance(LANCE_ANGLE_PARALLEL2-10);
if(counter - modeChangeCounter > 26){
lance(LANCE_ANGLE_PARALLEL2);
mode = MODE_TRACE;
}
break; break;
case MODE_TRACE: case MODE_TRACE:
trace(sensor); trace(sensor);
@ -274,14 +279,17 @@ void loop(){
// if( counter > LAP_COUNT*6 - LAP_COUNT/14 ){ // if( counter > LAP_COUNT*6 - LAP_COUNT/14 ){
// mode = MODE_TARGET_CYLINDER; // mode = MODE_TARGET_CYLINDER;
// } // }
if(counter > LAP_COUNT*3){ if(counter > LAP_COUNT*1){
mode = MODE_STOP; mode = MODE_STOP;
} }
break; break;
case MODE_LEFT: //左カーブ case MODE_LEFT: //左カーブ
trace(sensor); trace(sensor);
lance(0); lance(90);
if(counter - modeChangeCounter > TARGET_NONE_COUNT) mode = MODE_TRACE; if(counter - modeChangeCounter > TARGET_NONE_COUNT){
lance(0);
mode = MODE_TRACE;
}
break; break;
case MODE_TARGET_CYLINDER: //円筒標的 case MODE_TARGET_CYLINDER: //円筒標的
digitalWrite(PIN_LED, HIGH); digitalWrite(PIN_LED, HIGH);
@ -300,24 +308,4 @@ void loop(){
motorR.mode(STOP); motorR.mode(STOP);
break; break;
} }
/* 平行標的を狙う時は、ランスをぷるぷるする */
static unsigned long millis_lance = 0;
if(millis() - millis_lance > LANCE_INTERVAL){
millis_lance = millis();
switch(lanceRead()){
case LANCE_ANGLE_PARALLEL1:
lance(LANCE_ANGLE_PARALLEL1 - LANCE_INTERVAL_DEGREE);
break;
case LANCE_ANGLE_PARALLEL1 - LANCE_INTERVAL_DEGREE:
lance(LANCE_ANGLE_PARALLEL1);
break;
case LANCE_ANGLE_PARALLEL2:
lance(LANCE_ANGLE_PARALLEL2 - LANCE_INTERVAL_DEGREE);
break;
case LANCE_ANGLE_PARALLEL2 - LANCE_INTERVAL_DEGREE:
lance(LANCE_ANGLE_PARALLEL2);
break;
}
}
} }

View file

@ -36,4 +36,5 @@ alias f=find
#alias o=xdg-open #alias o=xdg-open
alias o=open alias o=open
#alias d=gvfs-trash #alias d=gvfs-trash
alias rm='gmv -f --backup=numbered --target-directory ~/.Trash' #alias rm='gmv -f --backup=numbered --target-directory ~/.Trash'
alias rm='mv -f --target-directory ~/.Trash'