[[2006a/C3/ロボコン]]

受け取る側

 #define blackline 40
 int frag;
 int step;
 task linetrace (){
 int frag;             //変数frag(黒線の本数)の設定
 int step;                          //変数step(動作の段階)の設定
 task linetrace (){         //ライントレースを定義
  if ((SENSOR_1<=blackline)&&(SENSOR_3>=blackline)){
    OnFwd (OUT_C);OnRev (OUT_A);
  }
  if ((SENSOR_1>=blackline)&&(SENSOR_3<=blackline)){
    OnFwd (OUT_A);OnRev (OUT_C);
  }
  if ((SENSOR_1<=blackline)&&(SENSOR_3<=blackline)){
    frag++;
    frag++;                         //両方のセンサーが暗さを感じたらfrag+1
    OnFwd (OUT_A+OUT_C); Wait(010);
  }
  if ((SENSOR_1>=blackline)&&(SENSOR_3>=blackline)){
    OnFwd (OUT_A+OUT_C);
  }
 }
 sub go_straight (){
  OnFwd (OUT_A+OUT_C);
 }
 sub go_back (){
  OnRev (OUT_A+OUT_C);
 }
 sub turn_R (){
  OnFwd (OUT_A+OUT_C);Wait(025);
  OnRev (OUT_C);Wait(200);Off(OUT_A+OUT_C);
 }
 sub turn_L (){
  OnFwd (OUT_C+OUT_A);Wait(025);
  OnRev (OUT_A);Wait(200);Off(OUT_A+OUT_C);
 }
 sub hold_can()
 {
 OnFwd(OUT_B);Wait(200);Off(OUT_B);
 }  
 sub part_can()
 {
 OnRev(OUT_B);Wait(300);Off(OUT_B);
 }
 task main(){
  SetSensor (SENSOR_1, SENSOR_LIGHT);
  SetSensor (SENSOR_3, SENSOR_LIGHT);
  frag=0;
  step=1;
  while (true){
  
     Wait(500);
     hold_can();
     while (step==1){
     while (step==1){          //ステップ1
        Wait(050);
        go_back ();Wait(400);
        turn_R ();Wait(200);
        step=step+1;
        turn_R ();Wait(200);      //後進して左折
        step=step+1;          //ステップ2へ移行
      }
      while (step==2){
        start linetrace;
      while (step==2){         //ステップ2
        start linetrace;        //ライントレース
        if (frag==2){
          frag=3;
          turn_L ();
          step=step++;
          turn_L ();          //黒線を3本認識したら左折
          step=step++;         //ステップ3へ移行
        }
      }
      while (step==3){
      while (step==3){         //ステップ3
          OnFwd(OUT_A+OUT_C);Wait(100);
          part_can();
          OnFwd(OUT_A+OUT_C);Wait(50);
          step=step++;
          OnFwd(OUT_A+OUT_C);Wait(50); //缶をゴールする
          step=step++;         
         }
         
        while(step==4){
        while(step==4){         //ステップ4
          OnRev(OUT_A+OUT_C);Wait(150);
            turn_L ();
            step=step++; 
        
            turn_L ();          //後進して左折
            step=step++;  
        }
        while(step==5){
            start linetrace;
        while(step==5){         //ステップ5
            start linetrace;      //ライントレース
            if(frag==5){
            turn_R();
            turn_R();         //黒線を5本認識したら右折
            frag=6;
            step=step++;
            }
            }
       while(step==6){
            start linetrace;
       while(step==6){        //ステップ6
            start linetrace;     //ライントレース
            if(frag==7){
            go_straight();Wait(50);
            go_straight();Wait(50);  //黒線を7本認識したら直進
            frag=8;
            step=step++;
           }
           }
         while(step==7){
            step=1;
            frag=0;
         while(step==7){       //ステップ7
            step=1;         //ステップ1へ移行
            frag=0;         //黒線の本数を0にする
         }  
           
          
    }
  }


繰り返しをしてしまい失敗。

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS