User Control
Drive Modes
opcontrol_tank()
Sets the drive to the left and right y axis.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
pros::delay(ez::util::DELAY_TIME);
}
}
void opcontrol_tank();
opcontrol_arcade_standard()
Sets the drive to standard arcade. Left stick is fwd/rev.
stick_type
is either ez::SPLIT
or ez::SINGLE
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_arcade_standard(ez::SPIT); // For split arcade
// chassis.opcontrol_arcade_standard(ez::SINGLE); // For single arcade
pros::delay(ez::util::DELAY_TIME);
}
}
void opcontrol_arcade_standard(e_type stick_type);
opcontrol_arcade_flipped()
Sets the drive to flipped arcade. Right stick is fwd/rev.
stick_type
is either ez::SPLIT
or ez::SINGLE
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_arcade_flipped(ez::SPIT); // For split arcade
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // For single arcade
pros::delay(ez::util::DELAY_TIME);
}
}
void opcontrol_arcade_flipped(e_type stick_type);
Joystick Curves
opcontrol_curve_sd_initialize()
Sets the left/right curve constants to what's on the SD card. If the SD card is empty, creates needed files.
- Prototype
- Example
void initialize() {
chassis.opcontrol_curve_sd_initialize();
}
void opcontrol_curve_sd_initialize();
opcontrol_curve_default_sets()
Sets the left/right curve defaults and saves new values to the SD card.
left
left input curve
right
right input curve
- Prototype
- Example
void initialize() {
chassis.opcontrol_curve_default_sets(2, 2);
}
void opcontrol_curve_default_set(double left, double right);
opcontrol_curve_buttons_toggle()
Enables/disables buttons used for modifying the controller curve with the joystick.
toggle
true enables, false disables
- Prototype
- Example
void initialize() {
chassis.opcontrol_curve_buttons_toggle(true);
}
void opcontrol_curve_buttons_toggle(bool toggle);
opcontrol_curve_buttons_toggle_get()
Returns true if modifying the curve with the controller is enabled, and false if it isn't.
- Prototype
- Example
void initialize() {
printf("Enabled? %i\n", chassis.opcontrol_curve_buttons_toggle_get()); // Returns false
chassis.opcontrol_curve_buttons_toggle(true);
printf("Enabled? %i\n", chassis.opcontrol_curve_buttons_toggle_get()); // Returns true
}
bool opcontrol_curve_buttons_toggle_get();
opcontrol_curve_buttons_left_set()
Sets the buttons that are used to modify the left input curve. The example is the default.
decrease
a pros button
increase
a pros button
- Prototype
- Example
void initialize() {
chassis.opcontrol_curve_buttons_left_set(pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT);
}
void opcontrol_curve_buttons_left_set(pros::controller_digital_e_t decrease, pros::controller_digital_e_t increase);
opcontrol_curve_buttons_right_set()
Sets the buttons that are used to modify the right input curve. The example is the default.
decrease
a pros button
increase
a pros button
- Prototype
- Example
void initialize() {
chassis.opcontrol_curve_buttons_right_set(pros::E_CONTROLLER_DIGITAL_Y, pros::E_CONTROLLER_DIGITAL_A);
}
void opcontrol_curve_buttons_right_set(pros::controller_digital_e_t decrease, pros::controller_digital_e_t increase);
opcontrol_curve_left()
Returns the input times the curve here. opcontrol_tank()
, opcontrol_arcade_standard()
, and opcontrol_arcade_flipped()
all handle this for you. When tank is enabled, only this curve is used.
x
input value
- Prototype
- Example
void opcontrol() {
while (true) {
int l_stick = opcontrol_curve_left(master.get_analog(ANALOG_LEFT_Y));
int r_stick = opcontrol_curve_left(master.get_analog(ANALOG_RIGHT_Y));
chassis.drive_set(l_stick, r_stick);
pros::delay(ez::util::DELAY_TIME);
}
}
double opcontrol_curve_left(double x);
opcontrol_curve_right()
Returns the input times the curve here. opcontrol_tank()
, opcontrol_arcade_standard()
, and opcontrol_arcade_flipped()
all handle this for you.
x
input value
- Prototype
- Example
void opcontrol() {
while (true) {
int l_stick = opcontrol_curve_left(master.get_analog(ANALOG_LEFT_Y));
int r_stick = opcontrol_curve_left(master.get_analog(ANALOG_RIGHT_Y));
chassis.drive_set(l_stick, r_stick);
pros::delay(ez::util::DELAY_TIME);
}
}
double opcontrol_curve_right(double x);
opcontrol_curve_buttons_iterate()
Allows the user to modify the curve with the controller.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_joystick_threshold_opcontrol(master.get_analog(ANALOG_LEFT_Y), master.get_analog(ANALOG_RIGHT_Y));
chassis.opcontrol_curve_buttons_iterate();
pros::delay(ez::util::DELAY_TIME);
}
chassis.opcontrol_joystick_threshold_set(5);
}
void opcontrol_curve_buttons_iterate();
Joystick General
opcontrol_joystick_threshold_set()
Threshold the joystick will return 0 within. This is useful because not all joysticks will return perfectly to 0 when let go.
threshold
an integer, recommended to be less then 5
- Prototype
- Example
void initialize() {
chassis.opcontrol_joystick_threshold_set(5);
}
void opcontrol_joystick_threshold_set(int threshold);
opcontrol_joystick_threshold_opcontrol()
Runs the joystick control. Sets the left drive to l_stick
, and right drive to r_stick
. Runs active brake and joystick thresholds.
l_stick
left joystick value
r_stick
right joystick value
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_joystick_threshold_opcontrol(master.get_analog(ANALOG_LEFT_Y), master.get_analog(ANALOG_RIGHT_Y));
pros::delay(ez::util::DELAY_TIME);
}
chassis.opcontrol_joystick_threshold_set(5);
}
void opcontrol_joystick_threshold_opcontrol(int l_stick, int r_stick);
Active Brake
opcontrol_drive_activebrake_set()
Active brake runs a P loop on the drive when joysticks are within their threshold.
kp
proportional constant for drive
- Prototype
- Example
void initialize() {
chassis.opcontrol_drive_activebrake_set(2.0);
}
void opcontrol_drive_activebrake_set(double kp);
opcontrol_drive_activebrake_get()
Returns the kP of active brake.
- Prototype
- Example
void initialize() {
chassis.opcontrol_drive_activebrake_set(0.1);
printf("kP is: %f\n", chassis.opcontrol_drive_activebrake_get);
}
double opcontrol_drive_activebrake_get();
Reversing Drive
opcontrol_drive_reverse_set()
Setting this to true reverses the drive direction during opcontrol, and false reverts it back to normal.
toggle
reverses or reverts drive direction.
- Prototype
- Example
void opcontrol() {
while (true) {
if (master.get_digital_new_press(DIGITAL_B))
chassis.opcontrol_drive_reverse_set(!chassis.opcontrol_drive_reverse_get());
chassis.opcontrol_tank();
pros::delay(10);
}
}
void opcontrol_drive_reverse_set(bool toggle);
opcontrol_drive_reverse_get()
Returns true
if the drive is currently reversed, and false
if it isn't.
- Prototype
- Example
void opcontrol() {
while (true) {
if (master.get_digital_new_press(DIGITAL_B))
chassis.opcontrol_drive_reverse_set(!chassis.opcontrol_drive_reverse_get());
chassis.opcontrol_tank();
pros::delay(10);
}
}
bool opcontrol_drive_reverse_get();