Skip to main content
Version: 2.x

Autonomous Functions

Setter functions​

set_drive_pid()​

Sets the drive to go forward using PID and heading correction.

target is in inches.
speed is -127 to 127. It's recommended to keep this at 110.
slew_on will ramp the drive up. toggle_heading will disable heading correction when false.

void set_drive_pid(double target, int speed, bool slew_on = false, bool toggle_heading = true);

set_turn_pid()​

Sets the drive to turn using PID.

target is in degrees.
speed is -127 to 127.

void set_turn_pid(double target, int speed);

set_swing_pid()​

Sets the robot to swing using PID. The robot will turn using one side of the drive, either the left or right.

type is either ez::LEFT_SWING or ez::RIGHT_SWING.
target is in degrees.
speed is -127 to 127.

void set_swing_pid(e_swing type, double target, int speed);

reset_pid_targets()​

Resets all drive PID targets to 0.

void reset_pid_targets();

set_angle()​

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 angle that the robot will think it's now facing

void set_angle(double angle);

set_max_speed()​

Sets the max speed of the drive.

speed an integer between -127 and 127.

void set_max_speed(int speed);

set_pid_constants()​

note

Note: this function was changed with 2.0.1

Set PID constants. Below are the defaults.

pid either &chassis.headingPID, &chassis.forward_drivePID, &chassis.backward_drivePID, &chassis.turnPID, or &chassis.swingPID
p proportion constant
i integral constant d derivative constant
p_start_i error needs to be within this for i to start

void set_pid_constants(PID* pid, double p, double i, double d, double p_start_i);

set_slew_min_power()​

Sets the starting speed for slew, with the ability to have different constants for forward and reverse. Below are the defaults.

fwd integer between -127 and 127 rev integer between -127 and 127

void set_slew_min_power(int fwd, int rev);

set_slew_distance()​

Sets the distance the drive will slew for, with the ability to have different constants for forward and reverse. Input is inches. Below are the defaults.

fwd a distance in inches
rev a distance in inches

void set_slew_distance (int fwd, int rev);

set_exit_condition()​

Sets the exit condition constants. This uses the exit conditions from the PID class. Below are the defaults.

type either chassis.turn_exit, chassis.swing_exit, or chassis.drive_exit
p_small_exit_time time, in ms, before exiting p_small_error
p_small_error small error threshold
p_big_exit_time time, in ms, before exiting p_big_error
p_big_error big error threshold
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 set_exit_condition(exit_condition_ &type, 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);

set_swing_min()​

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 set_swing_min(int min);

set_turn_min()​

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 set_turn_min(int min);

set_mode()​

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 set_mode(e_mode p_mode);

toggle_auto_drive()​

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 toggle_auto_drive(bool toggle);

toggle_auto_print()​

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 toggle_auto_print(bool toggle);

Getter​

get_swing_min()​

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

int get_swing_min();

get_turn_min()​

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

int get_turn_min();

interfered​

Boolean that returns true when wait_drive() or 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;

get_mode()​

Returns the current drive mode that the task is running. Returns ez::DISABLE, ez::SWING, ez::TURN, ez::DRIVE.

e_mode get_mode();

get_tick_per_inch()​

Returns the conversion between raw sensor value and inches.

double get_tick_per_inch();

Misc.​

wait_drive()​

Locks the code in place until the drive has settled. This uses the exit conditions from the PID class.

void wait_drive();

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

void wait_until(double target);