[[2017a/Member]]
目次
#contents
*課題について [#ucad970a]
詳しくは[[課題2 >2017a/Mission2]]を参照。今回は、交差点や急カーブを含めたライントレースを行った。
*ロボットについて [#fc2eff43]
今回は、下記の写真のように、ライントレースの授業で使用したものと全く同じ形のロボットでライントレースを行った。
*プログラムについて [#redfa641]
まず、しきい値や速さなど基本となる値を定義した。
 #define threshold 46
 #define SPEED_H 30
 #define SPEED_L 20
 #define OnRL(speedR,speedL) 
   OnFwd(OUT_C,speedR);OnFwd(OUT_B,speedL);
 #define go_forward OnRL(SPEED_H,SPEED_H);
 #define turn_left1 OnRL(SPEED_L,-SPEED_L);
 #define turn_left0 OnRL(SPEED_L,0);
 #define turn_right0 OnRL(0,SPEED_L);
 #define turn_right1 OnRL(-SPEED_L,SPEED_L);
 #define STEP 1
 #define nMax 150
 #define mMax 3
次に、

#define threshold 46
#define SPEED_H 30
#define SPEED_L 20
#define OnRL(speedR,speedL) \
  OnFwd(OUT_C,speedR);OnFwd(OUT_B,speedL);
#define go_forward OnRL(SPEED_H,SPEED_H);
#define turn_left1 OnRL(SPEED_L,-SPEED_L);
#define turn_left0 OnRL(SPEED_L,0);
#define turn_right0 OnRL(0,SPEED_L);
#define turn_right1 OnRL(-SPEED_L,SPEED_L);
#define STEP 1
#define nMax 150
#define mMax 3
#define tMax 30
*反省・考察 [#z21d5eb0]
やはり、タイヤとセンサーが離れていたせいか急カーブの内側をうまく曲がれることができなかった。そこをプログラムで補おうとしたが、それも難しかった。結局は外側を通ることでなんとか曲がれはしたものの不本意な結果となった。そして、ロボットに手を加える必要性と自分自身の見通しの甘さを痛感させられた。これからは、先を見通し、ロボットをうまく改良することでプログラミングを楽にさせていきたい。
 

sub line_cross1()
{
  int nOnline = 0;
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -12) {
       turn_left1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_left0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_right0;
      } else {
       turn_right1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross2()
{
  int nOnline = 0;
  turn_left0;
  Wait(800);
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -12) {
       turn_right1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_right0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_left0;
      } else {
       turn_left1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 Wait(1000);
 nOnline = 0;
}
sub line_cross3()
{
  int nOnline = 0;
  turn_right0;
  Wait(2000);
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -12) {
       turn_right1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_right0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_left0;
      } else {
       turn_left1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross4()
{
  int nOnline = 0;
  turn_left0;
  Wait(400);
  go_forward;
  Wait(200);
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -12) {
       turn_right1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_right0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_left0;
      } else {
       turn_left1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross5()
{
  int nOnline = 0;
  go_forward;
  Wait(200);
  while (nOnline < 3) {

      if (SENSOR_1 < threshold -12) {
       turn_left1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_left0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_right0;
      } else {
       turn_right1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 Wait(1000);
 nOnline = 0;
}
sub line_cross6()
{
  int nOnline = 0; 
  go_forward;
  Wait(300);
  while (nOnline < 1) {

      if (SENSOR_1 < threshold -10) {
       turn_left1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_left0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_right0;
      } else {
       turn_right1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 Wait(1000);
 nOnline = 0;
}
sub line_cross7()
{
  int nOnline = 0;
  go_forward;
  Wait(300);
  line_cross1();
}
sub line_cross8()
{
 int nOnline = 0;
 turn_left0;
 Wait(2800);
 go_forward;
 Wait(200);
  while (nOnline < nMax) {

      if (SENSOR_1 < threshold -12) {
       turn_left1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_left0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_right0;
      } else {
       turn_right1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross9()
{
  int nOnline = 0;
  turn_left1;
  Wait(2500);
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -15) {
       turn_left1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_left0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +15) {
       turn_right0;
      } else {
       turn_right1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross10()
{
  int nOnline = 0;
  go_forward;
  Wait(400);
  while (nOnline < 5) {

      if (SENSOR_1 < threshold -12) {
       turn_right1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_right0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_left0;
      } else {
       turn_left1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross11()
{
  int nOnline = 0;
  turn_right1;
  Wait(1500);
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -15) {
       turn_right1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_right0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +15) {
       turn_left0;
      } else {
       turn_left1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
}
sub line_cross12()
{
  int nOnline = 0;
  while (nOnline < mMax) {

      if (SENSOR_1 < threshold -12) {
       turn_right1;
        nOnline++;
      } else {
      if (SENSOR_1 < threshold -7) {
       turn_right0;
      } else if (SENSOR_1 < threshold +7) {
       go_forward;
      } else if (SENSOR_1 < threshold +12) {
       turn_left0;
      } else {
       turn_left1;
      }
       nOnline = 0;
      }
       Wait(STEP);
      }
 Off(OUT_BC);
 nOnline = 0;
 go_forward;
 Wait(500);
 Off(OUT_BC);
}
task play_music1()
{
 Wait(100);
 PlaySound(SOUND_UP);
 Wait(1000);
}

task play_music2()
{
 Wait(100);
 PlaySound(SOUND_DOWN);
 Wait(1000);
}

task main()
{
 SetSensorLight(S1);

 go_forward;
 Wait(1000);
 line_cross1();
 start play_music1;
 line_cross2();
 start play_music2;
 line_cross3();
 start play_music1;
 line_cross4();
 start play_music1;
 line_cross5();
 start play_music2;
 line_cross6();
 start play_music2;
 line_cross7();
 start play_music1;
 line_cross8();
 line_cross9();
 start play_music1;
 line_cross2();
 start play_music2;
 line_cross3();
 start play_music1;
 line_cross4();
 start play_music1;
 line_cross5();
 start play_music1;
 line_cross10();
 line_cross11();
 start play_music1;
 line_cross12();
}


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