Intakes and arms
Give each mechanism a small interface with a clear start, stop, and failure behavior.
Shared configuration. The arm example adds a motor on Port 4 with a 36:1 cartridge. Shared configuration ↗
On this pageStart and stop an intake
Start and stop an intake
This excerpt uses the intake motor from Simple autonomous, on Port 3. spin() starts a continuous motor command and returns immediately. The intake keeps running until another command changes it. This lets it run during a drive movement without creating a separate task.
Start the intake, call a movement helper, and stop the intake before handling either success or failure. If you return from autonomous while a mechanism is running, an expected stop later in the routine will never execute.
intake.spin(forward, 50, pct); bool reached = driveDistance(24); intake.stop(coast); if (!reached) return;
References: VEX Robotics: Motor and Motor Group — C++ API (opens in a new tab)
Establish an arm zero
Encoder zero is a numerical reference, not proof that the arm is in a known physical position. Place the arm at a repeatable reference before setting its position. An absolute sensor or a limit switch can support a more deliberate homing routine.
A motor encoder measures motor output rotation. External gearing changes the relationship between motor degrees and arm degrees. Mechanical travel limits must come from your robot’s geometry, not the example target below.
References: PROS: Motors tutorial (opens in a new tab) · VEX Robotics: Motor and Motor Group — C++ API (opens in a new tab)
Move an arm to a target
This helper uses bounded proportional output, a tolerance interval, and a timeout. Positive targets must command movement away from the zero reference in the intended direction. Confirm that direction at low output before using closed-loop control.
After establishing the arm zero, call moveArmTo(90) inside autonomous() to target 90 motor degrees. The example ends with hold braking. It is an educational position controller, not a complete gravity-compensated arm controller. Tune the gain and output limit; ensure every requested target is within measured mechanical limits.
motor arm(PORT4, ratio36_1, false);
bool moveArmTo(double targetMotorDegrees, double timeoutMs = 1800) {
if (!std::isfinite(targetMotorDegrees) || timeoutMs <= 0) {
arm.stop(hold);
return false;
}
timer elapsed;
elapsed.reset();
int settledMs = 0;
while (elapsed.time(msec) < timeoutMs) {
double error = targetMotorDegrees - arm.position(degrees);
double output = limit(0.3 * error, -25, 25);
arm.spin(forward, output, pct);
settledMs = std::fabs(error) < 3 ? settledMs + 10 : 0;
if (settledMs >= 100) { arm.stop(hold); return true; }
wait(10, msec);
}
arm.stop(hold);
return false;
}References: VEX Robotics: Motor and Motor Group — C++ API (opens in a new tab)
Choose a stop mode
Holding can require sustained motor effort under load. Check the mechanism’s balance, gearing, and temperature rather than assuming hold will solve a mechanically overloaded design.
| Mode | Use |
|---|---|
| coast | Allow the mechanism to spin down without active braking. |
| brake | Apply braking to reduce motion. |
| hold | Actively try to hold the stopped motor position. |
References: VEX Robotics: Motor and Motor Group — C++ API (opens in a new tab)
Keep one owner per mechanism
Do not let an autonomous helper and a background task continuously send competing commands to the same motor. Decide which loop owns the mechanism and pass it requests if other code needs a change.
Start with sequential code. Add concurrency when it solves a specific timing problem, and define what happens when autonomous ends, an action times out, or the next mode begins.
References: PROS: Multitasking and synchronization (opens in a new tab)
Sources for this guide
Examples are written for VEXcode C++. PROS and LemLib references explain related concepts; their APIs are different.
- VEX RoboticsMotor and Motor Group — C++ API (opens in a new tab)
VEXcode motor construction, encoder position, signed spin commands, and braking.
- PROSMotors tutorial (opens in a new tab)
Comparison of motor configuration, relative/absolute positioning, and firmware motion control. PROS code uses a different API.
- PROSMultitasking and synchronization (opens in a new tab)
Why loops need delays and why concurrent tasks need an explicit ownership and synchronization model. PROS task APIs are not VEXcode APIs.