0 / 6 页已完成

用时间控制机构Controlling Mechanisms with Time

1.1 最简单的方法:转几秒停下来1.1 The Simplest Way: Spin for a Few Seconds

在 Level 1 里,我们学会了让电机转动。现在假设机器人有一个升降臂(Lift),我们想让它升到一定高度。In Level 1, we learned how to make motors spin. Now suppose your robot has a lift arm, and we want to raise it to a certain height.

最直觉的方法:让电机转,等几秒,然后停。The most intuitive way: spin the motor, wait a few seconds, then stop.

C++ (VEXcode)
// 升降臂上升 2 秒
LiftMotor.spin(forward);
wait(2, seconds);
LiftMotor.stop();
C++ (VS Code)
// 升降臂上升 2 秒
LiftMotor.spin(forward);
wait(2, seconds);
LiftMotor.stop();
C++ (PROS)
// 升降臂上升 2 秒
LiftMotor.move(127);
pros::delay(2000);
LiftMotor.move(0);

逻辑很简单:开始转 → 等一会儿 → 停The logic is simple: start spinning → wait → stop.

1.2 先碰壁再教1.2 Learn by Hitting the Wall

时间控制看起来很好用,但你很快会发现一个问题:Time-based control seems great, but you'll quickly discover a problem:

问题:每次升的高度不一样!Problem: Different Height Every Time!

同样是 wait(2, seconds),有时候臂升得高,有时候升得低。为什么?With the same wait(2, seconds), sometimes the arm goes higher, sometimes lower. Why?

因为电池电压会变。充满电的时候电机转得快,电量低的时候电机转得慢。同样的 2 秒,转过的距离不一样。Because battery voltage changes. When fully charged, motors spin faster; when low on battery, motors spin slower. The same 2 seconds covers a different distance.

除了电池电压,还有这些因素会影响结果:Besides battery voltage, these factors also affect the result:

核心教训Key Lesson

时间控制是"开环"的 — 你不知道电机实际转了多少。后面学了传感器(Level 3),就能用"闭环"方式精确控制。Time-based control is "open-loop" — you don't know how far the motor actually moved. After learning sensors (Level 3), you can use "closed-loop" control for precision.

但时间控制也不是完全没用!对精度要求不高的动作(比如吐球、短暂启动),用时间控制完全够了。But time-based control isn't useless! For actions that don't need precision (like ejecting balls or brief starts), it works just fine.

1.3 动手练习1.3 Practice

动手试试Try It Out

假设你的机器人有一个吸球电机(Intake),写代码让它:Suppose your robot has an intake motor. Write code to make it:

  1. 正转吸球 3 秒Spin forward to intake balls for 3 seconds
  2. 停 1 秒Stop for 1 second
  3. 反转吐球 1 秒Spin reverse to eject balls for 1 second
  4. 停下来Stop
检查点:预测结果Checkpoint: Predict the Result
你的升降臂程序是 spin(forward) → wait(2秒) → stop()
比赛打到第三场,电池只剩 60%。和第一场满电相比,2 秒后臂的位置会怎样?
Your lift program is spin(forward) → wait(2s) → stop().
By the third match, the battery is down to 60%. Compared to the first match at full charge, where will the arm be after 2 seconds?