0 / 5 页已完成

为什么时间控制不够?Why Isn't Time-Based Control Enough?

1.1 回顾:用时间控制移动1.1 Review: Moving with Time Control

在 Level 1,我们学过用时间控制机器人走直线:In Level 1, we learned how to make the robot drive straight using time control:

C++ (VEXcode)
// 向前走 2 秒
LeftMotor.spin(forward);
RightMotor.spin(forward);
wait(2, seconds);
LeftMotor.stop();
RightMotor.stop();
C++ (VS Code)
// 向前走 2 秒
LeftMotor.spin(forward);
RightMotor.spin(forward);
wait(2, seconds);
LeftMotor.stop();
RightMotor.stop();
C++ (PROS)
// 向前走 2 秒
left_motor.move(127);
right_motor.move(127);
pros::delay(2000);
left_motor.move(0);
right_motor.move(0);

看起来挺好用的,对吧?但是试试看——Seems to work fine, right? But try this --

1.2 问题来了:跑 3 次,停 3 个位置1.2 The Problem: Run 3 Times, Stop at 3 Different Places

把上面的代码烧进机器人,连续跑 3 次,你会发现:Upload the code above to your robot and run it 3 times in a row. You'll find:

同样的代码,每次停的位置都不一样!Same code, different stopping position every time!

为什么?Why?

时间控制的问题在于:你只告诉机器人"跑多久",但没告诉它"跑多远"。The problem with time control is: you only tell the robot "how long to run," not "how far to go."

影响距离的因素有很多:Many factors affect the actual distance:

1.3 转弯也一样不准1.3 Turning Is Just as Inaccurate

用时间控制转弯更惨:Time-based turning is even worse:

C++ (VEXcode)
// 想转 90 度
LeftMotor.spin(forward);
RightMotor.spin(reverse);
wait(0.8, seconds);  // 试出来的时间
LeftMotor.stop();
RightMotor.stop();
C++ (VS Code)
// 想转 90 度
LeftMotor.spin(forward);
RightMotor.spin(reverse);
wait(0.8, seconds);  // 试出来的时间
LeftMotor.stop();
RightMotor.stop();
C++ (PROS)
// 想转 90 度
left_motor.move(127);
right_motor.move(-127);
pros::delay(800);  // 试出来的时间
left_motor.move(0);
right_motor.move(0);

0.8 秒是你调试时"试出来"的。换了电池、换了场地、甚至换了个轮子,这个数就不准了。0.8 seconds is a value you "figured out" during testing. Change the battery, change the field, or even change a wheel, and that number is no longer accurate.

比赛场上没时间给你一次次试数值。你需要更靠谱的方法。There's no time at a competition to keep tweaking values. You need a more reliable approach.

1.4 解决方案:让机器人"看到"自己1.4 The Solution: Let the Robot "See" Itself

人走路不会闭着眼睛数秒数。你会自己走到哪了,然后决定要不要继续走。When you walk, you don't close your eyes and count seconds. You look at where you are and decide whether to keep going.

机器人也可以这样做——用传感器Robots can do the same thing -- with sensors.

传感器的作用What Sensors Do

传感器让机器人能"感知"自己的状态:Sensors let the robot "feel" its own state:

有了传感器,代码从"跑 2 秒"变成"跑到 60 厘米":With sensors, the code changes from "run for 2 seconds" to "run to 60 cm":

接下来几节课,我们一个个来学这些传感器。In the next few lessons, we'll learn about each of these sensors one by one.

检查点Checkpoint
用时间控制机器人移动,为什么每次停的位置不一样?When using time to control robot movement, why does it stop at a different position each time?