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.
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();
}
odom_xy_set()
Sets the current X and Y coordinate for the robot.
p_x new x value, in units
p_y new y value, in units
- Prototype
- Example
void odom_xy_set(ez::QLength p_x, 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({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_xy_set(0_in, 0_in); // 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();
}
odom_xyt_set()
Sets the current X, Y, and Theta values for the robot.
x new x value, in inches
y new y value, in inches
t new theta value, in degrees
- Prototype
- Example
void odom_xyt_set(double x, double y, double t);
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_xyt_set(0, 0, -45);
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_xyt_set()
Sets the current X, Y, and Theta values for the robot.
p_x new x value, in units
p_y new y value, in units
p_t new theta value, in units
- Prototype
- Example
void odom_xyt_set(ez::QLength p_x, ez::QLength p_y, ez::QAngle p_t);
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
chassis.odom_xyt_set(0_in, 0_in, -45_deg);
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_pose_set()
Sets the current pose of the robot.
itarget {x, y, t} units in inches and degrees
- Prototype
- Example
void odom_pose_set(pose itarget);
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
ez::pose new_pose = {0, 0, -45};
chassis.odom_pose_set(new_pose);
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_pose_set()
Set the current pose of the robot.
itarget {x, y, t} as a unit
- Prototype
- Example
void odom_pose_set(united_pose itarget);
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
ez::united_pose new_pose = {0_in, 0_in, -45_deg};
chassis.odom_pose_set(new_pose);
// This will go back to the starting location
chassis.pid_odom_set({{-24_in, -24_in}, ez::rev, 110});
chassis.pid_wait();
}
odom_x_get()
Returns the current x position of the robot in inches.
- Prototype
- Example
double odom_x_get();
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
printf("X: %.2f Y: %.2f T: %.2f\n", chassis.odom_x_get(), chassis.odom_y_get(), chassis.odom_theta_get());
}
odom_y_get()
Returns the current Y coordinate of the robot in inches.
- Prototype
- Example
double odom_y_get();
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
printf("X: %.2f Y: %.2f T: %.2f\n", chassis.odom_x_get(), chassis.odom_y_get(), chassis.odom_theta_get());
}
odom_theta_get()
Returns the current Theta of the robot in degrees.
- Prototype
- Example
double odom_theta_get();
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
printf("X: %.2f Y: %.2f T: %.2f\n", chassis.odom_x_get(), chassis.odom_y_get(), chassis.odom_theta_get());
}
odom_pose_get()
Returns the current pose of the robot.
- Prototype
- Example
pose odom_pose_get();
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, 45_deg}, ez::fwd, 110});
chassis.pid_wait();
ez::pose c_pose = chassis.odom_pose_get();
printf("X: %.2f Y: %.2f T: %.2f\n", c_pose.x, c_pose.y, c_pose.theta);
}
Movement Constants
pid_odom_angular_constants_set()
Set the odom angular pid constants object.
p proportional term
i integral term
d derivative term
p_start_i error threshold to start integral
- Prototype
- Example
void pid_odom_angular_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
void initialize() {
chassis.pid_odom_angular_constants_set(5, 0, 50);
}
odom_turn_bias_set()
A proportion of how prioritized turning is during odometry motions.
Turning is prioritized so the robot "applies brakes" while turning. Lower number means more braking.
Values below 1 make the robot stop driving once turning has gone past a certain angle error, and the robot will never drive backwards to reach the point. The internal scale factor is clamped between 0 and 1.
Non-positive values are rejected, a message is printed to the terminal, and the previous value is kept.
bias a positive number, default is 0.9
- Prototype
- Example
void odom_turn_bias_set(double bias);
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.odom_turn_bias_set(1.0); // Set turn bias to 1
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
// Reset your angle and position
chassis.pid_turn_set(0_deg, 110);
chassis.pid_wait();
chassis.odom_xyt_set(0_in, 0_in, 0_deg);
chassis.odom_turn_bias_set(0.5); // Set turn bias to 0.5
// Go to 24, 24 relative to where the robot ended, but with a new turn bias
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
pid_odom_drive_exit_condition_set()
Set's constants for odom driving exit conditions.
p_small_exit_time time to exit when within small_error, in units
p_small_error small timer will start when error is within this, in units
p_big_exit_time time to exit when within big_error, in units
p_big_error big timer will start when error is within this, in units
p_velocity_exit_time time, in units, for velocity to be 0 after the robot has moved (or after 1 second if it never moves)
p_mA_timeout mA timer will start when the first motor on the side(s) being driven is over its current limit, in units
use_imu true adds a second velocity exit timer based on the imu's acceleration (exits if either the main sensor or the imu reports no movement for p_velocity_exit_time), false uses only the main sensor
- Prototype
- Example
void pid_odom_drive_exit_condition_set(ez::QTime p_small_exit_time, ez::QLength p_small_error, ez::QTime p_big_exit_time, ez::QLength p_big_error, ez::QTime p_velocity_exit_time, ez::QTime p_mA_timeout, bool use_imu = true);
void initialize() {
chassis.pid_odom_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms);
}
pid_odom_drive_exit_condition_set()
Set's constants for odom driving exit conditions.
p_small_exit_time time to exit when within small_error, in ms
p_small_error small timer will start when error is within this, in inches
p_big_exit_time time to exit when within big_error, in ms
p_big_error big timer will start when error is within this, in inches
p_velocity_exit_time velocity timer will start when velocity is 0 after the robot has moved (or after 1 second if it never moves), in ms
p_mA_timeout mA timer will start when the first motor on the side(s) being driven is over its current limit, in ms
use_imu true adds a second velocity exit timer based on the imu's acceleration (exits if either the main sensor or the imu reports no movement for p_velocity_exit_time), false uses only the main sensor
- Prototype
- Example
void pid_odom_drive_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true);
void initialize() {
chassis.pid_odom_drive_exit_condition_set(300, 1, 500, 3, 750, 750);
}
pid_odom_turn_exit_condition_set()
Set's constants for odom turning exit conditions.
p_small_exit_time time to exit when within small_error, in units
p_small_error small timer will start when error is within this, in units
p_big_exit_time time to exit when within big_error, in units
p_big_error big timer will start when error is within this, in units
p_velocity_exit_time time, in units, for velocity to be 0 after the robot has moved (or after 1 second if it never moves)
p_mA_timeout mA timer will start when the first motor on the side(s) being driven is over its current limit, in units
use_imu true adds a second velocity exit timer based on the imu's acceleration (exits if either the main sensor or the imu reports no movement for p_velocity_exit_time), false uses only the main sensor
- Prototype
- Example
void pid_odom_turn_exit_condition_set(ez::QTime p_small_exit_time, ez::QAngle p_small_error, ez::QTime p_big_exit_time, ez::QAngle p_big_error, ez::QTime p_velocity_exit_time, ez::QTime p_mA_timeout, bool use_imu = true);
void initialize() {
chassis.pid_odom_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
}
pid_odom_turn_exit_condition_set()
Set's constants for odom turning exit conditions.
p_small_exit_time time to exit when within small_error, in ms
p_small_error small timer will start when error is within this, in degrees
p_big_exit_time time to exit when within big_error, in ms
p_big_error big timer will start when error is within this, in degrees
p_velocity_exit_time velocity timer will start when velocity is 0 after the robot has moved (or after 1 second if it never moves), in ms
p_mA_timeout mA timer will start when the first motor on the side(s) being driven is over its current limit, in ms
use_imu true adds a second velocity exit timer based on the imu's acceleration (exits if either the main sensor or the imu reports no movement for p_velocity_exit_time), false uses only the main sensor
- Prototype
- Example
void pid_odom_turn_exit_condition_set(int p_small_exit_time, double p_small_error, int p_big_exit_time, double p_big_error, int p_velocity_exit_time, int p_mA_timeout, bool use_imu = true);
void initialize() {
chassis.pid_odom_turn_exit_condition_set(300, 3, 500, 7, 750, 750);
}
odom_look_ahead_set()
Sets how far away the robot looks in the path during pure pursuits.
distance how long the "carrot on a stick" is, in inches. Must be greater than 0. Otherwise it is rejected, a message is printed to the terminal, and the previous value is kept.
- Prototype
- Example
void odom_look_ahead_set(double distance);
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.odom_look_ahead_set(7.0); // Set look ahead to 7in
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
// Reset your angle and position
chassis.pid_turn_set(0_deg, 110);
chassis.pid_wait();
chassis.odom_xyt_set(0_in, 0_in, 0_deg);
chassis.odom_look_ahead_set(14.0); // Set look ahead to 14in
// Go to 24, 24 relative to where the robot ended, but with a new look ahead
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
odom_look_ahead_set()
Sets how far away the robot looks in the path during pure pursuits.
p_distance how long the "carrot on a stick" is, in units. Must be greater than 0. Otherwise it is rejected, a message is printed to the terminal, and the previous value is kept.
- Prototype
- Example
void odom_look_ahead_set(ez::QLength p_distance);
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.odom_look_ahead_set(7_in); // Set look ahead to 7in
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
// Reset your angle and position
chassis.pid_turn_set(0_deg, 110);
chassis.pid_wait();
chassis.odom_xyt_set(0_in, 0_in, 0_deg);
chassis.odom_look_ahead_set(14_in); // Set look ahead to 14in
// Go to 24, 24 relative to where the robot ended, but with a new look ahead
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
pid_odom_behavior_set()
Sets the default behavior for turns in odom turning movements.
behavior ez::shortest, ez::longest, ez::ccw, ez::cw, ez::raw
- Prototype
- Example
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_behavior_set(ez::longest); // Set the robot to take the longest path there
// This will make the robot go the long way around to get to 24, 0
chassis.pid_odom_set({{24_in, 0_in}, ez::fwd, 110});
chassis.pid_wait();
}
void pid_odom_behavior_set(e_angle_behavior behavior);
pid_odom_behavior_get()
Returns the turn behavior for odom turns.
- Prototype
- Example
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_behavior_set(ez::longest); // Set the robot to take the longest path there
if (chassis.pid_odom_behavior_get() == ez::longest) {
printf("Current behavior is ez::longest!\n");
} else {
printf("Current behavior is not ez::longest!\n");
}
// This will make the robot go the long way around to get to 24, 0
chassis.pid_odom_set({{24_in, 0_in}, ez::fwd, 110});
chassis.pid_wait();
}
e_angle_behavior pid_odom_behavior_get();
odom_path_spacing_set()
Sets the spacing between points when points get injected into the path.
p_spacing a small number in units. Must be greater than 0. Otherwise it is rejected, a message is printed to the terminal, and the previous value is kept.
- Prototype
- Example
void odom_path_spacing_set(ez::QLength p_spacing);
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.odom_path_spacing_set(0.5_in); // Set path spacing to 0.5 inches
printf("Path Spacing: %.2f\n", chassis.odom_path_spacing_get());
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
odom_path_spacing_set()
Sets the spacing between points when points get injected into the path.
spacing a small number in inches. Must be greater than 0. Otherwise it is rejected, a message is printed to the terminal, and the previous value is kept.
- Prototype
- Example
void odom_path_spacing_set(double spacing);
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.odom_path_spacing_set(0.5_in); // Set path spacing to 0.5 inches
printf("Path Spacing: %.2f\n", chassis.odom_path_spacing_get());
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
odom_turn_bias_get()
Returns the proportion of how prioritized turning is during odometry motions.
- Prototype
- Example
double odom_turn_bias_get();
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.odom_turn_bias_set(1.0); // Set turn bias to 1
printf("Turn Bias: %.2f\n", chassis.odom_turn_bias_get());
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
// Reset your angle and position
chassis.pid_turn_set(0_deg, 110);
chassis.pid_wait();
chassis.odom_xyt_set(0_in, 0_in, 0_deg);
chassis.odom_turn_bias_set(0.5); // Set turn bias to 0.5
printf("Turn Bias: %.2f\n", chassis.odom_turn_bias_get());
// Go to 24, 24 relative to where the robot ended, but with a new turn bias
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
odom_look_ahead_get()
Returns how far away the robot looks in the path during pure pursuits.
- Prototype
- Example
double odom_look_ahead_get();
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.odom_look_ahead_set(7_in); // Set look ahead to 7in
printf("Look Ahead: %.2f\n", chassis.odom_look_ahead_get());
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
// Reset your angle and position
chassis.pid_turn_set(0_deg, 110);
chassis.pid_wait();
chassis.odom_xyt_set(0_in, 0_in, 0_deg);
chassis.odom_look_ahead_set(14_in); // Set look ahead to 14in
printf("Look Ahead: %.2f\n", chassis.odom_look_ahead_get());
// Go to 24, 24 relative to where the robot ended, but with a new look ahead
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
odom_path_spacing_get()
Returns the spacing between points when points get injected into the path.
- Prototype
- Example
double odom_path_spacing_get();
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.odom_path_spacing_set(0.5_in); // Set path spacing to 0.5 inches
printf("Path Spacing: %.2f\n", chassis.odom_path_spacing_get());
// Go to 24, 24
chassis.pid_odom_set({{24_in, 24_in}, ez::fwd, 110});
chassis.pid_wait();
}
slew_odom_reenable()
Allows slew to reenable when the new input speed is larger than the current speed during pure pursuits.
reenable true enables, false disables
- Prototype
- Example
void slew_odom_reenable(bool reenable);
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
// Allow slew to reenable when speed dips too low
chassis.slew_odom_reenable(true);
// This will slew from the start to 110,
// and once the speed dips down to 50 it'll slew again up to 90
chassis.pid_odom_set({{{6_in, 10_in}, ez::fwd, 110},
{{0_in, 20_in}, ez::fwd, 50},
{{0_in, 30_in}, ez::fwd, 90}},
true);
chassis.pid_wait();
}
slew_odom_reenabled()
Returns if slew will reenable when the new input speed is larger than the current speed during pure pursuits.
- Prototype
- Example
bool slew_odom_reenabled();
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
// Allow slew to reenable when speed dips too low
chassis.slew_odom_reenable(true);
if (chassis.slew_odom_reenabled())
printf("Slew will Reenable in Odom!\n");
// This will slew from the start to 110,
// and once the speed dips down to 50 it'll slew again up to 90
chassis.pid_odom_set({{{6_in, 10_in}, ez::fwd, 110},
{{0_in, 20_in}, ez::fwd, 50},
{{0_in, 30_in}, ez::fwd, 90}},
true);
chassis.pid_wait();
}
odom_path_smooth_constants_set()
Sets the constants for smoothing out a path.
Path smoothing based on https://medium.com/@jaems33/understanding-robot-motion-path-smoothing-5970c8363bc4
weight_smooth how much weight to smooth the coordinates, 0 or more and less than 1
weight_data how much weight to keep the coordinates near the original path, 0 or more
tolerance how much change per iteration is necessary to keep iterating, greater than 0
weight_data + 2 * weight_smooth must also be less than 2. Smoothing makes repeated passes over the points, and at 2 or more each pass moves them further from the path instead of settling, so it would never finish. With the defaults that's 1.53.
If any of these are out of range, all of the constants are rejected, a message is printed to the terminal naming the first one that is out of range, and the previous constants are kept.
- Prototype
- Example
void odom_path_smooth_constants_set(double weight_smooth, double weight_data, double tolerance);
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_drive_toggle(false); // Disable the drive
chassis.pid_print_toggle(false); // Disable movement printing
// Print default smooth constants
std::vector<double> smooth_consts = chassis.odom_path_smooth_constants_get();
printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]);
chassis.pid_odom_set({{{0_in, 24_in}, ez::fwd, 110},
{{24_in, 24_in}, ez::fwd, 110}},
false);
chassis.odom_path_print(); // Print the full path to terminal
// Print updated smooth constants
chassis.odom_path_smooth_constants_set(0.5, 0.003, 0.0001);
smooth_consts = chassis.odom_path_smooth_constants_get();
printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]);
chassis.pid_odom_set({{{0_in, 24_in}, ez::fwd, 110},
{{24_in, 24_in}, ez::fwd, 110}},
false);
chassis.odom_path_print(); // Print the full path to terminal
}
odom_path_smooth_constants_get()
Returns the constants for smoothing out a path.
In order of:
- weight_smooth
- weight_data
- tolerance
- Prototype
- Example
std::vector<double> odom_path_smooth_constants_get();
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_drive_toggle(false); // Disable the drive
chassis.pid_print_toggle(false); // Disable movement printing
// Print default smooth constants
std::vector<double> smooth_consts = chassis.odom_path_smooth_constants_get();
printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]);
chassis.pid_odom_set({{{0_in, 24_in}, ez::fwd, 110},
{{24_in, 24_in}, ez::fwd, 110}},
false);
chassis.odom_path_print(); // Print the full path to terminal
// Print updated smooth constants
chassis.odom_path_smooth_constants_set(0.5, 0.003, 0.0001);
smooth_consts = chassis.odom_path_smooth_constants_get();
printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]);
chassis.pid_odom_set({{{0_in, 24_in}, ez::fwd, 110},
{{24_in, 24_in}, ez::fwd, 110}},
false);
chassis.odom_path_print(); // Print the full path to terminal
}
odom_path_print()
Prints the current path the robot is following.
- Prototype
- Example
void odom_path_print();
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_drive_toggle(false); // Disable the drive
chassis.pid_print_toggle(false); // Disable movement printing
// Print default smooth constants
std::vector<double> smooth_consts = chassis.odom_path_smooth_constants_get();
printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]);
chassis.pid_odom_set({{{0_in, 24_in}, ez::fwd, 110},
{{24_in, 24_in}, ez::fwd, 110}},
false);
chassis.odom_path_print(); // Print the full path to terminal
// Print updated smooth constants
chassis.odom_path_smooth_constants_set(0.5, 0.003, 0.0001);
smooth_consts = chassis.odom_path_smooth_constants_get();
printf("Weight Smooth: %.2f Weight Data: %.2f Tolerance: %.2f\n", smooth_consts[0], smooth_consts[1], smooth_consts[2]);
chassis.pid_odom_set({{{0_in, 24_in}, ez::fwd, 110},
{{24_in, 24_in}, ez::fwd, 110}},
false);
chassis.odom_path_print(); // Print the full path to terminal
}
Boomerang Behavior
pid_odom_boomerang_constants_set()
Set the odom boomerang pid constants object.
p proportional term
i integral term
d derivative term
p_start_i error threshold to start integral
- Prototype
- Example
void pid_odom_boomerang_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
void initialize() {
chassis.pid_odom_boomerang_constants_set(5, 0, 50);
}
odom_boomerang_dlead_set()
Sets a new dlead.
Dlead is a proportional value of how much to make the robot curve during boomerang motions.
input a value between 0 and 1
- Prototype
- Example
void odom_boomerang_dlead_set(double input);
void initialize() {
chassis.odom_boomerang_dlead_set(0.5);
}
odom_boomerang_distance_set()
Sets how far away the carrot point can be from the target point.
distance distance in inches
- Prototype
- Example
void odom_boomerang_distance_set(double distance);
void initialize() {
chassis.odom_boomerang_dlead_set(0.5);
chassis.odom_boomerang_distance_set(12);
}
odom_boomerang_distance_set()
Sets how far away the carrot point can be from the target point.
p_distance distance as a unit
- Prototype
- Example
void odom_boomerang_distance_set(ez::QLength p_distance);
void initialize() {
chassis.odom_boomerang_dlead_set(0.5);
chassis.odom_boomerang_distance_set(12_in);
}
odom_boomerang_dlead_get()
Returns the current dlead.
- Prototype
- Example
double odom_boomerang_dlead_get();
void initialize() {
chassis.odom_boomerang_dlead_set(0.5);
printf("dlead: %.2f\n", chassis.odom_boomerang_dlead_get());
}
odom_boomerang_distance_get()
Returns the maximum distance the carrot point can be away from the target point.
- Prototype
- Example
double odom_boomerang_distance_get();
void initialize() {
chassis.odom_boomerang_dlead_set(0.5);
chassis.odom_boomerang_distance_set(12_in);
printf("Max Distance: %.2f\n", chassis.odom_boomerang_distance_get());
}