担当:後藤
ライントレースロボット
プログラム作成ー>後藤
工夫した点
ソース
#define RIGHT -1 #define LEFT 1 #define TURN_L OnFwd(OUT_C);OnRev(OUT_A); #define TURN_R OnFwd(OUT_A);OnRev(OUT_C); #define White SENSOR_2 > 40 #define Black SENSOR_2 < 40 #define GO OnFwd(OUT_A+OUT_C); #define TURN_mR OnFwd(OUT_A); #define TURN_mL OnFwd(OUT_C); //===================HENSU_TEIGI============================= int tim=0; int no=-1; int change=0; int check=0; int separate=1; int turn=0; int find=1; //==================MAIN===================================== task main() { SetSensor(SENSOR_2,SENSOR_LIGHT); while(true){//while1 ClearTimer(1); while(change < 5){//while2 GO; until(White); trace(no);
}//while2 if((change >= 5) || (FastTimer(1)/5) < 1000){ SecondTrace(); } change = 0; }//while1 }//main
//============================-functions================================== void trace(int no){ ClearTimer(0); if(separate != 0){ check = FastTimer(1); } TURN(no); until((Black) || (FastTimer(0) > 80)); tim = FastTimer(0); fast(no); CourseChange(no); }
void TURN(int i){ if(i == RIGHT){ TURN_R; }else if(i == LEFT){ TURN_L; } } void CourseChange(int i){ if(tim >= 80){//if5 ClearTimer(0); TURN(-i); until(Black);
if(FastTimer(0) > (140 + tim)){//if-c TURN(-i); until(White); TURN(-i); until((Black) || (FastTimer(0) > 300)); if(FastTimer(0) > 300){//if-b Search(); if(find == -1){//if-a Off(OUT_A+OUT_C); }//if-a }//if-b }//if-c no *= -1; change++; }//if5 }//void
void fast(int i){ if(tim < 40){//if2 separate++; if((separate >= 3) && ((FastTimer(1) - check) < 120)){//if3 ClearTimer(3); TURN(-i); until((FastTimer(3) > 40) || (White));
if(White){ TURN(-i); until(Black); } }else{//if3 separate = 0; }//if3 }//if2 }
//=======================SECOND-TRACE============================== sub SecondTrace(){ int tim; while(true){ ClearTimer(1); TURN_mR; until((White) || (FastTimer(1) > 40); tim = FastTimer(1); if(tim > 40){ Search(); if(find = -1){ break; } } TURN_mL; until((Black) || ((FastTimer(1) - tim) > 40)); if((FastTimer(1)-tim) > 40) Search(); if(find = -1){ break; } } }//while } //=======================Search============================== sub Search() { int i=1; int tim; while(i <= 5){ ClearTimer(1); repeat(2){ GO; until((FastTimer(1) > (i*100)) || (Black)); if(Black){ find = 1; break; } tim = FastTimer(1); TURN(RIGHT); until(((FastTimer(1)-tim) > 80) || (Black)); if(Black){ find = 1; break; } }//repeat i++; }//while find = -1; //return(find); }