Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Robots 1.17 KB | None | 0 0
  1. // добавляем датчики расстояния и освещенности
  2. const int V = 40; // скорость
  3. const int distF = 614; // 1 клетка при движении вперед
  4. const int distP = // нужно подобрать;
  5.  
  6. void left()
  7. {
  8.     nMotorEncoder[motorB] = 0;
  9.     motor[motorB] = -V;
  10.     motor[motorC] = V;
  11.     while (nMotorEncoder[motorB] < distP)
  12.     {
  13.         wait1Msec(50);
  14.     }
  15.     motor[motorB] = 0;
  16.     motor[motorC] = 0;
  17. }
  18.  
  19. void right()
  20. {
  21.     nMotorEncoder[motorB] = 0;
  22.     motor[motorB] = V;
  23.     motor[motorC] = -V;
  24.     while (nMotorEncoder[motorB] < distP)
  25.     {
  26.         wait1Msec(50);
  27.     }
  28.     motor[motorB] = 0;
  29.     motor[motorC] = 0;
  30. }
  31.  
  32. void forward()
  33. {
  34.     nMotorEncoder[motorB] = 0;
  35.     motor[motorB] = V;
  36.     motor[motorC] = V;
  37.     while (nMotorEncoder[motorB] < distF)
  38.     {
  39.         wait1Msec(50);
  40.     }
  41.     motor[motorB] = 0;
  42.     motor[motorC] = 0;
  43. }
  44.  
  45. task main()
  46. {
  47.     while (GetColorName[S3] != colorBlack)
  48.     {
  49.         if (SensorValue[S2] > 15) // справа свободно
  50.         {
  51.             right();
  52.             forward();
  53.         }
  54.         else
  55.         {
  56.             if (SensorValue[S1] > 15) // прямо свободно
  57.             {
  58.                 forward();
  59.             }
  60.             else
  61.             {
  62.                 left(); // иначе налево
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement