[[2005/C5/しょう]]
*詰め合わせ [#m0674b0b]

ライン
 int c=40;
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   SetSensor (SENSOR_3, SENSOR_LIGHT);
   while (true)
   {
     while (SENSOR_1<c && SENSOR_3<c)
     {
      OnFwd (OUT_AC);
     }
 
     while (SENSOR_1<c && SENSOR_3>=c) 
     {
       OnFwd (OUT_C);
       OnRev (OUT_A);
     }
 
     while (SENSOR_1>=c && SENSOR_3<c)
     {
       OnFwd (OUT_A);
       OnRev (OUT_C);
     }
       OnFwd (OUT_AC);
   }
 }


light2
 int t=75;
 int m=0;
 int b; 
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   ClearTimer (0);
   while (Timer (0) <= t)
   {
   OnFwd (OUT_B);
   until (SENSOR_1 >= m || Timer (0) >= t+1);
   if (Timer (0) >= t+1) goto fine;
   Off (OUT_B);
   ClearTimer (1);
   m=SENSOR_1;
   PlaySound (SOUND_CLICK);
   }
   fine:
   Off (OUT_B);
   b=FastTimer (1)+5;
   PlaySound (SOUND_FAST_UP);
   OnRev (OUT_B);
   Wait (b);
   Off (OUT_B);
 }
 

light3
 int t=50;
 int m=0;
 int b;
 
 task main ()
 {
   SetSensor (SENSOR_3, SENSOR_LIGHT);
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   ClearTimer (0);
   while (Timer (0) <= t)
   {
   OnFwd (OUT_A);
   OnRev (OUT_C);
   if (SENSOR_1 >= m)
    {
    ClearTimer (1);
    m=SENSOR_1;
    PlaySound (SOUND_CLICK);
    }
   }
    Off (OUT_A+OUT_C);
   b=FastTimer (1);
 
   PlaySound (SOUND_FAST_UP);
   OnFwd (OUT_C);
   OnRev (OUT_A);
   Wait (b);
   Off (OUT_A+OUT_C);
   start follow;
   stop main;
 
 }
 
 task follow ()
 {
  start watch;
  while (true)
  {
   if (SENSOR_1 > SENSOR_3)
   {
     Off (OUT_A);
     OnFwd (OUT_C);
   }
   if (SENSOR_1 < SENSOR_3)
   {
     Off (OUT_C);
     OnFwd (OUT_A);
   }
   if (SENSOR_1 == SENSOR_3)
   {
     OnFwd (OUT_AC);
   }
  }
 }
 
 task watch ()
 {
    SetEvent(1, SENSOR_1, EVENT_TYPE_FASTCHANGE);
    SetEvent(2, SENSOR_3, EVENT_TYPE_FASTCHANGE);    
 
   monitor( EVENT_MASK(1) | EVENT_MASK(2) )
    {}
    catch( EVENT_MASK(1) | EVENT_MASK(2) )
    {
     start main;
     stop follow;
    }
 }

wall
 int t;
 int w;
 
 sub yuu ()
 {
    OnFwd(OUT_A+OUT_C);
    until((SENSOR_1==1)&&(SENSOR_3==1));
    OnRev(OUT_A+OUT_C);
    Wait(w);
    OnFwd(OUT_A);
    OnRev(OUT_C);
    Wait(105);
    Off (OUT_A+OUT_C);
 }
 
 sub sho ()
 {
   ClearTimer (0);
 
   while (Timer (0) < t)
   {
 
     while (SENSOR_1==1 && SENSOR_3==0)
     {
       Off (OUT_A+OUT_C);
       OnFwd (OUT_A+OUT_C);
     }
 
     while (SENSOR_1==0 && SENSOR_3==0)
     {
       Off (OUT_A+OUT_C); 
       OnFwd (OUT_C);
       OnRev (OUT_A);
       Wait (10);
       OnFwd (OUT_A+OUT_C);
       Wait (10);
     }
 
     if (SENSOR_1==1 && SENSOR_3==1)
     {
       OnRev (OUT_A+OUT_C);
       Wait (0);
       OnFwd (OUT_A);
       OnRev (OUT_C);
       Wait (130);
       Off (OUT_A+OUT_C);
     }
   } 
 
   Off (OUT_A+OUT_C);
 }
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_TOUCH); //left
   SetSensor (SENSOR_3, SENSOR_TOUCH); //right
   w=5;
   yuu();
   w=50;
   yuu();
   OnFwd (OUT_A+OUT_C);
   Wait (330);
   OnFwd (OUT_C);
   OnRev (OUT_A);
   Wait (90);
   OnFwd (OUT_A+OUT_C);
   until (SENSOR_1==1 && SENSOR_3==1);
   t=160;
   sho();
   w=5;
   yuu();
   yuu();
   OnFwd (OUT_A+OUT_C);
   Wait(340);
   t=1000;
   sho();
   Off (OUT_A+OUT_C);
 
 }

ロボコン用プログラム子機

 //OUT_C is arm and OUT_A is turntable
 //OnRev (OUT_C) is up and OnFwd (OUT_C);  is down
 //OnRev (OUT_A) is side and OnFwd (OUT_A);  is back
 
 int m;
 
 task main ()
 {
    SetSensor (SENSOR_1, SENSOR_LIGHT);
    SetSensor (SENSOR_2, SENSOR_TOUCH);
    ClearMessage();
    start arm;
    start turntable;
    start color;
    start touch;
  }
  
  task touch ()
  {
   while (true)
   {
    if (Message ()==7)
    {
         SendMessage (250);
      Wait (10);   
     until (SENSOR_2==1);
    do
    {
      SendMessage (4);
      ClearMessage ();
      Wait (20);
      PlaySound (SOUND_CLICK);
    }
    while (Message ()!=249);
    ClearMessage ();
    Wait (50);
    PlaySound (SOUND_FAST_UP);
    }
   }
  }
 
 task arm ()
  {
   while (true)
   {
     until ((Message ()==1 || Message ()==2) || Message ()==3);
      repeat (3)
       {
         SendMessage (254);
         Wait (5);
         }
      if (Message ()==1) OnRev (OUT_C);
     if (Message ()==2) OnFwd (OUT_C);
     if (Message ()==3) Off (OUT_C);
     ClearMessage ();
   }
  }
  
  task turntable ()
  {
   while (true)
     {
      until (Message ()==4 || Message ()==5);
           repeat (3)
           {
            SendMessage (253);
            Wait (5);
           }
      if (Message ()==4)
      {
        OnFwd (OUT_A);
      }
      if (Message ()==5)
      {
        OnRev (OUT_A);
      }
      ClearMessage ();
    }
  }
  
  task color ()
  {
    while (true)
    {
    until (Message ()==6);
    repeat (3)
    {
      SendMessage (252);
      Wait (5);
    }
    if (SENSOR_1<=34)
    {
      m=3;
    }
    else
    {
      if (SENSOR_1>=44)
      {
        m=1;
      }
      else
      {
        m=2;
      }
    }
    do
    {
      SendMessage (m);
      ClearMessage ();
      Wait (20);
    }
    while (Message ()!=255);
    }
    ClearMessage ();
  }


