Drive and Telemetry
Initialize Drive
initialize()
Runs opcontrol_curve_sd_initialize() and drive_imu_calibrate().
run_loading_animation false skips the loading animation on the brain screen while the IMU calibrates
- Prototype
- Example
void initialize() {
chassis.initialize();
}
void Drive::initialize(bool run_loading_animation = true);
Set Drive
drive_set()
Sets the chassis to voltage.
Disables PID when called.
left voltage for left side, -127 to 127
right voltage for right side, -127 to 127
- Prototype
- Example
void autonomous() {
drive_set(127, 127);
pros::delay(1000); // Wait 1 second
drive_set(0, 0);
}
void drive_set(int left, int right);
drive_brake_set()
Changes the way the drive behaves when it is not under active user control.
brake_type the 'brake mode' of the motor e.g. 'pros::E_MOTOR_BRAKE_COAST' 'pros::E_MOTOR_BRAKE_BRAKE' 'pros::E_MOTOR_BRAKE_HOLD'
- Prototype
- Example
void initialize() {
drive_brake_set_mode(MOTOR_BRAKE_COAST);
}
void drive_brake_set(pros::motor_brake_mode_e_t brake_type);
drive_current_limit_set()
Sets the limit for the current on the drive.
mA input in miliamps
- Prototype
- Example
void initialize() {
drive_brake_set_mode(1000);
}
void drive_current_limit_set(int mA);
drive_imu_scaler_set()
Sets a new imu scaling factor.
This value is multiplied by the imu to change its output.
scaler factor to scale the imu by
- Prototype
- Example
void turn_example() {
chassis.drive_imu_scaler_set(2);
// This will now turn to 45 real degrees
chassis.pid_turn_set(90_deg, TURN_SPEED);
chassis.pid_wait();
// This will turn to 22.5 real degrees
chassis.pid_turn_set(45_deg, TURN_SPEED);
chassis.pid_wait();
chassis.pid_turn_set(0_deg, TURN_SPEED);
chassis.pid_wait();
}
void drive_imu_scaler_set(double scaler);
drive_imus_scalers_set()
Sets a new IMU scaling factor for all IMUs, for drives built with the redundant IMU constructor.
This value is multiplied by each imu to change its output.
scales input {0.99, 1.01...}, in the same order as the IMU ports passed to the constructor
- Prototype
- Example
void initialize() {
chassis.initialize();
chassis.drive_imus_scalers_set({1.0, 1.02});
}
void drive_imus_scalers_set(std::vector<double> scales);
Telemetry
drive_sensor_right()
The position of the right sensor in inches.
If you have two parallel tracking wheels, this will return tracking wheel position. Otherwise this returns motor position.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Right Sensor: %i \n", chassis.drive_sensor_right());
pros::delay(ez::util::DELAY_TIME);
}
}
int drive_sensor_right();
drive_velocity_right()
The velocity of the right motor.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Right Velocity: %i \n", chassis.drive_velocity_right());
pros::delay(ez::util::DELAY_TIME);
}
}
int drive_velocity_right();
drive_mA_right()
The watts of the right motor.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Right mA: %i \n", chassis.drive_mA_right());
pros::delay(ez::util::DELAY_TIME);
}
}
double drive_mA_right();
drive_current_right_over()
Return true when the motor is over current.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Right Over Current: %i \n", chassis.drive_current_right_over());
pros::delay(ez::util::DELAY_TIME);
}
}
bool drive_current_right_over();
drive_sensor_left()
The position of the left sensor in inches.
If you have two parallel tracking wheels, this will return tracking wheel position. Otherwise this returns motor position.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Left Sensor: %i \n", chassis.drive_sensor_left());
pros::delay(ez::util::DELAY_TIME);
}
}
int drive_sensor_left();
drive_velocity_left()
The velocity of the left motor.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Left Velocity: %i \n", chassis.drive_velocity_left());
pros::delay(ez::util::DELAY_TIME);
}
}
int drive_velocity_left();
drive_mA_left()
The watts of the left motor.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Left mA: %i \n", chassis.drive_mA_left());
pros::delay(ez::util::DELAY_TIME);
}
}
double drive_mA_left();
drive_current_left_over()
Return true when the motor is over current.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Left Over Current: %i \n", chassis.drive_current_left_over());
pros::delay(ez::util::DELAY_TIME);
}
}
bool drive_current_left_over();
drive_sensor_reset()
Reset all the chassis motors and tracking wheels, recommended to run at the start of your autonomous routine.
- Prototype
- Example
void initialize() {
chassis.drive_sensor_reset();
}
void drive_sensor_reset();
drive_imu_reset()
Resets the current imu value. Defaults to 0, recommended to run at the start of your autonomous routine.
new_heading_value new heading value
- Prototype
- Example
void initialize() {
chassis.drive_imu_reset();
}
void drive_imu_reset(double new_heading = 0);
drive_imu_get()
Returns the current imu heading rotation value in degrees.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Gyro: %f \n", chassis.drive_imu_get());
pros::delay(ez::util::DELAY_TIME);
}
}
double drive_imu_get();
drive_imu_accel_get()
Returns the current imu accel x + accel y value.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
printf("Accel x + y: %f \n", chassis.drive_imu_accel_get());
pros::delay(ez::util::DELAY_TIME);
}
}
double drive_imu_accel_get();
drive_imu_calibrate()
Calibrates the IMU, recommended to run in initialize().
run_loading_animation true runs the animation, false doesn't
- Prototype
- Example
void initialize() {
chassis.drive_imu_calibrate();
}
bool drive_imu_calibrate(bool run_loading_animation = true);
drive_imu_get()
Gets IMU sensor scaler. This number is multiplied by the imu so users can tune what a "degree" means.
- Prototype
- Example
...
double drive_imu_scaler_get();
drive_imu_scaler_get()
Returns the current imu scaling factor.
- Prototype
- Example
void turn_example() {
chassis.drive_imu_scaler_set(2);
printf("%.2f\n", chassis.drive_imu_scaler_get()); // Prints 2
// This will now turn to 45 real degrees
chassis.pid_turn_set(90_deg, TURN_SPEED);
chassis.pid_wait();
// This will turn to 22.5 real degrees
chassis.pid_turn_set(45_deg, TURN_SPEED);
chassis.pid_wait();
chassis.pid_turn_set(0_deg, TURN_SPEED);
chassis.pid_wait();
}
double drive_imu_scaler_get();
drive_imus_scalers_get()
Returns the scaling factor for all IMUs, keyed by port, for drives built with the redundant IMU constructor.
- Prototype
- Example
chassis.drive_imus_scalers_set({1.0, 1.02});
for (auto& [port, scale] : chassis.drive_imus_scalers_get())
printf("port %i: %.2f\n", port, scale);
std::map<int, double> drive_imus_scalers_get();
drive_angle_get()
Returns the angle of the robot, from whichever IMU is currently focused. On a redundant IMU drive, this is the one to read instead of talking to an individual pros::Imu directly, since it stays correct across a failover.
- Prototype
- Example
printf("%.2f\n", chassis.drive_angle_get());
double drive_angle_get();
drive_imu_scaler_get()
Checks if the imu calibrated successfully or if it took longer than expected.
Returns true if calibrated successfully, and false if unsuccessful.
- Prototype
- Example
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
// Initialize chassis and auton selector
chassis.initialize();
ez::as::initialize();
master.rumble(chassis.drive_imu_calibrated() ? "." : "---");
}
bool drive_imu_calibrated();