Introduction
Reaper is a PROS template for VEX V5 robots. It's built on EZ-Template, with some features adapted from RW-Template.
What's included
- Drive & odometry: EZ's drive, odometry, motion exits, redundant-IMU handling and EZ-Units (
24_in,90_deg). - MCL: distance-sensor localization against the field walls, kept in sync with odometry.
- Route selector: match slots, skills slots, and a red/blue auto toggle.
- Driver controls: arcade or tank, joystick curves, active brake, and a Down + B shortcut to test autons without field control.
- Lift PID: hold-on-release, one-button return, and autonomous position commands.
- Extras: roller color control and VMP vibration monitoring (observe-only).
The source compiles and passes host tests, but every robot is different. Check ports, directions and tuning on your own robot before relying on it in competition.
Installation
Reaper is a source project. You open the whole folder in PROS rather than applying a template archive.
- Download Reaper
Grab the latest Reaper project folder and unzip it somewhere you'll keep it.
- Open it in PROS
In VS Code with the PROS extension, open the
Reaperfolder (the one containingproject.pros). - Configure your robot
Set your ports, wheel size and RPM first. See Configure your robot.
- Build and upload
pros mu
Don't install the precompiled EZ-Template archive over this folder. It would bypass Reaper's selector and odometry changes.
PROS kernel 4.2.2 and liblvgl 9.2.0 are included. Reaper builds as an application (IS_LIBRARY=0).
Project structure
These are the only files you need to touch.
| File | What goes in it |
|---|---|
robot_hardware.hpp | Every port and sensor position: drive, IMUs, trackers, distance sensors and mechanisms |
main.cpp | Driver control, button bindings and localization startup |
lift_settings.hpp | Lift travel limit, presets, PID and gravity compensation |
match_routes.cpp | Your match routes |
skills_routes.cpp | Your skills routes |
Configure your robot
Every port and sensor position lives in robot_hardware.hpp, between the SETTINGS and END SETTINGS markers. Edit that section, then rebuild and upload. No port edits anywhere else.
0means disabled. The device isn't created.- A negative motor port reverses that motor. Fix direction here, not by negating power in code.
- Smart ports are 1 to 21. Never use one port for two devices.
Drivetrain
Use as many motors per side as your drive has. Wheel RPM is measured at the wheel, after gearing (a 600 RPM cartridge geared 36:48 is 450).
static inline const std::vector<int> DRIVE_LEFT_PORTS{-1, -2, -3};
static inline const std::vector<int> DRIVE_RIGHT_PORTS{4, 5, 6};
static constexpr double DRIVE_WHEEL_DIAMETER = 3.25; // inches
static constexpr double DRIVE_WHEEL_RPM = 450.0;
IMUs
static constexpr int DRIVE_IMU_1_PORT = 7; // required for turns and odometry
static constexpr int DRIVE_IMU_2_PORT = 0; // optional second IMU, 0 disables
With two IMUs, EZ averages them and can catch one drifting.
Tracking wheels
Fill in every field, then set enabled to true.
// enabled, type, smart_port, ADI pair, diameter, offset, ratio
static constexpr hardware::TrackerConfig LEFT_TRACKER{
true, hardware::TrackerType::Rotation, 13, {0, 0}, 2.75, 4.0, 1.0};
| Field | Meaning |
|---|---|
type | Rotation (V5 rotation sensor), ADI (encoder on the brain's 3-wire ports) or ExpanderADI (encoder on a 3-wire expander) |
smart_port | The rotation sensor's or expander's port. Ignored for ADI. |
adi_ports | Encoder channels, e.g. {'A', 'B'}. {0, 0} for Rotation. |
| diameter, offset, ratio | Wheel size (in), distance from the turning center (in), and gear ratio |
Distance sensors
The four distance sensors for localization are set here too. See MCL.
Mechanisms
Every mechanism motor and sensor is set in the same SETTINGS block, so all your wiring is in one place.
Drive controls
Pick exactly one drive mode in opcontrol(). Running two makes the second overwrite the first.
// chassis.opcontrol_tank(); // tank
chassis.opcontrol_arcade_standard(ez::SPLIT); // split arcade (default)
// chassis.opcontrol_arcade_standard(ez::SINGLE); // single-stick arcade
// chassis.opcontrol_arcade_flipped(ez::SPLIT); // flipped split arcade
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // flipped single arcade
Curves & active brake
Set in initialize():
chassis.opcontrol_curve_buttons_toggle(true); // adjust the curve live from the controller
chassis.opcontrol_drive_activebrake_set(0.0); // active brake kP, ~2 recommended, 0 = off
chassis.opcontrol_curve_default_set(0.0, 0.0); // default curve (remove if using an SD card)
Test an auton: Down + B
With field control disconnected, press Down + B to run the selected route. Press it again to cancel at any point, even mid-PID-wait. Joystick drive is paused while it runs.
Lift
The lift runs on its own background task, so it can move while the chassis drives.
| Input | Behavior |
|---|---|
| Raise button (hold) | Lift up. Releasing holds the height. |
| Lower button (hold) | Lift down. Releasing holds the height. |
| Both together | Hold position |
| Return button (press) | Return to the startup height |
Changing the buttons
Every lift button is configurable. Each one is just an argument to lift::driver_update() in opcontrol() in main.cpp, so swap in any controller button you want:
lift::driver_update(
master.get_digital(pros::E_CONTROLLER_DIGITAL_R2), // raise
master.get_digital(pros::E_CONTROLLER_DIGITAL_L2), // lower
master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_Y)); // return
Use get_digital for hold buttons and get_digital_new_press for the return button, so it fires once per press.
EZ's joystick-curve buttons are on by default (opcontrol_curve_buttons_toggle(true)) and use Left/Right and Y/A. If you bind the lift to one of those, either turn the curve buttons off or move them.
Lift settings
Travel limit, presets, PID and gravity compensation live in lift_settings.hpp.
c.max_height = 1150; // your measured safe top, in motor degrees
c.allow_unbounded_jog = false; // true only while measuring travel
c.full_power_manual_jog = true; // false for a smoother, slower jog
The lift's position at power-on becomes zero, so always start with the lift at its lowest point.
Route selector
Reaper's brain-screen selector has match slots, skills slots, and a red/blue auto toggle. Pick a route before the match and it runs in autonomous.
Writing a route
Every slot is already registered. Rename its label and write movements inside its [] { ... } block. Keep the function name (match_01) as it is.
// match_routes.cpp
ez::Auton match_01() {
return {"Right Side", "Score, then grab the stack", [] {
chassis.pid_drive_set(24_in, 80);
chassis.pid_wait();
chassis.pid_turn_set(90_deg, 80);
chassis.pid_wait();
}};
}
Registration sits at the bottom of the same file:
void register_routes() {
ez::as::auton_selector.autons_add({match_01(), match_02(), /* … */ match_15()});
ez::as::auton_selector.skills_add({skills_01(), skills_02(), skills_03()});
}
Every route starts after the shared resets in autonomous() (pose 0, 0, 0). Use short labels; long ones get shortened on the button.
Movements
Speed is a power cap from 0 to 127. Forward is +Y, +X is right, and positive headings turn clockwise. A setter starts a motion and returns right away; a wait blocks until it's done. A new setter replaces the current motion; it doesn't queue.
Drive a distance
chassis.pid_drive_set(24_in, 80); // negative distance drives backward
chassis.pid_wait();
Turn
pid_turn_set turns to an absolute heading. Calling 90° twice doesn't turn twice. Use pid_turn_relative_set to add to the target.
chassis.pid_turn_set(90_deg, 80);
chassis.pid_wait();
chassis.pid_turn_relative_set(45_deg, 80); // target becomes 135°
chassis.pid_wait();
Turn to face a field point (needs a valid pose):
chassis.pid_turn_set(ez::united_pose{24_in, 24_in}, ez::fwd, 80);
chassis.pid_wait();
Swing
One side drives while the other holds. ez::LEFT_SWING means the left side moves.
chassis.pid_swing_set(ez::LEFT_SWING, 45_deg, 80);
chassis.pid_wait();
chassis.pid_swing_set(ez::LEFT_SWING, 90_deg, 80, 30); // wider swing: other side at 30
chassis.pid_wait();
Move to a point
chassis.pid_odom_set(ez::united_odom{{24_in, 36_in}, ez::fwd, 80});
chassis.pid_wait();
chassis.pid_odom_set(ez::united_odom{{0_in, 0_in}, ez::rev, 60}); // drive back in reverse
chassis.pid_wait();
Boomerang
Add a heading to arrive at a point facing a direction. Leave room for the curve.
chassis.pid_odom_boomerang_set(ez::united_odom{{24_in, 36_in, 90_deg}, ez::fwd, 80});
chassis.pid_wait();
Pure pursuit paths
std::vector<ez::united_odom> path = {
{{0_in, 24_in}, ez::fwd, 80},
{{24_in, 36_in}, ez::fwd, 80},
{{36_in, 48_in}, ez::fwd, 60}
};
chassis.pid_odom_set(path); // injects + smooths points
chassis.pid_wait();
Variants: pid_odom_pp_set (raw points), pid_odom_injected_pp_set (inject only), pid_odom_smooth_pp_set (inject + smooth). Smoothing rounds corners. For a hard stop at a point, use a separate point move.
Waits & chaining
| Wait | Continues when |
|---|---|
pid_wait() | The motion settles or an exit condition ends it |
pid_wait_until(12_in) | An encoder drive reaches that distance from its start |
pid_wait_until(45_deg) | A turn or swing crosses that absolute heading |
pid_wait_quick() | The target is crossed, without the full settle delay |
pid_wait_quick_chain() | Close enough to flow straight into the next command |
pid_wait_until_index(i) | The path passes waypoint i |
pid_wait_until_point(p) | An odom motion passes a field point |
Checkpoints
chassis.pid_drive_set(36_in, 100);
chassis.pid_wait_until(12_in); // 12" in…
chassis.pid_speed_max_set(60); // …slow down for the rest
chassis.pid_wait();
Chaining
chassis.pid_drive_set(24_in, 80);
chassis.pid_wait_quick_chain();
chassis.pid_turn_set(90_deg, 80);
chassis.pid_wait(); // full wait at the end of the chain
Returning from a wait doesn't prove the target was reached. It can also exit on timeout, velocity or interference. Check chassis.interfered where it matters.
Pose & odometry
Set the real start pose at the top of a route if it isn't 0, 0, 0. Pose setters change the estimate; they don't move the robot.
chassis.odom_xyt_set(36_in, 36_in, 90_deg);
chassis.pid_odom_set(ez::united_odom{{60_in, 36_in}, ez::fwd, 70});
chassis.pid_wait();
| Function | Purpose |
|---|---|
odom_xyt_set(x, y, h) | Set the full pose |
odom_xy_set(x, y) | Set position only |
odom_x_get() / odom_y_get() / odom_theta_get() | Read the pose |
drive_angle_set(angle) | Set IMU heading and heading target together |
drive_sensor_left() / drive_sensor_right() | Drivetrain distance in inches |
(0, 0) must be the field center, not your starting corner.
Tuning constants
Shared PID, exit and slew settings live in default_constants(). Gains are P, I, D, start_I.
void default_constants() {
chassis.pid_drive_constants_set(5.0, 0.0, 0.0);
chassis.pid_heading_constants_set(5.0, 0.0, 0.0);
chassis.pid_turn_constants_set(4.8, 0.0, 5.3, 0.0);
chassis.pid_swing_constants_set(5.0, 0.0, 0.0);
// small error, small-error time, big error, big-error time, velocity, current
chassis.pid_drive_exit_condition_set(90_ms, 1_in, 250_ms, 3_in, 500_ms, 500_ms);
chassis.pid_turn_exit_condition_set(90_ms, 3_deg, 250_ms, 7_deg, 500_ms, 500_ms);
// how close pid_wait_quick_chain() needs to be before moving on
chassis.pid_drive_chain_constant_set(5_in);
chassis.pid_turn_chain_constant_set(5_deg);
chassis.slew_drive_constants_set(3_in, 50);
chassis.odom_turn_bias_set(0.9);
chassis.odom_look_ahead_set(7_in);
chassis.odom_boomerang_distance_set(16_in);
chassis.pid_angle_behavior_set(ez::shortest);
}
- Raise kP
Until the robot oscillates around the target, then back off a little.
- Add kD
Until the oscillation damps out and it settles fast.
- Add kI only if needed
If it consistently stops just short. Keep it small.
Mechanisms in auton
The lift has its own task, so it can move while the chassis drives. chassis.pid_wait() only waits for the drive. Use lift::wait_until_settled() for the lift.
if (!lift::move_to(200.0)) return; // motor degrees, measure your own height
chassis.pid_drive_set(24_in, 70);
chassis.pid_wait();
if (!lift::wait_until_settled()) return;
// score here
lift::return_to_start();
roller::maintain_for(ms) holds the roller on the selected color for a set time.
MCL
Reaper's Monte Carlo localization uses distance sensors against the field walls to correct odometry's X/Y drift. Heading still comes from the IMUs. There's one pose, and EZ's motion control uses it.
Configure sensors
In robot_hardware.hpp, each distance sensor is a localization::Mount: {port, x, y, heading, scale}. Port 0 disables a sensor, and if all four are 0, MCL stays off.
// port, x, y, heading, scale
static constexpr localization::Mount DISTANCE_FRONT{11, 0.0, 6.0, 0.0, 1.0};
static constexpr localization::Mount DISTANCE_RIGHT{12, 5.0, 0.0, 90.0, 1.0};
static constexpr localization::Mount DISTANCE_BACK {0, 0.0, 0.0, 180.0, 1.0};
static constexpr localization::Mount DISTANCE_LEFT {0, 0.0, 0.0, 270.0, 1.0};
static constexpr double FIELD_HALF_SIZE = 70.25; // center to wall, in inches
static constexpr unsigned DISTANCE_SENSOR_DELAY_MS = 40;
static constexpr double DISTANCE_RESET_MAX_JUMP = 12.0; // biggest wall-reset correction
main.cpp starts localization with these settings at startup. Leave scale at 1.0 unless a sensor reads consistently long or short.
- Measure from the robot's turning center to the sensor face. X is right, Y is forward, and angles are clockwise (front 0, right 90, back 180, left 270).
(0, 0)is the field center, and heading 0 faces +Y.- Corrections are capped at 0.15" per update, and they're skipped while turning fast or when readings disagree.
- Readings outside 1.5–60" are ignored.
Distance sensor reset
DSR snaps one coordinate to a wall using a single sensor reading. Stop the robot first. It needs a clear view of the wall.
chassis.pid_targets_reset();
chassis.drive_mode_set(ez::DISABLE, true);
chassis.drive_set(0, 0);
pros::delay(200);
bool applied = localization::distance_reset(localization::Sensor::front);
// also Sensor::right, ::back, ::left. If false, the pose is unchanged.
const auto pose = localization::getPose(); // same pose EZ uses
Settings
Most belong in default_constants(). A change made inside a route lasts until it's changed again.
| Setting | Effect |
|---|---|
pid_speed_max_set(speed) | Cap the current motion's power |
pid_*_constants_set(...) | Drive, heading, turn, swing, odom angular and boomerang gains |
pid_*_exit_condition_set(...) | When drive, turn, swing and odom moves count as done |
pid_*_chain_constant_set(...) | How early a chained move hands off |
slew_*_constants_set(dist, min) | Ramp up at the start of a move |
pid_angle_behavior_set(b) | ez::shortest, longest, left_turn, right_turn, raw |
odom_turn_bias_set(v) | Turning vs. driving priority in odom moves (max 1.0) |
odom_look_ahead_set(d) | Pure pursuit look-ahead |
odom_boomerang_distance_set(d) | Max boomerang lead distance |
odom_boomerang_dlead_set(v) | Boomerang lead scaling |
drive_brake_set(mode) | MOTOR_BRAKE_COAST, _BRAKE or _HOLD |
Credits & help
Reaper started as an edited version of EZ-Template and grew from there. Thank you to the EZ-Robotics team. Some features are adapted from RW-Template.
- LightLib by Alex Bryan, for helping with parts of the auton selector.
- EZ-Template source is covered by MPL-2.0 (
LICENSE.md). - RW-Template-derived files keep their MIT notice (
licenses/RW-Template.txt).
Email notzaron@gmail.com or find Okimzaron on Discord.
Reaper v1.0 beta