Skip to main content
Version: 3.0.1

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

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);

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

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);

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

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);

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

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);

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

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);

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

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);

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_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);

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();

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();

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();