自动阶段是什么?What Is the Autonomous Period?
1.1 VEX 比赛流程1.1 VEX Match Structure
每场 VEX 比赛分为两个阶段:Each VEX match is split into two periods:
- 自动阶段(Autonomous)Autonomous Period:开场 15 秒,机器人自己动,不能碰遥控器: The first 15 seconds where the robot moves on its own -- no touching the controller
- 手动阶段(Driver Control)Driver Control Period:剩下 1 分 45 秒,操作手用遥控器控制: The remaining 1 minute 45 seconds where the driver controls the robot
自动阶段的分数可能决定一场比赛的胜负。很多比赛,双方手动阶段打得差不多,最终谁赢就看自动阶段多拿了几分。The autonomous score can decide a match. In many matches, both sides score similarly during driver control, so whoever scores more in autonomous wins.
15 秒听起来很短,但如果程序写得好,机器人可以:先拿最近的得分物 → 推到得分区 → 触碰色块。关键是先拿近的、容易的,不要贪多。15 seconds sounds short, but with good programming, the robot can: grab the nearest scoring object -> push it to the scoring zone -> touch the color pad. The key is to go for what's close and easy first -- don't be greedy.
1.2 autonomous() 函数1.2 The autonomous() Function
自动阶段的代码写在一个专门的函数里。比赛系统会在自动阶段开始时自动调用它。The autonomous code goes in a dedicated function. The competition system automatically calls it when the autonomous period begins.
// 比赛模板
competition Competition;
// 自动阶段:15 秒,机器人自己跑
void autonomous() {
// 你的自动代码写在这里
}
// 手动阶段:1 分 45 秒,遥控器控制
void userControl() {
// 你的手动代码写在这里
}
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(userControl);
while (true) {
wait(100, msec);
}
}
代码解释:Code explanation:
competition Competition;— 创建比赛对象Create a competition objectCompetition.autonomous(autonomous)— 告诉系统:自动阶段执行 autonomous 函数Tell the system: run the autonomous function during autonomous periodCompetition.drivercontrol(userControl)— 告诉系统:手动阶段执行 userControl 函数Tell the system: run the userControl function during driver controlwhile (true)— 主循环保持程序运行,不让程序退出Main loop keeps the program running, prevents it from exiting
// 比赛模板
competition Competition;
// 自动阶段:15 秒,机器人自己跑
void autonomous() {
// 你的自动代码写在这里
}
// 手动阶段:1 分 45 秒,遥控器控制
void userControl() {
// 你的手动代码写在这里
}
int main() {
Competition.autonomous(autonomous);
Competition.drivercontrol(userControl);
while (true) {
wait(100, msec);
}
}
代码解释:Code explanation:
competition Competition;— 创建比赛对象Create a competition objectCompetition.autonomous(autonomous)— 告诉系统:自动阶段执行 autonomous 函数Tell the system: run the autonomous function during autonomous periodCompetition.drivercontrol(userControl)— 告诉系统:手动阶段执行 userControl 函数Tell the system: run the userControl function during driver controlwhile (true)— 主循环保持程序运行,不让程序退出Main loop keeps the program running, prevents it from exiting
// PROS 自动提供这些函数,你只需要填内容
// 初始化(程序启动时运行)
void initialize() {
// 传感器初始化等
}
// 自动阶段:15 秒
void autonomous() {
// 你的自动代码写在这里
}
// 手动阶段:1 分 45 秒
void opcontrol() {
// 你的手动代码写在这里
}
PROS 的结构更简单:不需要手动注册回调,系统会自动在对应阶段调用对应函数。PROS has a simpler structure: no need to manually register callbacks -- the system automatically calls the corresponding function for each period.
1.3 自动 vs 手动:代码有什么不同?1.3 Autonomous vs Driver Control: What's Different in the Code?
手动阶段Driver control:代码在 while 循环里不断读遥控器输入,根据摇杆值控制电机。: Code runs in a while loop, constantly reading controller input and controlling motors based on joystick values.
自动阶段Autonomous:没有遥控器输入!代码是一步一步的指令序列——先做这个,再做那个,像菜谱一样。: No controller input! The code is a step-by-step sequence of commands -- do this first, then that, like a recipe.
// 手动阶段 — 不断循环读遥控器
void userControl() {
while (true) {
int speed = Controller1.Axis3.position();
LeftMotor.spin(forward, speed, percent);
wait(20, msec);
}
}
// 自动阶段 — 按顺序执行指令
void autonomous() {
// 第 1 步:前进
LeftMotor.spin(forward, 50, percent);
RightMotor.spin(forward, 50, percent);
wait(2, seconds);
// 第 2 步:停
LeftMotor.stop();
RightMotor.stop();
}
// 手动阶段 — 不断循环读遥控器
void userControl() {
while (true) {
int speed = Controller1.Axis3.position();
LeftMotor.spin(forward, speed, percent);
wait(20, msec);
}
}
// 自动阶段 — 按顺序执行指令
void autonomous() {
// 第 1 步:前进
LeftMotor.spin(forward, 50, percent);
RightMotor.spin(forward, 50, percent);
wait(2, seconds);
// 第 2 步:停
LeftMotor.stop();
RightMotor.stop();
}
// 手动阶段 — 不断循环读遥控器
void opcontrol() {
pros::Controller master(pros::E_CONTROLLER_MASTER);
while (true) {
int speed = master.get_analog(ANALOG_LEFT_Y);
left_motor.move(speed);
pros::delay(20);
}
}
// 自动阶段 — 按顺序执行指令
void autonomous() {
// 第 1 步:前进
left_motor.move(64);
right_motor.move(64);
pros::delay(2000); // 2000 毫秒 = 2 秒
// 第 2 步:停
left_motor.move(0);
right_motor.move(0);
}
1.4 策略:先做什么?1.4 Strategy: What to Do First?
写自动程序之前,先想清楚策略:Before writing autonomous code, plan your strategy:
- 观察场地Observe the field:哪些得分物离起点最近?: Which scoring objects are closest to the starting position?
- 排优先级Prioritize:先拿容易拿的,稳稳得分: Go for easy ones first, score reliably
- 估时间Estimate time:15 秒不够做很多事,2-3 个动作就差不多了: 15 seconds isn't enough for much -- 2-3 actions is about right
- 考虑对手Consider opponents:对面的机器人会不会挡路?: Will the opposing robot block your path?
新手最容易犯的错:想在 15 秒内做太多事。结果什么都没做完,还不如只做一件事做到位。The most common beginner mistake: trying to do too much in 15 seconds. Ending up finishing nothing is worse than doing one thing well.