目次
#contents
*課題 [#tf9e242a]
*ロボット [#i593e6bf]
*プログラム [#nb492bf3]
**マスター側 [#xaacd2e0]
 // マスター側(タイヤ、センサー)
 /*
 B  -> 右のモーター
 C  -> 左のモーター
 S1 -> 光センサー
 S2 -> 超音波センサー
 */
**定義 [#j5c85497]
 #define CONN 1          // スレーブの接続番号
 #define SPEED 40
 #define OROSE 11        // アームを降ろさせる	
 #define TOJIRO 12       // 缶を掴ませる
 #define AGERO 13        // アームを上げさせる 
 #define HIRAKE 14       // 缶を離させる
 #define TUM 15          // 缶の上まで下ろす
 #define RYO 16          // 完了
 #define SIRO0 47         // 白のしきい値
 #define SIRO1 54
 #define KURO0 42         // 黒のしきい値
 #define KURO1 37
**ライントレース [#zec7eb5a]
sub line_l()              //左側のライントレース

{
  SetSensorLight(S1);


  if (SENSOR_1 > SIRO1){

    Off(OUT_B);
    OnFwd(OUT_C,SPEED);


  } else if (SENSOR_1 > SIRO0){

    OnFwd(OUT_B,20);
    OnFwd(OUT_C,SPEED);


  } else if (SENSOR_1 > KURO0){

    OnFwd(OUT_BC,SPEED);


  } else if (SENSOR_1 > KURO1){

    OnFwd(OUT_B,SPEED);
    OnFwd(OUT_C,20);


  } else {

    OnFwd(OUT_B,SPEED);
    Off(OUT_C);


  }

}


sub line_r()              // ライントレース

{
  SetSensorLight(S1);

  if (SENSOR_1 > SIRO1){

    Off(OUT_C);
    OnFwd(OUT_B,SPEED);


  } else if (SENSOR_1 > SIRO0){

    OnFwd(OUT_C,20);
    OnFwd(OUT_B,SPEED);


  } else if (SENSOR_1 > KURO0){

    OnFwd(OUT_BC,SPEED);


  } else if (SENSOR_1 > KURO1){

    OnFwd(OUT_C,SPEED);
    OnFwd(OUT_B,20);


  } else {

    OnFwd(OUT_C,SPEED);
    Off(OUT_B);


  }

}


sub orose(int t)     // アームを下ろす

{
  int msg;


  SendRemoteNumber(CONN,MAILBOX1,OROSE);

  Wait(t);


}


sub hirake(int t)    // アームを開く

{
 
  int msg;

  
  SendRemoteNumber(CONN,MAILBOX1,HIRAKE);

  Wait(t);


}


sub tojiro(int t)    // 缶をつかむ

{
  
  int msg;


  SendRemoteNumber(CONN,MAILBOX1,TOJIRO);

  Wait(t);


}


sub agero(int t)     // アームを上げる

{
  
  int msg;


  SendRemoteNumber(CONN,MAILBOX1,AGERO);

  Wait(t);


}


sub tum(int t)       // 二段目まで下ろす

{
  
  int msg;


  SendRemoteNumber(CONN,MAILBOX1,TUM);

  Wait(t);


}



sub iti()        // Eの缶と一番上の缶

{
  
  SetSensorLight(S1);

  SetSensorLowspeed(S2);


  until (BluetoothStatus(CONN) == NO_ERR);

  hirake(1000);


  while(SensorUS(S2) > 10){
 
   OnFwdSync(OUT_BC,SPEED,0);
  
}


  Off(OUT_BC);

  tojiro(1000);
  
  
  long t0 = CurrentTick();


  while(CurrentTick()-t0 < 7000){
 
   line_l();

  }

  
  OnFwd(OUT_B,-40);

  OnFwd(OUT_C,40);

  Wait(700);
 
 
  t0 = CurrentTick();

  
  while(CurrentTick()-t0 < 2500){
 
   line_r();

  }


  t0 = CurrentTick();


  while(CurrentTick()-t0 < 1000){

    OnFwdSync(OUT_BC,SPEED,0);

  }
 
 
  Off(OUT_BC);

  Wait(500);

  RotateMotor(OUT_BC,-SPEED,65);

  Wait(100);

 
  agero(3000);
 
 
  while(SensorUS(S2) > 15){

    OnFwdSync(OUT_BC,SPEED,0);

  }


  Off(OUT_BC);


  tum(3000);

  Wait(500);


  while(SensorUS(S2) > 10){
 
   OnFwdSync(OUT_BC,SPEED,0);

  }


  Off(OUT_BC);


  tojiro(1000);

  OnFwd(OUT_BC,60);

  Wait(500);

  Off(OUT_BC);

  RotateMotor(OUT_C,SPEED,250);

  Wait(1000);
  Off(OUT_BC);

  OnFwd(OUT_BC,40);

  Wait(1000);

  Off(OUT_BC);

  hirake(1000);
 

}


sub ni()         // FとTの缶

{

  SetSensorLight(S1);

  SetSensorLowspeed(S2);


  OnRev(OUT_BC,SPEED);

  Wait(1000);

  OnFwd(OUT_B,-SPEED);

  OnFwd(OUT_C,SPEED);

  Wait(500);

  until (SensorUS(S2) < 40)

  Off(OUT_BC);


  orose(1000);


  hirake(1000);


  OnFwdSync(OUT_BC,SPEED,0);

  until (SensorUS(S2) < 20);


  tojiro(900);


  agero(1300);


  while(SENSOR_1 > SIRO0){

    OnFwd(OUT_BC,SPEED);

  }


  while(SensorUS(S2) > 20){

    line_l();

  }

  Off(OUT_BC);


  tum(1000);


  tojiro(1000);


  OnFwd(OUT_B,SPEED);

  Off(OUT_C);

  Wait(100);


  hirake(1000);


  agero(1300);


}


sub san()        // GとHの缶

{
 
 SetSensorLight(S1);

  SetSensorLowspeed(S2);





}


sub yon()        // 下のカーブと中身の入っている缶

{

  SetSensorLight(S1);

  SetSensorLowspeed(S2);





}





task main()

{
 
 iti();

/*
  ni();


  san();


  yon();
*/ [#v8d16809]

}
*結果・反省 [#d161449b]

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