This commit is contained in:
Nebel 2012-09-14 22:47:27 +09:00
parent ee9bc099ec
commit 22207c5064

View file

@ -138,6 +138,27 @@ void trace(byte sensor){
} }
} }
int checkMarker(byte sensor){
int mode = MODE_TRACE;
switch(sensor & MASK_CHECK_MARKER){
case 0b10000001:
counterOld = counter;
mode = MODE_LEFT;
break;
case 0b00000001:
if(counter%LAP_COUNT > LAP_COUNT/2){
mode = MODE_TARGET_RIGHT_VERTICAL;
}else{
mode = MODE_TARGET_PARALLEL1;
}
break;
case 0b10000000:
mode = MODE_TARGET_LEFT_VERTICAL;
break;
}
return mode;
}
void motorMode(byte motorLeftMode, byte motorRightMode, byte motorLeftSpeed, byte motorRightSpeed){ void motorMode(byte motorLeftMode, byte motorRightMode, byte motorLeftSpeed, byte motorRightSpeed){
motorL.mode( motorLeftMode, motorLeftSpeed); motorL.mode( motorLeftMode, motorLeftSpeed);
motorR.mode(motorRightMode, motorRightSpeed); motorR.mode(motorRightMode, motorRightSpeed);
@ -164,30 +185,6 @@ void count(){
} }
} }
int checkMarker(byte sensor){
int mode;
switch(sensor & MASK_CHECK_MARKER){
case 0b10000001:
counterOld = counter;
mode = MODE_LEFT;
break;
case 0b00000001:
if(counter%LAP_COUNT > LAP_COUNT/2){
mode = MODE_TARGET_RIGHT_VERTICAL;
}else{
mode = MODE_TARGET_PARALLEL1;
}
break;
case 0b10000000:
mode = MODE_TARGET_LEFT_VERTICAL;
break;
default:
mode = MODE_TRACE;
break;
}
return mode;
}
void sensorInit(){ void sensorInit(){
pinMode(PIN_SENSOR_0, INPUT); pinMode(PIN_SENSOR_0, INPUT);
pinMode(PIN_SENSOR_1, INPUT); pinMode(PIN_SENSOR_1, INPUT);
@ -250,19 +247,6 @@ void loop(){
#endif #endif
//ロータリーエンコーダーの変化を見る //ロータリーエンコーダーの変化を見る
count(); count();
//平行標的を狙う時は、ランスをぷるぷるする
static unsigned long millis_lance = 0;
if(millis() - millis_lance > LANCE_INTERVAL){
millis_lance = millis();
switch(servoLance.read()){
case LANCE_ANGLE1:
lance(LANCE_ANGLE2);
break;
case LANCE_ANGLE2:
lance(LANCE_ANGLE1);
break;
}
}
//全体の動作を決定する //全体の動作を決定する
switch(mode){ switch(mode){
case MODE_TARGET_RIGHT_VERTICAL: //右垂直標的 case MODE_TARGET_RIGHT_VERTICAL: //右垂直標的
@ -310,4 +294,17 @@ 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(servoLance.read()){
case LANCE_ANGLE1:
lance(LANCE_ANGLE2);
break;
case LANCE_ANGLE2:
lance(LANCE_ANGLE1);
break;
}
}
} }