[[2006a/C3/ロボコン]]
 
 #define blackline 40
 int frag;
 sub linetrace (){
  if ((SENSOR_1 <= blackline) && (SENSOR_3 <= blackline)){
    OnFwd(OUT_A + OUT_C);
    Wait(030);
    frag++;
  }
  else{
    if ((SENSOR_1 <= blackline) && (SENSOR_3 >= blackline)){
      OnFwd (OUT_A);OnRev (OUT_C);
    }
    if ((SENSOR_1 >= blackline) && (SENSOR_3 <= blackline)){
      OnFwd (OUT_C);OnRev (OUT_A);
    }
    if ((SENSOR_1 >= blackline) && (SENSOR_3 >= blackline))   {
      OnFwd (OUT_A + OUT_C);
    }
  }
 }
 sub hold_can (){
 ClearMessage();           
        until (Message() != 0); 
        if ( Message() == 1 ){
 Wait(1000);
 OnFwd(OUT_B);Wait(200);
 OnRev(OUT_A+OUT_C);Wait(350);
 }
 }
 
 sub port_can (){
 OnFwd(OUT_A+OUT_C);Wait(30);
  OnRev(OUT_B);
  Wait (200);
  Off (OUT_B);
  OnFwd(OUT_A+OUT_C);
  Wait(50);
  OnRev(OUT_A+OUT_C);
  Wait(250);
  }
 sub go_straight (){
  OnFwd (OUT_A+OUT_C);
 }
 sub go_down (){
  OnRev (OUT_A+OUT_C);
 }
 sub turn_R (){
  Off (OUT_A + OUT_C);OnRev (OUT_A+OUT_C);Wait (007);OnFwd  (OUT_A);Wait (150);Off (OUT_A+OUT_C);
 }
 
 sub turn_r(){ 
 Off(OUT_A+OUT_C);OnRev(OUT_A+OUT_C);Wait(007);OnFwd  (OUT_A);Wait(130);
 }
 
 sub turn_L (){
  Off (OUT_A + OUT_C);OnRev (OUT_C+OUT_A);Wait (007);OnFwd (OUT_C);Wait (130);Off (OUT_A+OUT_C);
 }
 task main(){
  SetSensor (SENSOR_1, SENSOR_LIGHT);
  SetSensor (SENSOR_3, SENSOR_LIGHT);
  frag=0;
  while (true){
   if(frag==0){
   hold_can();
   turn_R();
   frag=1; 
   }
      if (frag ==1|| 2||6||7||9){
        linetrace ();
      }	
      if (frag == 3){
      OnFwd(OUT_A+OUT_C);Wait(30);
        turn_L ();
        frag = 4;
      }
      if (frag == 4){
        port_can();
        turn_L();
        frag=6;
        }
        if (frag == 8){
        OnFwd(OUT_A+OUT_C);Wait(050);
        turn_r ();
        frag =9;
      }
      if (frag == 10){
          OnFwd(OUT_A+OUT_C);Wait(120);
          Off(OUT_A+OUT_C);
          Wait(80);
           frag = 0;
      }
    }
    }



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS