Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // добавляем датчики расстояния и освещенности
- const int V = 40; // скорость
- const int distF = 614; // 1 клетка при движении вперед
- const int distP = // нужно подобрать;
- void left()
- {
- nMotorEncoder[motorB] = 0;
- motor[motorB] = -V;
- motor[motorC] = V;
- while (nMotorEncoder[motorB] < distP)
- {
- wait1Msec(50);
- }
- motor[motorB] = 0;
- motor[motorC] = 0;
- }
- void right()
- {
- nMotorEncoder[motorB] = 0;
- motor[motorB] = V;
- motor[motorC] = -V;
- while (nMotorEncoder[motorB] < distP)
- {
- wait1Msec(50);
- }
- motor[motorB] = 0;
- motor[motorC] = 0;
- }
- void forward()
- {
- nMotorEncoder[motorB] = 0;
- motor[motorB] = V;
- motor[motorC] = V;
- while (nMotorEncoder[motorB] < distF)
- {
- wait1Msec(50);
- }
- motor[motorB] = 0;
- motor[motorC] = 0;
- }
- task main()
- {
- while (GetColorName[S3] != colorBlack)
- {
- if (SensorValue[S2] > 15) // справа свободно
- {
- right();
- forward();
- }
- else
- {
- if (SensorValue[S1] > 15) // прямо свободно
- {
- forward();
- }
- else
- {
- left(); // иначе налево
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement