0 / 5 页已完成

综合挑战Comprehensive Challenge

5.1 挑战目标5.1 Challenge Goal

写一个完整的手动控制程序,包含:Write a complete manual control program that includes:

  1. 底盘:Arcade 驾驶(含死区处理)Drivetrain: Arcade drive (with deadzone handling)
  2. 机构电机:用按钮控制一个额外的电机(比如机械臂或进球机构)Mechanism motor: use buttons to control an extra motor (like an arm or intake)
没有框架,从头开始写No Template — Write from Scratch

这次不给框架代码。从声明电机开始,一步步搭建你自己的程序。下面有提示和参考答案,但请先自己试。This time there's no starter code. Start by declaring motors and build your program step by step. Hints and answers are below, but try on your own first.

5.2 你需要的知识5.2 Knowledge You Need

回顾一下前面学过的:Let's review what we've learned:

读取按钮Reading Buttons

遥控器上有很多按钮(R1、R2、L1、L2、A、B、X、Y 等),可以用来控制机构。The controller has many buttons (R1, R2, L1, L2, A, B, X, Y, etc.) that can be used to control mechanisms.

C++ (VEXcode)
// 检查 R1 按钮是否正在被按下
if (Controller1.ButtonR1.pressing()) {
    // R1 被按着,做点什么
}

// 检查 R2 按钮
if (Controller1.ButtonR2.pressing()) {
    // R2 被按着,做点什么
}
C++ (VS Code)
// 检查 R1 按钮是否正在被按下
if (Controller1.ButtonR1.pressing()) {
    // R1 被按着,做点什么
}

// 检查 R2 按钮
if (Controller1.ButtonR2.pressing()) {
    // R2 被按着,做点什么
}
C++ (PROS)
// 检查 R1 按钮是否正在被按下
if (controller.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) {
    // R1 被按着,做点什么
}

// 检查 R2 按钮
if (controller.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) {
    // R2 被按着,做点什么
}

5.3 动手写吧5.3 Start Coding

挑战要求Challenge Requirements

写一个完整程序,实现:Write a complete program that:

  1. 声明左右底盘电机(端口 1 和 2)和一个机构电机(端口 3)Declare left and right drivetrain motors (ports 1 and 2) and a mechanism motor (port 3)
  2. 底盘用 Arcade 驾驶,带死区处理Use Arcade drive for the drivetrain with deadzone handling
  3. 按 R1 → 机构电机正转;按 R2 → 机构电机反转;都不按 → 机构电机停Press R1 → mechanism motor forward; press R2 → mechanism motor reverse; neither → mechanism motor stop

5.4 提示5.4 Hints

提示 1:程序整体结构Hint 1: Overall Program Structure

你的程序大致是这样的结构:Your program should roughly follow this structure:

  1. 声明电机(在 main/opcontrol 外面)Declare motors (outside main/opcontrol)
  2. while(true) 里:读摇杆 → 死区处理 → 算左右轮速 → 发指令Inside while(true): read joysticks → deadzone → calculate wheel speeds → send commands
  3. 在同一个循环里:读按钮 → 控制机构电机In the same loop: read buttons → control mechanism motor
  4. 循环末尾加 wait(20)Add wait(20) at the end of the loop
提示 2:机构电机的逻辑Hint 2: Mechanism Motor Logic

if / else if / else 判断:Use if / else if / else to decide:

C++ (伪代码)
if (R1 被按下) {
    机构电机正转;
} else if (R2 被按下) {
    机构电机反转;
} else {
    机构电机停;
}
提示 3:机构电机用什么停止模式?Hint 3: What Stop Mode for the Mechanism Motor?

如果是机械臂(需要保持位置),用 hold。如果是进球轮(不需要保持),用 coastbrakeIf it's an arm (needs to hold position), use hold. If it's an intake wheel (doesn't need to hold), use coast or brake.

5.5 参考答案5.5 Reference Answer

先自己写再看答案Write Your Own First

参考答案只是其中一种写法,你的写法可能不一样,只要功能对就行。The reference answer is just one way to write it. Your approach might be different — as long as it works, it's fine.

检查点:综合理解Checkpoint: Comprehensive Understanding
在上面的程序中,如果把 while(true) 循环里的 wait(20, msec) 删掉,会发生什么?In the program above, what happens if you remove wait(20, msec) from the while(true) loop?
检查点:调试思维Checkpoint: Debugging Mindset
你写好程序下载到机器人上,发现推摇杆向前时机器人在原地转圈。最可能的原因是什么?You download your program to the robot and find that when you push the joystick forward, the robot spins in place. What's the most likely cause?