ロボコン用プログラム親機


 int c=40;
 int c1=47;
 int t=0;
 int tur=0;
 int total=0;
 int goback=0;
 int trans=0;
 int w=0;
 int b=0;
 int noturn=0;
 int m=0;
 int re=0;
 int hal=0;
 int t1=0;
 int t2=0;
 int t3=0;
 int t4=0;
 int t5=0;
 int t6=0;
 int touch=0;
 int notouch=0;
 int v=0;
 
 task transfer ()
 {
   trans=1;
   t=0;
 
   while (true)
   {
 
     if (SENSOR_1< c1 && SENSOR_3<c)
     {
       if (noturn==1)
       {
         Off (OUT_A+OUT_C);
         trans=0;
         start sto;
       }
       else
       {
         start turn;
         Wait (10);
         until (tur==0);
       }
     }
 
     while (SENSOR_1< c1 && SENSOR_3>=c)
     {
       OnFwd (OUT_C);
       OnRev (OUT_A);
     }
 
     while (SENSOR_1>= c1 && SENSOR_3<c)
     {
       OnFwd (OUT_A);
       OnRev (OUT_C);
     }
 
     OnFwd (OUT_A+OUT_C);
   }
 }
 
 task sto()
 {
   stop transfer;
 }
 
 
 task turn ()
 {
   tur=1;
   if (((t==t1 || t==t2) || t==t3) || t==t4)
   {
     if (t==t5 || t==t6)
     {
       if (goback==0)
       {
         tl ();
       }
       else
       {
         tr ();
       }
     }
     else
     {
       if (goback==0)
       {
         tr ();
       }
       else
       {
         tl ();
       }
     }
     if (t==t4 && hal==0)
     {
       trans=0;
       stop transfer;
     }
     t++;
   }
   else
   {
     if (t>t4)
     {
       trans=0;
       stop transfer;
     }
     else
     {
       t++;
       OnFwd (OUT_A+OUT_C);
       until (SENSOR_1>= c1 && SENSOR_3>=c);
     }
   }
   tur=0;
 }
 
 sub tl ()
 {
   SetPower (OUT_A,1);
   OnFwd (OUT_C);
   OnRev (OUT_A);
   until (SENSOR_1>= c1 && SENSOR_3>=c);
   SetPower (OUT_A,OUT_FULL);
 }
 
 sub tr ()
 {
   SetPower (OUT_C,1);
   OnFwd (OUT_A);
   OnRev (OUT_C);
   until (SENSOR_1>= c1 && SENSOR_3>=c);
   SetPower (OUT_C,OUT_FULL);
 }
 
 
 
 task back ()
 { 
   while (true)
   {
   while (SENSOR_2>=c)
     {
       OnRev (OUT_A);
       Off(OUT_C);
     }
    OnRev (OUT_C);
    Off (OUT_A);   
   }
 }
 
 
 task color ()
 {
   m=6;
   re=252;
   sm ();
   ClearMessage ();
   until ((Message ()==1 || Message ()==2) || Message ()==3);
   repeat (3)
   {
     SendMessage (255);
     Wait (5);
   }
    if (Message ()==1 && total<3 )
   {
     w=1;
     t1=0;
     t2=0;
     t3=0;
     t4=2;
     t5=5;
     t6=5;
   }
   if (Message ()==2 &&  total<3 )
   {
     g=1;
     t1=0;
     t2=0;
     t3=0;
     t4=1;
     t5=5;
     t6=5;
   }
   if (Message ()==3 &&  total<3 )
   {
     b=1;
     t1=0;
     t2=0;
     t3=0;
     t4=3;
     t5=5;
     t6=5;
   }
   if (Message ()==1 && total>=3)
   {
     w=1;
     t1=0;
     t2=2;
     t3=3;
     t4=5;
     t5=3;
     t6=3;
   }
   if (Message ()==2 &&  total>=3)
   {
     g=1;
     t1=0;
     t2=2;
     t3=3;
     t4=4;
     t5=3;
     t6=3;
   }
   if (Message ()==3 &&  total>=3)
   {
     b=1;
     t1=0;
     t2=2;
     t3=3;
     t4=6;
     t5=3;
     t6=3;
   }
   if (total<=1)
    {
    t4++;
    t3=1;
    t5=1;
    t6=1;
    }
 
   start transfer;
 }
 
 task revert ()
 {
   if (g==1 && total<3)
   {
     g=0;
     t1=1;
     t2=1;
     t3=1;
     t4=1;
     t5=1;
     t6=1;
     hal=1;
   }
   if (b==1 && total<3)
   {
     b=0;
     t1=3;
     t2=3;
     t3=3;
     t4=3;
     t5=3;
     t6=3;
     hal=1;
   }
   if (w==1 && total<3)
   {
     w=0;
     t1=2;
     t2=2;
     t3=2;
     t4=2;
     t5=2;
     t6=2;
     hal=1;
   }
   if (g==1 && total>=3)
   {
     g=0;
     t1=1;
     t2=1;
     t3=2;
     t4=4;
     t5=1;
     t6=4;
     hal=0;
   }
   if (b==1 && total>=3)
   {
     b=0;
     t1=3;
     t2=3;
     t3=4;
     t4=6;
     t5=3;
     t6=6;
     hal=0;
   }
   if (w==1 && total>=3)
   {
     w=0;
     t1=2;
     t2=2;
     t3=3;
     t4=5;
     t5=2;
     t6=5;
     hal=0;
   }
   start transfer;
 }
 
 sub sm ()
 {
   do
   {
     SendMessage (m);
     ClearMessage ();                         
     Wait (20);
   }
   while (Message ()!=re);
 }
 
 
 task main ()
 {
   SetSensor (SENSOR_1, SENSOR_LIGHT);
   SetSensor (SENSOR_2, SENSOR_LIGHT);
   SetSensor (SENSOR_3, SENSOR_LIGHT);
   repeat (6)
   {
     m=1;
     re=254;
     sm ();
    Wait (30);
     m=5;
     re=253;
     sm ();
    Wait (125);
     start back;
     Wait (30);
     m=7;
     re=250;
     sm ();
     until (Message ()==4);
     stop back;
     Off (OUT_A+OUT_C);
      repeat (4)
       {
         SendMessage (249);
         Wait (5);
         }
      Wait(50);   
     m=2;
     re=254;
     sm ();
     if (total==1)
     {
     OnFwd (OUT_A+OUT_C);
    Wait (110);
     Off (OUT_A+ OUT_C);
    OnFwd (OUT_C);
     OnRev (OUT_A);
    Wait (20);
     OnFwd (OUT_A+OUT_C);
    Wait (500);
 
     OnRev (OUT_C);
     Off (OUT_A);   
     Wait (100);
     m=4;
     re=253;
     sm();         
     until (SENSOR_2<c);
     until (SENSOR_2>=c);
     Off (OUT_A+ OUT_C);
     OnFwd (OUT_C);
     OnRev (OUT_A);
     until (SENSOR_3<c);
     Off (OUT_A+ OUT_C);
     OnFwd (OUT_A);
     until (SENSOR_1>= c1 && SENSOR_3>=c);
     SetPower (OUT_A,OUT_FULL);     
     Off (OUT_A+ OUT_C);
     }
     
     if (total<1)
     {
     t1=8;
     t2=8;
     t3=8;
     t4=8;
     t5=8;
     t6=8;
     start transfer;
     Wait (370);
     stop transfer;
     Off (OUT_A+ OUT_C);
     Wait (30);
     OnRev (OUT_C);
     Off (OUT_A);   
     Wait (110);
     m=4;
     re=253;
     sm();         
     until (SENSOR_2<c);
     until (SENSOR_2>=c);
     Off (OUT_A+ OUT_C);
     OnFwd (OUT_C);
     OnRev (OUT_A);
     until (SENSOR_3<c);
     Off (OUT_A+ OUT_C);
     OnFwd (OUT_A);
     until (SENSOR_1>= c1 && SENSOR_3>=c);
     SetPower (OUT_A,OUT_FULL);     
     Off (OUT_A+ OUT_C);
     } 
  
     start color;
     if (total>1)
     {
     m=4;
     re=253;
     sm();    
    } 
     Wait (100);
     until (trans==0);
 
     start transfer;
     Wait (410);
     stop transfer;
     Off (OUT_A+OUT_C);
     m=5;
     re=253;
     sm ();
     OnRev (OUT_A+OUT_C);
     Wait (100);
     Off (OUT_A+OUT_C);
     m=1;
     re=254;
     sm ();
     noturn=1;
     start transfer;
     Wait (180);
     stop transfer;
     Off (OUT_A+OUT_C);
     noturn=0;
     m=4;
     re=253;
     sm();
     start back;
     Wait (1050);
     stop back;
     Off (OUT_A+OUT_C);
     goback=1;
     start revert;
     Wait (500);
     m=3;
     re=254;
     sm ();
     until (trans==0);
    OnFwd (OUT_C);
     OnRev (OUT_A);
     until (SENSOR_3<c);
     Off (OUT_A+ OUT_C);
     OnFwd (OUT_A);
     until (SENSOR_1>= c1 && SENSOR_3>=c);
      Off (OUT_A+OUT_C);
     if (SENSOR_2>=c)
     {
    OnFwd (OUT_A);
     OnRev (OUT_C);
     Wait (30);
     Off (OUT_A+ OUT_C);     
     }
     hal=0;
     goback=0;
     total++;
   }
 }


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