VEXcode Pro V5 (C++) code for a VEX Robotics Competition robot from the 2020–21 Change Up season. The core of it is tracking-wheel odometry: two V5 rotation sensors and the inertial sensor keep a running estimate of where the robot is on the field, and the drive functions use the heading for field-oriented moves.
| Device | Port | Notes |
|---|---|---|
TR, TL, BR, BL drive motors |
1–4 | 18:1 (green) cartridges; holonomic drive, diagonal wheel pairs driven together |
RIntake, LIntake motors |
5, 6 | configured, not used in code yet |
yRot rotation sensor |
14 | y (forward) tracking wheel, reversed |
xRot rotation sensor |
15 | x (sideways) tracking wheel |
Inertial16 inertial sensor |
16 | heading |
- Startup (
Initinsrc/Definitions.cpp): stops the drive, calibrates the inertial sensor (blocks until done), zeroes both tracking wheels, and sets the tuning constants and the starting position (0, 0). - Background thread (
BckGroundinsrc/Util.cpp, about every 20 ms): corrects the heading, runs one odometry step, and prints x, y and heading to the Brain screen. - Odometry (
src/Odom.cpp): takes the change in each tracking wheel and in heading since the last step, uses the arc-chord approximation to get the local displacement, rotates it into field coordinates by the heading, and adds it toxPos/yPos. - Heading correction (
Correctinsrc/Util.cpp): adds a drift correction proportional to how far the robot has turned in total (inertError, about 2.4 %).
TurnInPlace(deg, slowDown, minSpeed)turns to an absolute heading. Speed is the remaining error divided byslowDown, plusminSpeed, and the error is wrapped to ±180° so the robot turns the short way round.StrafeXY(x, y, speed, decel)drives toward an (x, y) offset in tracking-wheel degrees, with the direction corrected for the robot's heading. It stops once both tracking wheels are within 5° of the target.SetVelocityTheta(theta, speed, state)sets the drive moving at an angle: robot-relative whenstateis"local", field-relative otherwise. It does not stop the drive on its own.
Open idk.v5code in VEXcode Pro V5, build, and download to the V5 Brain. main() currently initializes the sensors and starts the odometry thread; the StrafeXY test call is commented out.
- Positions are in tracking-wheel degrees, not inches.
Print()insrc/Util.cpptakes achar, so the values it shows on the Brain screen are truncated to a single character.yTurnOffset,xTurnOffsetand thedecelargument ofStrafeXYare set but not used yet.