Í¿¤¨¤é¤ì¤¿¥³¡¼¥¹¤Ë½¾¤Ã¤¿´Ì¤È¥í¥Ü¥Ã¥È¤Î°ÜÆ°
¥³¡¼¥¹2
²ÝÂê1¤Î·Ð¸³¤òÀ¸¤«¤·¤Æ¥»¥ó¥µ¡¼¤ò¤Ç¤¤ë¤À¤±Á°Îؤ˶á¤Å¤±¤¿¡£
¥¢¡¼¥à¤ò¼è¤êÉÕ¤±¤ë¤È½Å¿´¤¬Á°¤Ë¤¤¤¯¤¿¤á¡¢Ä¶²»ÇÈ¥»¥ó¥µ¡¼¤ò²¼¤Ë¤Ä¤±¤Æ°ÂÄꤵ¤»¤¿¡£
¥¢¡¼¥à¤Ï´Ì¤ò°ÂÄꤷ¤ÆÄϤá¤ë¤è¤¦¤Ë´è¾æ¤Ê¤â¤Î¤Ë¤·¤¿¡£
¥¢¡¼¥à¤Ë¥¿¥Ã¥Á¥»¥ó¥µ¡¼¤â¼è¤êÉÕ¤±¤Æ¤¤¤¿¤¬´Ì¤¬·Ú²á¤®¤Æǧ¼±¤·¤Ê¤¤¤Î¤Ç¼è¤ê¤Ï¤º¤·¤¿
#define THRESHOLD 50
¸÷¥»¥ó¥µ¡¼¤Î´ð½àÃͤò»ØÄê
#define SPEED_H 25¡¡ #define SPEED_L 20
®¤µ¤ò¤½¤ì¤¾¤ì»ØÄê
#define OnRL(speedR,speedL)OnFwd(OUT_B,speedR);OnFwd(OUT_C,speedL); #define go_forward OnRL(SPEED_H,SPEED_H); #define turn_left1 OnRL(SPEED_L+20,-SPEED_L-20); #define turn_left0 OnRL(SPEED_L,0); #define turn_right0 OnRL(0,SPEED_L); #define turn_right1 OnRL(-SPEED_L-20,SPEED_L+20);Wait(t);
ľ¿Ê¡¢¥«¡¼¥ÖÅù¤ÎÄ´À°
#define STEP 1 #define short_break Off(OUT_BC);Wait(1000); #define CROSS_TIME 300 #define cross_line OnRL(SPEED_L,SPEED_L);Wait(CROSS_TIME);short_break;
¾åµÎã³°¤ÎÆ°¤¤ò»ØÄê
̾Á°¤òÉÕ¤±¤¿¤¬Æ°¤¤Ë¤è¤Ã¤ÆÊѤ¨¤Æ¤¤¤Ã¤¿¤¿¤á¥ë¡¼¥È¤È̾Á°¤Ï»²¹Í¤Ë¤Ê¤é¤Ê¤¤¡£
¸òº¹ÅÀ¤Ï¹õ¤Î¿§¤Ç¼±ÊÌ
sub AtoJ(int t) { int n = 0; SetSensorLowspeed(S4); SetSensorLight(S3); ¡¡ while(n < 1){ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//´Ì¤ò¸«¤Ä¤±¤ë¤Þ¤ÇÀ®¤êΩ¤Ä ¡¡ if(SensorUS(S4) <= 7){ //´Ì¤¬£·Ñ°ÊÆâ¤Ë¤¢¤ë¤È¼Â¹Ô ¡¡ Off(OUT_BC); ¡¡ Wait(1000); ¡¡ go_forward; ¡¡ Wait(500); ¡¡ Off(OUT_BC); ¡¡ OnRev(OUT_A,50); ¡¡ Wait(1000); ¡¡ Off(OUT_A); ¡¡ n++; ¡¡ }else{¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//±¦¥È¥ì¡¼¥¹ ¡¡¡¡ if (SENSOR_3 < THRESHOLD-14){ ¡¡¡¡ turn_right1; ¡¡ }else if(SENSOR_3 < THRESHOLD-7){ ¡¡¡¡ turn_right0; ¡¡ }else if(SENSOR_3 < THRESHOLD+7){ ¡¡¡¡ go_forward; ¡¡ }else if(SENSOR_3 < THRESHOLD+10){ ¡¡¡¡ turn_left0; ¡¡ }else if(SENSOR_3 < THRESHOLD+20){ ¡¡ turn_left1; }else{ ¡¡ turn_left1; ¡¡ } ¡¡ Wait(STEP); ¡¡ } ¡¡ } n = 0; }
¤Þ¤º¤Ï±¦ÀÞ¤¹¤ë¤¿¤á¡¢¥é¥¤¥ó¤Î±¦Â¦¤ò¥È¥ì¡¼¥¹
´Ì¤ÈĶ²»ÇÈ¥»¥ó¥µ¡¼¤È¤Îµ÷Î¥¤¬7Ѱʲ¼¤ÇÁ°¿Ê¤·¤Æ´Ì¤ò¤Ä¤«¤à¡£
sub JtoL(int t) { int n = 0; int nOnline=0; SetSensorLight(S3);
while(n < 4){ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡//»Í²ó¤Î¸òº¹ÅÀ¤Î´Ö¤ÇÀ®Î© if (SENSOR_3 < THRESHOLD-14){ if(nOnline < 2){¡¡¡¡¡¡¡¡¡¡¡¡//¸òº¹ÅÀ¤òÆó¤Ä̵»ë¤¹¤ë¤Þ¤ÇÀ®Î© OnFwd(OUT_BC,30);¡¡¡¡¡¡¡¡ //¸òº¹ÅÀ¤òǧ¼±¤¹¤ë¤ÈÁ°¿Ê Wait(200); nOnline++; n++; }else{ //¸òº¹ÅÀ¤òÆó²óÁ°¿Ê¤¹¤ë¤ÈÀ®Î© turn_left1;Wait(1500); //I¤Î¸òº¹ÅÀ¤ÈH¤Î¸òº¹ÅÀ¤òº¸ÀÞ nOnline=0; n++; } }else{ if(SENSOR_3 < THRESHOLD-7){ turn_left0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_right0; }else if(SENSOR_3 < THRESHOLD+20){ turn_right1; }else{ turn_right1; } nOnline=0; Wait(STEP); }
} n=0; Off(OUT_BC); Wait(1000); turn_right1;¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//¼¡¤Î±¦¥È¥ì¡¼¥¹¤Î¤¿¤á±¦ÀÞ¤·¤Æ¤ª¤¯ }
º£Å٤Ϻ¸¥È¥ì¡¼¥¹¡£
K¤ÈL¤ÇÆó²óº¸ÀÞ¤ò̵»ë¤·¡¢I¤Çº¸ÀÞ¤¹¤ë
sub LtoH(int t) { int n = 0; SetSensorLight(S3);
while(n < 6){¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//°ì²óÌܤεޥ«¡¼¥Ö¤Þ¤ÇÀ®Î©
if (SENSOR_3 < THRESHOLD-14){ turn_right1; }else{ if(SENSOR_3 < THRESHOLD-7){ turn_right0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_left0; }else if(SENSOR_3 < THRESHOLD+20){¡¡¡¡¡¡¡¡//º¸¥È¥ì¡¼¥¹¤Ë°Ü¹Ô¤Ç¤¤ë¤è¤¦¤ËÂç²óž turn_left1;Wait(420);/*ÅÅÃӰ͸*/ n++; }else{ turn_left1; n++; } Wait(STEP); } } n = 0; }
H°Ê¹ß¤ÎµÞ¥«¡¼¥Ö¤Î¤¿¤á±¦¥È¥ì¡¼¥¹¡£
sub HtoG(int t) { int n = 0; SetSensorLight(S3);
while(n < 1){¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//µÞ¥«¡¼¥Ö¸å¹õ¤òǧ¼±¤¹¤ë¤Þ¤ÇÀ®Î©
if (SENSOR_3 < THRESHOLD-14){ cross_line; n++; }else{ if(SENSOR_3 < THRESHOLD-7){ turn_left0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_right0; }else if(SENSOR_3 < THRESHOLD+20){ turn_right1; }else{ turn_right1; } Wait(STEP); }
} n = 0; }
µÞ¥«¡¼¥Ö¤Î¤¿¤áº¸¥È¥ì¡¼¥¹¡£
¼¡±¦¥È¥ì¡¼¥¹¤ØÀÚ¤êÂؤ¨¤ë¤¿¤áºÇ¸å¤Ë±¦¤Ø°Ü¹Ô¤¹¤ë¡£
sub GtoD(int t) { int n = 0; SetSensorLight(S3);
while(n < 2){¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//¸òº¹ÅÀ¤òÆó²ó±¦ÀÞ¤¹¤ë¤Þ¤ÇÀ®Î©
if (SENSOR_3 < THRESHOLD-14){¡¡¡¡¡¡//¸òº¹ÅÀ¤òǧ¼±¤·¤¿¤é±¦ÀÞ Off(OUT_BC); Wait(1000); turn_right1; n++; }else{ if(SENSOR_3 < THRESHOLD-7){ turn_right0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_left0; }else if(SENSOR_3 < THRESHOLD+20){ turn_left1; }else{ turn_left1; } Wait(STEP); }
} n = 0; }
±¦¥È¥ì¡¼¥¹¡£G¤Î¸òº¹ÅÀ¤ò±¦¤Ë¶Ê¤¬¤ë¡£
sub FtoD(int t) { int n = 0; SetSensorLight(S3);
while(n < 1){¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//E¤Î¸òº¹ÅÀ¤ò̵»ë¤¹¤ë¤Þ¤ÇÀ®Î©
if (SENSOR_3 < THRESHOLD-14){¡¡¡¡//E¤òǧ¼±¤·Ä¾¿Ê OnFwd(OUT_BC,30); Wait(200); n++; }else{ if(SENSOR_3 < THRESHOLD-7){ turn_right0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_left0; }else if(SENSOR_3 < THRESHOLD+20){ turn_left1; }else{ turn_left1; } Wait(STEP); }
} n = 0; }
±¦¥È¥ì¡¼¥¹¡£E¤Î±¦ÀÞ¤ò̵»ë¤·¡¢´Ì¤òÃÖ¤¯¤¿¤á¤Î½àÈ÷
sub DtoD(int t) { int n = 0; SetSensorLight(S3);
while(n < 1){¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//´Ì¤òÃÖ¤¡¢180¡ë²óž¤¹¤ë¤Þ¤ÇÀ®Î©
if (SENSOR_3 < THRESHOLD-14){¡¡//D¤òǧ¼±¤¹¤ë¤ÈÃÖ¤¯¤Ù¤¾ì½ê¤Ë´Ì¤òÃÖ¤180¡ë²óž turn_left1;Wait(t); OnRev(OUT_BC,30); Wait(t); Off(OUT_BC); OnFwd(OUT_A,50); Wait(1000); Off(OUT_A); OnRev(OUT_BC,30); Wait(90); Off(OUT_BC); turn_left1; Wait(t); n++; }else{ if(SENSOR_3 < THRESHOLD-7){ turn_right0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_left0; }else if(SENSOR_3 < THRESHOLD+20){ turn_left1; }else{ turn_left1; } Wait(STEP); }
} n = 0; }
Êý¸þž´¹¤·¤Æ´Ì¤òÃÖ¤¯¡£¤â¤¦°ìÅÙÊý¸þž´¹¤·Ä¾Àܼ¡¤Î¥«¡¼¥Ö¤Ø
sub DtoC(int t) { int n = 0; SetSensorLight(S3);
while(n < 2){¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡//C¤Î¸òº¹ÅÀ¤ÈA¤Îľ¿Ê¤Þ¤ÇÀ®Î©
if (SENSOR_3 < THRESHOLD-14){ //¹õ¤òƧ¤ó¤À¤éľ¿Ê Off(OUT_BC); Wait(1000); cross_line; n++; }else{ if(SENSOR_3 < THRESHOLD-7){ turn_right0; }else if(SENSOR_3 < THRESHOLD+7){ go_forward; }else if(SENSOR_3 < THRESHOLD+10){ turn_left0; }else if(SENSOR_3 < THRESHOLD+20){ turn_left1; }else{ turn_left1; } Wait(STEP); }
} n = 0; }
±¦¥È¥ì¡¼¥¹¡£µÞ¥«¡¼¥Ö¡¢¤½¤·¤ÆC¤Î¸òº¹ÅÀ¤ò̵»ë¤·¤ÆA¤Ø
task main() { AtoJ(1350); turn_left1; Wait(1000); go_forward; Wait(500); Off(OUT_BC); JtoL(100); LtoH(100); turn_left0; Wait(3000); HtoG(100); turn_left0; Wait(400); GtoD(740); FtoD(100); DtoD(1500); DtoC(100); }
¥×¥í¥°¥é¥à¤Î¼Â¹Ô¡£º¸±¦¥È¥ì¡¼¥¹¤ÎÊä½õ
µÞ¥«¡¼¥Ö¤È¥«¡¼¥Ö¤ÈÀþ¤Î¹çήÅÀ¤¬¿É¤«¤Ã¤¿¡£Æä˵ޥ«¡¼¥Ö¤Ç¤Ï¤É¤¦¤·¤Æ¤âº¸±¦¤Î¥È¥ì¡¼¥¹¤òÀÚ¤êÂؤ¨¤ëɬÍפ¬¤¢¤ë¤¿¤áÅÅÃÓ»ÄÎ̤˺¸±¦¤µ¤ì¤ë¤¿¤áÄ´À°¤¹¤ëɬÍפ¬¤¢¤Ã¤¿¡£
¥¢¡¼¥à¤Ë¤è¤ë´Ì¤Î¥¥ã¥Ã¥Á¡õ¥ê¥ê¡¼¥¹¤Ï¤¹¤°¤Ë¤Ç¤¤¿¤Î¤Ç¤è¤«¤Ã¤¿