General
Tracking Wheels
For a more in depth guide to Tracking Wheels look at this guide.
odom_tracker_left_set()
Sets the parallel left tracking wheel for odometry.
input an ez::tracking_wheel
- Prototype
- Example
void odom_tracker_left_set(tracking_wheel* input);
ez::tracking_wheel right_tracker({-'A', -'B'}, 2.75, 4.0); // ADI Encoders
ez::tracking_wheel left_tracker(1, {'C', 'D'}, 2.75, 4.0); // ADI Encoders plugged into a Smart port
ez::tracking_wheel horiz_tracker(1, 2.75, 4.0); // Rotation sensors
void initialize() {
// Print our branding over your terminal :D
ez::ez_template_print();
pros::delay(500); // Stop the user from doing anything while legacy ports configure
chassis.odom_tracker_right_set(&right_tracker);
chassis.odom_tracker_left_set(&left_tracker);
chassis.odom_tracker_back_set(&horiz_tracker); // Replace `back` to `front` if your tracker is in the front!
}
odom_tracker_right_set()
Sets the parallel right tracking wheel for odometry.
input an ez::tracking_wheel
- Prototype
- Example
void odom_tracker_right_set(tracking_wheel* input);
ez::tracking_wheel right_tracker({-'A', -'B'}, 2.75, 4.0); // ADI Encoders
ez::tracking_wheel left_tracker(1, {'C', 'D'}, 2.75, 4.0); // ADI Encoders plugged into a Smart port
ez::tracking_wheel horiz_tracker(1, 2.75, 4.0); // Rotation sensors
void initialize() {
// Print our branding over your terminal :D
ez::ez_template_print();
pros::delay(500); // Stop the user from doing anything while legacy ports configure
chassis.odom_tracker_right_set(&right_tracker);
chassis.odom_tracker_left_set(&left_tracker);
chassis.odom_tracker_back_set(&horiz_tracker); // Replace `back` to `front` if your tracker is in the front!
}
odom_tracker_front_set()
Sets the perpendicular front tracking wheel for odometry.
input an ez::tracking_wheel
- Prototype
- Example
ez::tracking_wheel right_tracker({-'A', -'B'}, 2.75, 4.0); // ADI Encoders
ez::tracking_wheel left_tracker(1, {'C', 'D'}, 2.75, 4.0); // ADI Encoders plugged into a Smart port
ez::tracking_wheel horiz_tracker(1, 2.75, 4.0); // Rotation sensors
void initialize() {
// Print our branding over your terminal :D
ez::ez_template_print();
pros::delay(500); // Stop the user from doing anything while legacy ports configure
chassis.odom_tracker_right_set(&right_tracker);
chassis.odom_tracker_left_set(&left_tracker);
chassis.odom_tracker_front_set(&horiz_tracker); // Replace `back` to `front` if your tracker is in the front!
}
void odom_tracker_front_set(tracking_wheel* input);
odom_tracker_back_set()
Sets the perpendicular back tracking wheel for odometry.
input an ez::tracking_wheel
- Prototype
- Example
void odom_tracker_back_set(tracking_wheel* input);
ez::tracking_wheel right_tracker({-'A', -'B'}, 2.75, 4.0); // ADI Encoders
ez::tracking_wheel left_tracker(1, {'C', 'D'}, 2.75, 4.0); // ADI Encoders plugged into a Smart port
ez::tracking_wheel horiz_tracker(1, 2.75, 4.0); // Rotation sensors
void initialize() {
// Print our branding over your terminal :D
ez::ez_template_print();
pros::delay(500); // Stop the user from doing anything while legacy ports configure
chassis.odom_tracker_right_set(&right_tracker);
chassis.odom_tracker_left_set(&left_tracker);
chassis.odom_tracker_back_set(&horiz_tracker); // Replace `back` to `front` if your tracker is in the front!
}
Custom Tracking
By default, position is computed by tracking_wheels_tracking(), using whatever tracking wheels or drive encoders you configured. odom_tracking_set() lets you replace that entirely, for example to fuse in a camera or a different sensor.
odom_tracking_set()
Sets a new task to use for tracking.
In the function you pass in, you must set odom_current.x, odom_current.y, and odom_current.theta. x and y are in inches and theta is in degrees. The function does not need to loop, that is done for you by EZ-Template.
Write the pose directly. Don't call odom_xyt_set(), odom_xy_set(), odom_x_set(), odom_y_set() or odom_pose_set() inside your function, those are for setting the pose from your own code. A tracking function that calls them gets no xy D term (kD) in odom motions, because a pose that was set is not counted as the robot moving.
When your own code sets the pose while a custom tracking function is running, the pass right after the set counts as no movement for the xy D term. EZ-Template can't tell if your function kept the pose that was set or wrote its own over it, like a GPS does. Setting the pose on every pass leaves the xy D term at 0.
To go back to EZ-Template's own tracking, call drive_defaults_set() (it sets every other default again too). Odom picks up from the last pose your function wrote.
EZ-Template calls your function about every 10 ms from its background task, while that task holds the drive lock. Setters like pid_drive_set() wait for that lock, so don't call pros::delay() or anything else that blocks in your function, or every setter will wait on it.
tracking_task new function for tracking
- Prototype
- Example
void custom_tracking() {
chassis.odom_current.x = my_sensor_fusion_x();
chassis.odom_current.y = my_sensor_fusion_y();
chassis.odom_current.theta = chassis.drive_angle_get();
}
void initialize() {
chassis.odom_tracking_set(custom_tracking);
chassis.initialize();
}
void odom_tracking_set(std::function<void(void)> tracking_task);
tracking_wheels_tracking()
The default tracking task, used unless odom_tracking_set() is called. Documented here for reference - most users will never call this directly.
- Prototype
void tracking_wheels_tracking();
Pose
odom_enable()
Enables / disables tracking.
input true enables tracking, false disables tracking
- Prototype
- Example
void odom_enable(bool input);
void initialize() {
// Print our branding over your terminal :D
ez::ez_template_print();
pros::delay(500); // Stop the user from doing anything while legacy ports configure
// Enable tracking
chassis.odom_enable(true);
}
odom_enabled()
Returns whether the bot is tracking with odometry.
True means tracking is enabled, false means tracking is disabled.
- Prototype
- Example
bool odom_enabled();
void initialize() {
// Print our branding over your terminal :D
ez::ez_template_print();
pros::delay(500); // Stop the user from doing anything while legacy ports configure
// Enable tracking
chassis.odom_enable(true);
if (chassis.odom_enabled())
printf("Odom is enabled!\n");
}
odom_x_set()
Sets the current x position of the robot.
x new x coordinate in inches
- Prototype
- Example
void odom_x_set(double x);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_odom_set({{24_in, 0_in}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_x_set(0); // Set current x to 0
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, 0_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_x_set()
Sets the current X coordinate of the robot.
p_x new x coordinate as a unit
- Prototype
- Example
void odom_x_set(ez::QLength p_x);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_odom_set({{24_in, 0_in}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_x_set(0_in); // Set current x to 0
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, 0_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_y_set()
Sets the current Y coordinate of the robot.
y new y coordinate in inches
- Prototype
- Example
void odom_y_set(double y);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_odom_set({{0_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_y_set(0); // Set current y to 0
// This will go back to the starting location
chassis.pid_odom_set({{0_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_y_set()
Sets the current Y coordinate of the robot.
p_y new y coordinate as a unit
- Prototype
- Example
void odom_y_set(ez::QLength p_y);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_odom_set({{0_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_y_set(0_in); // Set current y to 0
// This will go back to the starting location
chassis.pid_odom_set({{0_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_theta_set()
Sets the current Theta of the robot.
a new angle in degrees
- Prototype
- Example
void odom_theta_set(double a);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(90_deg, 110);
chassis.pid_wait();
chassis.odom_theta_set(0); // Set current theta to 0
// This will go back to the starting location
chassis.pid_turn_set(-90_deg, 110);
chassis.pid_wait();
}
odom_theta_set()
Sets the current angle of the robot.
p_a new angle as a unit
- Prototype
- Example
void odom_theta_set(ez::QAngle p_a);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_turn_set(90_deg, 110);
chassis.pid_wait();
chassis.odom_theta_set(0_deg); // Set current theta to 0
// This will go back to the starting location
chassis.pid_turn_set(-90_deg, 110);
chassis.pid_wait();
}
odom_xy_set()
Sets the current X and Y coordinate for the robot.
x new x value, in inches
y new y value, in inches
- Prototype
- Example
void odom_xy_set(double x, double y);
void autonomous() {
chassis.pid_targets_reset(); // Resets PID targets to 0
chassis.drive_imu_reset(); // Reset gyro position to 0
chassis.drive_sensor_reset(); // Reset drive sensors to 0
chassis.odom_xyt_set(0_in, 0_in, 0_deg); // Set the current position, you can start at a specific position with this
chassis.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_xy_set(0, 0); // Set current x and y to 0
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}