Autonomous Functions
Functions with Okapi Units
pid_drive_set()
Sets the drive to go forward using PID and heading correction.
p_target
is in an okapi length unit.
speed
is 0 to 127. It's recommended to keep this at 110.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
toggle_heading
will disable heading correction when false.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_drive_set(24_in, 110, true);
chassis.pid_wait();
}
void pid_drive_set(okapi::QLength p_target, int speed, bool slew_on = false, bool toggle_heading = true);
pid_turn_set()
Sets the drive to turn using PID.
p_target
is an okapi angle unit.
speed
is 0 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_turn_set(24_deg, 110, true);
chassis.pid_wait();
}
void pid_turn_set(okapi::QAngle p_target, int speed, bool slew_on = false);
pid_turn_relative_set()
Sets the drive to turn using PID. Target is relative here, the robot will add the target to your current angle.
p_target
is an okapi angle unit.
speed
is 0 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
// Turns to 90 deg
chassis.pid_turn_relative_set(90_deg, 110, true);
chassis.pid_wait();
// Turns backwards by 45 degrees
chassis.pid_turn_relative_set(-45_deg, 110, true);
chassis.pid_wait();
}
void pid_turn_relative_set(okapi::QAngle p_target, int speed, bool slew_on = false);
pid_swing_set()
Sets the robot to swing using PID. The robot will turn using one side of the drive, either the left or right. The opposite side of the drive can be set to a value for wider or tighter arcs.
type
is either ez::LEFT_SWING
or ez::RIGHT_SWING
.
p_target
is an okapi angle unit.
speed
is 0 to 127.
opposite_speed
is -127 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void pid_swing_set(e_swing type, okapi::QAngle p_target, int speed, int opposite_speed = 0, bool slew_on = false);
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_swing_set(ez::LEFT_SWING, 45_deg, 110, 0, true);
chassis.pid_wait();
chassis.pid_swing_set(ez::RIGHT_SWING, 0_deg, 110, 50, true);
chassis.pid_wait();
}
pid_swing_relative_set()
Sets the robot to swing using PID. The robot will turn using one side of the drive, either the left or right. The opposite side of the drive can be set to a value for wider or tighter arcs. Target is relative here, the robot will add the target to your current angle.
type
is either ez::LEFT_SWING
or ez::RIGHT_SWING
.
p_target
is an okapi angle unit.
speed
is 0 to 127.
opposite_speed
is -127 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void pid_swing_relative_set(e_swing type, okapi::QAngle p_target, int speed, int opposite_speed = 0, bool slew_on = false);
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
// This will turn to 90 degrees
chassis.pid_swing_relative_set(ez::LEFT_SWING, 90_deg, 110);
chassis.pid_wait();
// This will go backwards by 45 degrees
chassis.pid_swing_relative_set(ez::RIGHT_SWING, -45_deg, 110);
chassis.pid_wait();
}
drive_angle_set()
Sets the angle of the robot. This is useful when your robot is setup in at an unconventional angle and you want 0 to be when you're square with the field.
p_angle
an okapi angle unit, angle that the robot will think it's now facing.
- Prototype
- Example
void drive_angle_set(okapi::QAngle p_angle);
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.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.
chassis.drive_angle_set(45_deg);
chassis.pid_turn_set(0, TURN_SPEED);
chassis.pid_wait();
}
pid_drive_exit_condition_set()
Sets the exit condition constants for driving. This uses the exit conditions from the PID class.
p_small_exit_time
time, in okapi units, before exiting p_small_error
p_small_error
small error threshold in okapi length unit
p_big_exit_time
time, in okapi units, before exiting p_big_error
p_big_error
big error threshold, in okapi length unit
p_velocity_exit_time
time, in okapi units, for velocity to be 0
p_mA_timeout
time, in okapi units, for is_over_current
to be true
use_imu
boolean, true adds the IMU to velocity timeouts, false only uses the PID sensor. This defaults to true
- Prototype
- Example
void initialize() {
chassis.pid_drive_exit_condition_set(300_ms, 1_in, 500_ms, 3_in, 750_ms, 750_ms);
}
void pid_drive_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QLength p_small_error, okapi::QTime p_big_exit_time, okapi::QLength p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, use_imu = true);
pid_turn_exit_condition_set()
Sets the exit condition constants for turning. This uses the exit conditions from the PID class.
p_small_exit_time
time, in okapi units, before exiting p_small_error
p_small_error
small error threshold in okapi angle unit
p_big_exit_time
time, in okapi units, before exiting p_big_error
p_big_error
big error threshold, in okapi angle unit
p_velocity_exit_time
time, in okapi units, for velocity to be 0
p_mA_timeout
time, in okapi units, for is_over_current
to be true
use_imu
boolean, true adds the IMU to velocity timeouts, false only uses the PID sensor. This defaults to true
- Prototype
- Example
void initialize() {
chassis.pid_turn_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
}
void pid_turn_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, use_imu = true);
pid_swing_exit_condition_set()
Sets the exit condition constants for swing turns. This uses the exit conditions from the PID class.
p_small_exit_time
time, in okapi units, before exiting p_small_error
p_small_error
small error threshold in okapi angle unit
p_big_exit_time
time, in okapi units, before exiting p_big_error
p_big_error
big error threshold, in okapi angle unit
p_velocity_exit_time
time, in okapi units, for velocity to be 0
p_mA_timeout
time, in okapi units, for is_over_current
to be true
use_imu
boolean, true adds the IMU to velocity timeouts, false only uses the PID sensor. This defaults to true
- Prototype
- Example
void initialize() {
chassis.pid_swing_exit_condition_set(300_ms, 3_deg, 500_ms, 7_deg, 750_ms, 750_ms);
}
void pid_swing_exit_condition_set(okapi::QTime p_small_exit_time, okapi::QAngle p_small_error, okapi::QTime p_big_exit_time, okapi::QAngle p_big_error, okapi::QTime p_velocity_exit_time, okapi::QTime p_mA_timeout, use_imu = true);
pid_drive_chain_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for drive motions.
input
okapi length unit
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_constant_set(3_in);
}
void pid_drive_chain_constant_set(okapi::QLength input);
pid_drive_chain_forward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for forward drive motions.
input
okapi length unit
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_forward_constant_set(3_in);
}
void pid_drive_chain_forward_constant_set(okapi::QLength input);
pid_drive_chain_backward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for backward drive motions.
input
okapi length unit
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_backward_constant_set(3_in);
}
void pid_drive_chain_backward_constant_set(okapi::QLength input);
pid_turn_chain_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for turns.
input
okapi angle unit
- Prototype
- Example
void initialize() {
chassis.pid_turn_chain_constant_set(3_deg);
}
void pid_turn_chain_constant_set(okapi::QAngle input);
pid_swing_chain_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for swings.
input
okapi angle unit
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_constant_set(5_deg);
}
void pid_swing_chain_constant_set(okapi::QAngle input);
pid_swing_chain_forward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for forward swings.
input
okapi angle unit
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_forward_constant_set(5_deg);
}
void pid_swing_chain_forward_constant_set(okapi::QAngle input);
pid_swing_chain_backward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for backward swings.
input
okapi angle unit
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_backward_constant_set(5_deg);
}
void pid_swing_chain_backward_constant_set(okapi::QAngle input);
pid_wait_until()
Locks the code in place until the drive has passed the input parameter. This uses the exit conditions from the PID class. This only works for drive motions.
target
the distance the robot needs to travel before unlocking the code as an okapi length unit.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_drive_set(48_in, 110);
chassis.pid_wait_until(24_in);
chassis.pid_speed_max_set(40);
chassis.pid_wait();
}
void pid_wait_until(okapi::QLength target);
pid_wait_until()
Locks the code in place until the drive has passed the input parameter. This uses the exit conditions from the PID class. This only works for turn and swing motions.
target
the distance the robot needs to travel before unlocking the code as an okapi angle unit.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_turn_set(90_deg, 110);
chassis.pid_wait_until(45_deg);
chassis.pid_speed_max_set(40);
chassis.pid_wait();
}
void pid_wait_until(okapi::QAngle target);
Functions without Okapi Units
pid_drive_set()
Sets the drive to go forward using PID and heading correction.
target
is in inches.
speed
is 0 to 127. It's recommended to keep this at 110.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
toggle_heading
will disable heading correction when false.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_drive_set(24, 110, true);
chassis.pid_wait();
}
void pid_drive_set(double target, int speed, bool slew_on = false, bool toggle_heading = true);
pid_turn_set()
Sets the drive to turn using PID.
target
is in degrees.
speed
is 0 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_turn_set(24, 110, true);
chassis.pid_wait();
}
void pid_turn_set(double target, int speed, bool slew_on = false);
pid_turn_relative_set()
Sets the drive to turn using PID. Target is relative here, the robot will add the target to your current angle.
target
is in degrees.
speed
is 0 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
// Turns to 90 deg
chassis.pid_turn_relative_set(90, 110, true);
chassis.pid_wait();
// Turns backwards by 45 degrees
chassis.pid_turn_relative_set(-45, 110, true);
chassis.pid_wait();
}
void pid_turn_relative_set(double target, int speed, bool slew_on = false);
pid_swing_set()
Sets the robot to swing using PID. The robot will turn using one side of the drive, either the left or right. The opposite side of the drive can be set to a value for wider or tighter arcs.
type
is either ez::LEFT_SWING
or ez::RIGHT_SWING
.
target
is in degrees.
speed
is 0 to 127.
opposite_speed
is -127 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void pid_swing_set(e_swing type, double target, int speed, int opposite_speed = 0, bool slew_on = false);
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_swing_set(ez::LEFT_SWING, 45, 110, 0, true);
chassis.pid_wait();
chassis.pid_swing_set(ez::RIGHT_SWING, 0, 110, 50, true);
chassis.pid_wait();
}
pid_swing_relative_set()
Sets the robot to swing using PID. The robot will turn using one side of the drive, either the left or right. The opposite side of the drive can be set to a value for wider or tighter arcs. Target is relative here, the robot will add the target to your current angle.
type
is either ez::LEFT_SWING
or ez::RIGHT_SWING
.
p_target
is in degrees.
speed
is 0 to 127.
opposite_speed
is -127 to 127.
slew_on
increases the speed of the drive gradually. You must set slew constants for this to work!
- Prototype
- Example
void pid_swing_relative_set(e_swing type, double target, int speed, int opposite_speed = 0, bool slew_on = false);
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
// This will turn to 90 degrees
chassis.pid_swing_relative_set(ez::LEFT_SWING, 90, 110);
chassis.pid_wait();
// This will go backwards by 45 degrees
chassis.pid_swing_relative_set(ez::RIGHT_SWING, -45, 110);
chassis.pid_wait();
}
drive_angle_set()
Sets the angle of the robot. This is useful when your robot is setup in at an unconventional angle and you want 0 to be when you're square with the field.
angle
is in degrees, angle that the robot will think it's now facing.
- Prototype
- Example
void drive_angle_set(double angle);
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.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.
chassis.drive_angle_set(45);
chassis.pid_turn_set(0, TURN_SPEED);
chassis.pid_wait();
}
pid_drive_exit_condition_set()
Sets the exit condition constants for driving. This uses the exit conditions from the PID class.
This function can also be used without okapi units.
p_small_exit_time
time, in ms, before exiting p_small_error
p_small_error
small error threshold, assumed inches
p_big_exit_time
time, in ms, before exiting p_big_error
p_big_error
big error threshold, assumed inches
p_velocity_exit_time
time, in ms, for velocity to be 0
p_mA_timeout
time, in ms, for is_over_current
to be true
use_imu
boolean, true adds the IMU to velocity timeouts, false only uses the PID sensor. This defaults to true
- Prototype
- Example
void initialize() {
chassis.pid_drive_exit_condition_set(300, 1, 500, 3, 750, 750);
}
void pid_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, use_imu = true);
pid_turn_exit_condition_set()
Sets the exit condition constants for turning. This uses the exit conditions from the PID class.
This function can also be used without okapi units.
p_small_exit_time
time, in ms, before exiting p_small_error
p_small_error
small error threshold, assumed degrees
p_big_exit_time
time, in ms, before exiting p_big_error
p_big_error
big error threshold, assumed degrees
p_velocity_exit_time
time, in ms, for velocity to be 0
p_mA_timeout
time, in ms, for is_over_current
to be true
use_imu
boolean, true adds the IMU to velocity timeouts, false only uses the PID sensor. This defaults to true
- Prototype
- Example
void initialize() {
chassis.pid_turn_exit_condition_set(300, 1, 500, 3, 750, 750);
}
void pid_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, use_imu = true);
pid_swing_exit_condition_set()
Sets the exit condition constants for swing turns. This uses the exit conditions from the PID class.
This function can also be used without okapi units.
p_small_exit_time
time, in ms, before exiting p_small_error
p_small_error
small error threshold, assumed degrees
p_big_exit_time
time, in ms, before exiting p_big_error
p_big_error
big error threshold, assumed degrees
p_velocity_exit_time
time, in ms, for velocity to be 0
p_mA_timeout
time, in ms, for is_over_current
to be true
use_imu
boolean, true adds the IMU to velocity timeouts, false only uses the PID sensor. This defaults to true
- Prototype
- Example
void initialize() {
chassis.pid_swing_exit_condition_set(300, 1, 500, 3, 750, 750);
}
void pid_swing_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, use_imu = true);
pid_speed_max_set()
Sets the max speed of the drive.
speed
an integer between -127 and 127.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_drive_set(48, 110);
chassis.pid_wait_until(24);
chassis.pid_speed_max_set(40);
chassis.pid_wait();
}
void pid_speed_max_set(int speed);
pid_drive_constants_set()
Set PID drive constants for forwards and backwards.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_drive_constants_set(10, 0, 100);
}
void pid_drive_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_drive_constants_forward_set()
Set PID drive constants for forwards movements.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_drive_constants_forward_set(10, 0, 100);
}
void pid_drive_constants_forward_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_drive_constants_backward_set()
Set PID drive constants for backwards movements.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_drive_constants_backward_set(10, 0, 100);
}
void pid_drive_constants_backward_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_heading_constants_set()
Set PID drive constants heading correction during drive motions.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_heading_constants_set(3, 0, 20);
}
void pid_heading_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_turn_constants_set()
Set PID drive constants for turns.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_turn_constants_set(3, 0, 20);
}
void pid_turn_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_swing_constants_set()
Set PID drive constants for forward and backward swings.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_swing_constants_set(5, 0, 30);
}
void pid_swing_constants_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_swing_constants_forward_set()
Set PID drive constants for forward swings.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_swing_constants_forward_set(5, 0, 30);
}
void pid_swing_constants_forward_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_swing_constants_backward_set()
Set PID drive constants for backward swings.
p
proportion constant
i
integral constant
d
derivative constant
p_start_i
error needs to be within this for i to start
- Prototype
- Example
void initialize() {
chassis.pid_swing_constants_backward_set(5, 0, 30);
}
void pid_swing_constants_backward_set(double p, double i = 0.0, double d = 0.0, double p_start_i = 0.0);
pid_drive_chain_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for drive motions.
input
double, length in inches
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_constant_set(3);
}
void pid_drive_chain_constant_set(double input);
pid_drive_chain_forward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for forward drive motions.
input
double, length in inches
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_forward_constant_set(3);
}
void pid_drive_chain_forward_constant_set(double input);
pid_drive_chain_backward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for backward drive motions.
input
double, length in inches
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_backward_constant_set(3);
}
void pid_drive_chain_backward_constant_set(double input);
pid_turn_chain_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for turns.
input
double, angle in degrees
- Prototype
- Example
void initialize() {
chassis.pid_turn_chain_constant_set(3);
}
void pid_turn_chain_constant_set(double input);
pid_swing_chain_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for swings.
input
double, angle in degrees
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_constant_set(5);
}
void pid_swing_chain_constant_set(double input);
pid_swing_chain_forward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for forward swings.
input
double, angle in degrees
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_forward_constant_set(5);
}
void pid_swing_chain_forward_constant_set(double input);
pid_swing_chain_backward_constant_set()
Sets the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for backward swings.
input
double, angle in degrees
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_backward_constant_set(5);
}
void pid_swing_chain_backward_constant_set(double input);
pid_swing_min_set()
Sets the max power of the drive when the robot is within start_i
. This only enables when i
is enabled, and when the movement is greater then start_i
.
min
the minimum speed the robot will turn at when integral is being used
- Prototype
- Example
void autonomous() {
chassis.pid_swing_min_set(30);
chassis.pid_swing_set(45, 110);
chassis.pid_wait();
}
void pid_swing_min_set(int min);
pid_turn_min_set()
Sets the max power of the drive when the robot is within start_i
. This only enables when i
is enabled, and when the movement is greater then start_i
.
min
the minimum speed the robot will turn at when integral is being used
- Prototype
- Example
void autonomous() {
chassis.pid_turn_min_set(30);
chassis.pid_turn_set(45, 110);
chassis.pid_wait();
}
void pid_turn_min_set(int min);
drive_mode_set()
Sets the current mode of the drive.
p_mode
the current task running for the drive. accepts ez::DISABLE
, ez::SWING
, ez::TURN
, ez::DRIVE
- Prototype
- Example
void autonomous() {
chassis.pid_drive_set(12, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_mode_set(ez::DISABLE); // Disable drive
chassis.drive_set(-127, -127); // Run drive motors myself
pros::delay(2000);
chassis.drive_set(0, 0);
}
void drive_mode_set(e_mode p_mode);
drive_rpm_set()
Sets a new RPM for the drive. This is can be used when a drive has a transmission.
rpm
the rpm of the wheel
- Prototype
- Example
void drive_example() {
chassis.pid_drive_set(24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_rpm_set(50); // Engage torque rpm
chassis.pid_drive_set(-24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_rpm_set(343); // Return back to normal rpm
}
void drive_rpm_set(double rpm);
drive_ratio_set()
Sets a new ratio for the drive. This is can be used when a drive has a transmission. This should be wheel / motor
.
ratio
the new of the drive
- Prototype
- Example
void drive_example() {
chassis.pid_drive_set(24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_ratio_set(0.083); // Engage torque rpm
chassis.pid_drive_set(-24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_ratio_set(1.79); // Return back to normal rpm
}
void drive_ratio_set(double ratio);
pid_drive_toggle()
Enables/disables the drive from moving in autonomous. This is useful for debugging and checking PID variables.
toggle
true enables the drive, false disables the drive
- Prototype
- Example
void autonomous() {
chassis.pid_drive_set(12, DRIVE_SPEED);
chassis.pid_wait();
pid_drive_toggle(false); // Disable drive
chassis.pid_drive_set(-12, DRIVE_SPEED);
while (true) {
printf(" Left Error: %f Right Error: %f\n", chassis.leftPID.error, chassis.rightPID.error);
pros::delay(ez::util::DELAY_TIME);
}
}
void pid_drive_toggle(bool toggle);
pid_print_toggle()
Enables/disables the drive functions printing every drive motion. This is useful when you're debugging something and don't want terminal cluttered.
toggle
true enables printing, false disables
- Prototype
- Example
void autonomous() {
chassis.pid_drive_set(12, DRIVE_SPEED); // This will print
chassis.pid_wait(); // This will print
pid_print_toggle(false); // Disable prints
chassis.pid_drive_set(-12, DRIVE_SPEED); // This won't print
chassis.pid_wait(); // This won't print
}
void pid_print_toggle(bool toggle);
pid_wait_until()
Locks the code in place until the drive has passed the input parameter. This uses the exit conditions from the PID class.
target
the distance the robot needs to travel before unlocking the code. This is degrees if turning or swinging, and inches if driving.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_drive_set(48, 110);
chassis.pid_wait_until(24);
chassis.pid_speed_max_set(40);
chassis.pid_wait();
}
void pid_wait_until(double target);
pid_targets_reset()
Resets all drive PID targets to 0.
- 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.drive_brake_set(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency.
ez::as::auton_selector.selected_auton_call(); // Calls selected auton from autonomous selector.
}
void pid_targets_reset();
Getter
pid_swing_min_get()
Returns the minimum power the robot will swing at while integral is enabled.
- Prototype
- Example
void autonomous() {
chassis.pid_swing_min_set(30);
printf("Swing Min: %i", chassis.pid_swing_min_get());
}
int pid_swing_min_get();
pid_turn_min_get()
Returns the minimum power the robot will turn at while integral is enabled.
- Prototype
- Example
void autonomous() {
chassis.pid_turn_min_set(30);
printf("Turn Min: %i", chassis.pid_turn_min_get());
}
int pid_turn_min_get();
pid_drive_chain_forward_constant_get()
Returns a double that's the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for forward drive motions.
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_constant_set(3_in);
printf("%.2f\n", chassis.pid_drive_chain_forward_constant_get());
}
double pid_drive_chain_forward_constant_get();
pid_drive_chain_backward_constant_get()
Returns a double that's the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for backward drive motions.
- Prototype
- Example
void initialize() {
chassis.pid_drive_chain_constant_set(3_in);
printf("%.2f\n", chassis.pid_drive_chain_backward_constant_get());
}
double pid_drive_chain_backward_constant_get();
pid_turn_chain_constant_get()
Returns a double that's the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for turns.
- Prototype
- Example
void initialize() {
chassis.pid_turn_chain_constant_set(3_deg);
printf("%.2f\n", chassis.pid_turn_chain_constant_get());
}
double pid_turn_chain_constant_get();
pid_swing_chain_forward_constant_get()
Returns a double that's the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for forward swings.
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_constant_set(5_deg);
printf("%.2f\n", chassis.pid_swing_chain_forward_constant_get());
}
double pid_swing_chain_forward_constant_get();
pid_swing_chain_backward_constant_get()
Returns a double that's the amount that the PID will overshoot target by to maintain momentum into the next motion when using pid_wait_quick_chain()
for backward swings.
- Prototype
- Example
void initialize() {
chassis.pid_swing_chain_constant_set(5_deg);
printf("%.2f\n", chassis.pid_swing_chain_backward_constant_get());
}
double pid_swing_chain_backward_constant_get();
interfered
Boolean that returns true when pid_wait()
or pid_wait_until()
exit with velocity or is_over_current. This can be used to detect unwanted motion and stop the drive motors from overheating during autonomous.
- Prototype
- Example
void tug (int attempts) {
for (int i=0; i<attempts-1; i++) {
// Attempt to drive backwards
printf("i - %i", i);
chassis.pid_drive_set(-12, 127);
chassis.pid_wait();
// If failsafed...
if (chassis.interfered) {
chassis.drive_sensor_reset();
chassis.pid_drive_set(-2, 20);
pros::delay(1000);
}
// If robot successfully drove back, return
else {
return;
}
}
}
void auto1() {
chassis.pid_drive_set(24, 110, true);
chassis.pid_wait();
if (chassis.interfered) {
tug(3);
return;
}
chassis.pid_turn_set(90, 90);
chassis.pid_wait();
}
bool interfered = false;
drive_mode_get()
Returns the current drive mode that the task is running. Returns ez::DISABLE
, ez::SWING
, ez::TURN
, ez::DRIVE
.
- Prototype
- Example
void autonomous() {
chassis.pid_drive_set(12, DRIVE_SPEED);
chassis.pid_wait();
if (chassis.interfered)
chassis.drive_mode_set(ez::DISABLE);
if (chassis.drive_mode_get() == ez::DISABLE) {
chassis.drive_set(-127, -127); // Run drive motors myself
pros::delay(2000);
chassis.drive_set(0, 0);
}
}
e_mode drive_mode_get();
drive_tick_per_inch()
Returns the conversion between raw sensor value and inches.
- Prototype
- Example
void initialize() {
printf("Tick Per Inch: %f\n", chassis.drive_tick_per_inch());
}
double drive_tick_per_inch();
drive_rpm_get()
Returns RPM for the drive. This is can be used when a drive has a transmission.
- Prototype
- Example
void drive_example() {
chassis.pid_drive_set(24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_rpm_set(50); // Engage torque rpm
printf("%.2f\n", chassis.drive_rpm_get());
chassis.pid_drive_set(-24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_rpm_set(343); // Return back to normal
printf("%.2f\n", chassis.drive_rpm_get());
}
double drive_rpm_get();
drive_ratio_get()
Returns ratio for the drive. This is can be used when a drive has a transmission. This should be wheel / motor
.
- Prototype
- Example
void drive_example() {
chassis.pid_drive_set(24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_ratio_set(0.083); // Engage torque rpm
printf("%.2f\n", chassis.drive_ratio_get());
chassis.pid_drive_set(-24_in, DRIVE_SPEED);
chassis.pid_wait();
chassis.drive_ratio_set(1.79); // Return back to normal rpm
printf("%.2f\n", chassis.drive_ratio_get());
}
double drive_ratio_get();
Misc.
pid_wait()
Locks the code in place until the drive has settled. This uses the exit conditions from the PID class.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_turn_set(90, 110);
chassis.pid_wait();
chassis.pid_turn_set(0, 110);
chassis.pid_wait();
}
void pid_wait();
pid_wait_quick()
Locks the code in place until the drive passes target. This function exits quicker then pid_wait()
, and is effectively using pid_wait_until(target)
, where target
is the most recent targe value that was set. If target
is not overshot, this will use the normal exit conditions from the PID class.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_turn_set(90, 110);
chassis.pid_wait_quick();
chassis.pid_turn_set(0, 110);
chassis.pid_wait_quick();
}
void pid_wait_quick();
pid_wait_quick_chain()
Locks the code in place until the drive passes target. To ensure that the robot will pass the target, this function will add some amount, such as pid_turn_chain_constant_set(3_deg);
, to target, then will act as a wrapper for pid_wait_quick()
. If target is not overshot, this will use the normal exit conditions from the PID class.
Because this function adds to target, this should not be used as a final wait. This should be used between motions.
- Prototype
- Example
void autonomous() {
chassis.drive_imu_reset();
chassis.drive_sensor_reset();
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
chassis.pid_turn_set(90, 110);
chassis.pid_wait_quick_chain();
chassis.pid_turn_set(0, 110);
chassis.pid_wait_quick();
}
void pid_wait_quick_chain();