Skip to main content
Version: 3.1.0

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.

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!

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!

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!

void pid_swing_set(e_swing type, okapi::QAngle p_target, int speed, int opposite_speed = 0, bool slew_on = false);

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!

void pid_swing_relative_set(e_swing type, okapi::QAngle p_target, int speed, int opposite_speed = 0, bool slew_on = false);

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.

void drive_angle_set(okapi::QAngle p_angle);

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

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

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

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

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

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

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

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

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

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

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.

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.

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.

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!

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!

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!

void pid_swing_set(e_swing type, double target, int speed, int opposite_speed = 0, bool slew_on = false);

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!

void pid_swing_relative_set(e_swing type, double target, int speed, int opposite_speed = 0, bool slew_on = false);

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.

void drive_angle_set(double angle);

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

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

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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.

void pid_wait_until(double target);

pid_targets_reset()

Resets all drive PID targets to 0.

void pid_targets_reset();

Getter

pid_swing_min_get()

Returns the minimum power the robot will swing at while integral is enabled.

int pid_swing_min_get();

pid_turn_min_get()

Returns the minimum power the robot will turn at while integral is enabled.

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.

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.

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.

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.

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.

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.

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.

e_mode drive_mode_get();

drive_tick_per_inch()

Returns the conversion between raw sensor value and inches.

double drive_tick_per_inch();

drive_rpm_get()

Returns RPM for the drive. This is can be used when a drive has a transmission.

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.

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.

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.

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.

void pid_wait_quick_chain();