diff --git a/arduino/SerialReadRot/SerialReadRot.ino b/arduino/SerialReadRot/SerialReadRot.ino new file mode 100644 index 0000000..837ce3d --- /dev/null +++ b/arduino/SerialReadRot/SerialReadRot.ino @@ -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); +} diff --git a/arduino/hanzo2_1/hanzo2_1.ino b/arduino/hanzo2_1/hanzo2_1.ino index 3e4268d..2338561 100644 --- a/arduino/hanzo2_1/hanzo2_1.ino +++ b/arduino/hanzo2_1/hanzo2_1.ino @@ -21,13 +21,10 @@ const unsigned long LAP_COUNT = 854; const unsigned long TARGET_NONE_COUNT = LAP_COUNT/10; -const int LANCE_ANGLE_PARALLEL1 = 43; //度 -const int LANCE_ANGLE_PARALLEL2 = 42; -const int LANCE_ANGLE_LEFT_VERTICAL = -33; -const int LANCE_ANGLE_RIGHT_VERTICAL = 34; - -const int LANCE_INTERVAL_DEGREE = 10; //ぷるぷるメソッドのための間隔(度) -const unsigned long LANCE_INTERVAL = 6*LANCE_INTERVAL_DEGREE; //ms +const int LANCE_ANGLE_PARALLEL1 = 90 - 43; //度 +const int LANCE_ANGLE_PARALLEL2 = 90 - 34; +const int LANCE_ANGLE_LEFT_VERTICAL = 90 - 123; +const int LANCE_ANGLE_RIGHT_VERTICAL = 90 - 59; const byte SPEED_DEFAULT = 255; @@ -91,11 +88,11 @@ void trace(byte sensor){ switch(sensor&MASK_MODE_TRACE){ case 0b01000000: handle(-5*HANDLE_KP); - motorMode(GO, GO, 0, SPEED_DEFAULT); + motorMode(GO, GO, SPEED_DEFAULT/4, SPEED_DEFAULT/2); break; case 0b01100000: handle(-4*HANDLE_KP); - motorMode(GO, GO, SPEED_DEFAULT/4, SPEED_DEFAULT); + motorMode(GO, GO, SPEED_DEFAULT*0.8, SPEED_DEFAULT); break; case 0b00100000: handle(-3*HANDLE_KP); @@ -260,12 +257,20 @@ void loop(){ mode = MODE_TRACE; break; case MODE_TARGET_PARALLEL1: //平行標的1 - lance(LANCE_ANGLE_PARALLEL1); - mode = MODE_TRACE; + trace(sensor); + lance(LANCE_ANGLE_PARALLEL1-10); + if(counter - modeChangeCounter > 25){ + lance(LANCE_ANGLE_PARALLEL1); + mode = MODE_TRACE; + } break; case MODE_TARGET_PARALLEL2: //平行標的2 - lance(LANCE_ANGLE_PARALLEL2); - mode = MODE_TRACE; + trace(sensor); + lance(LANCE_ANGLE_PARALLEL2-10); + if(counter - modeChangeCounter > 26){ + lance(LANCE_ANGLE_PARALLEL2); + mode = MODE_TRACE; + } break; case MODE_TRACE: trace(sensor); @@ -274,14 +279,17 @@ void loop(){ // if( counter > LAP_COUNT*6 - LAP_COUNT/14 ){ // mode = MODE_TARGET_CYLINDER; // } - if(counter > LAP_COUNT*3){ + if(counter > LAP_COUNT*1){ mode = MODE_STOP; } break; case MODE_LEFT: //左カーブ trace(sensor); - lance(0); - if(counter - modeChangeCounter > TARGET_NONE_COUNT) mode = MODE_TRACE; + lance(90); + if(counter - modeChangeCounter > TARGET_NONE_COUNT){ + lance(0); + mode = MODE_TRACE; + } break; case MODE_TARGET_CYLINDER: //円筒標的 digitalWrite(PIN_LED, HIGH); @@ -300,24 +308,4 @@ void loop(){ motorR.mode(STOP); 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; - } - } } diff --git a/shellscript/.bashrc b/shellscript/.bashrc index 42b2aca..ba4aa76 100644 --- a/shellscript/.bashrc +++ b/shellscript/.bashrc @@ -36,4 +36,5 @@ alias f=find #alias o=xdg-open alias o=open #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'