Miscellaneous C++ API module

Contents

///

Classes

class pros::v5::Controller

Functions

Controller(controller_id_e_t id) explicit
Creates a controller object for the given controller id.
std::int32_t is_connected(void)
Checks if the controller is connected.
std::int32_t get_analog(controller_analog_e_t channel)
Gets the value of an analog channel (joystick) on a controller.
std::int32_t get_battery_capacity(void)
Gets the battery capacity of the controller.
std::int32_t get_battery_level(void)
Gets the battery level of the controller.
std::int32_t get_digital(controller_digital_e_t button)
Checks if a digital channel (button) on the controller is currently pressed.
std::int32_t get_digital_new_press(controller_digital_e_t button)
Returns a rising-edge case for a controller button press.
template<typename T>
T convert_args(T arg)
const char* convert_args(const std::string& arg)
template<typename... Params>
std::int32_t print(std::uint8_t line, std::uint8_t col, const char* fmt, Params... args)
Sets text to the controller LCD screen.
std::int32_t set_text(std::uint8_t line, std::uint8_t col, const char* str)
Sets text to the controller LCD screen.
std::int32_t set_text(std::uint8_t line, std::uint8_t col, const std::string& str)
std::int32_t clear_line(std::uint8_t line)
Clears an individual line of the controller screen.
std::int32_t rumble(const char* rumble_pattern)
Rumble the controller.
std::int32_t clear(void)
Clears all of the lines on the controller screen.
double get_capacity(void)
Gets the current voltage of the battery, as reported by VEXos.
int32_t get_current(void)
Gets the current current of the battery in milliamps, as reported by VEXos.
double get_temperature(void)
Gets the current temperature of the battery, as reported by VEXos.
int32_t get_voltage(void)
Gets the current capacity of the battery in millivolts, as reported by VEXos.

Variables

controller_id_e_t _id

Function documentation

Controller(controller_id_e_t id) explicit

Creates a controller object for the given controller id.

Parameters
id The ID of the controller (e.g. the master or partner controller). Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER

std::int32_t is_connected(void)

Checks if the controller is connected.

Returns 1 if the controller is connected, 0 otherwise

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void status_display_controller(){
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  if(!master.is_connected()) {
       pros::lcd::print(0, "Main controller is not connected!");
  }
}

std::int32_t get_analog(controller_analog_e_t channel)

Gets the value of an analog channel (joystick) on a controller.

Parameters
channel The analog channel to get. Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X, ANALOG_RIGHT_Y
Returns The current reading of the analog channel: [-127, 127]. If the controller was not connected, then 0 is returned

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  while (true) {
    motor_move(1, master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));
    delay(2);
  }
}

std::int32_t get_battery_capacity(void)

Gets the battery capacity of the controller.

Returns The controller's battery capacity

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void initialize() {
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  printf("Battery Capacity: %d\n", master.get_battery_capacity());
}

std::int32_t get_battery_level(void)

Gets the battery level of the controller.

Returns The controller's battery level

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void initialize() {
     pros::Controller master(pros::E_CONTROLLER_MASTER);
  printf("Battery Level: %d\n", master.get_battery_level());
}

std::int32_t get_digital(controller_digital_e_t button)

Checks if a digital channel (button) on the controller is currently pressed.

Parameters
button The button to read. Must be one of DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
Returns 1 if the button on the controller is pressed. If the controller was not connected, then 0 is returned

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  while (true) {
  if (master.get_digital(pros::E_CONTROLLER_DIGITAL_A)) {
    motor_set(1, 100);
  }
  else {
    motor_set(1, 0);
  }
    delay(2);
  }
}

std::int32_t get_digital_new_press(controller_digital_e_t button)

Returns a rising-edge case for a controller button press.

Parameters
button The button to read. Must be one of DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
Returns 1 if the button on the controller is pressed and had not been pressed the last time this function was called, 0 otherwise.

This function is not thread-safe. Multiple tasks polling a single button may return different results under the same circumstances, so only one task should call this function for any given button. E.g., Task A calls this function for buttons 1 and 2. Task B may call this function for button 3, but should not for buttons 1 or 2. A typical use-case for this function is to call inside opcontrol to detect new button presses, and not in any other tasks.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
    pros::Controller master(pros::E_CONTROLLER_MASTER);
    while (true) {
  if (master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) {
    // Toggle pneumatics or other similar actions
  }

  delay(2);
  }
}

template<typename T>
T convert_args(T arg)

const char* convert_args(const std::string& arg)

template<typename... Params>
std::int32_t print(std::uint8_t line, std::uint8_t col, const char* fmt, Params... args)

Sets text to the controller LCD screen.

Parameters
line The line number at which the text will be displayed [0-2]
col The column number at which the text will be displayed [0-14]
fmt The format string to print to the controller
args
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
  int count = 0;
     pros::Controller master(pros::E_CONTROLLER_MASTER);
  while (true) {
  if (!(count % 25)) {
    // Only print every 50ms, the controller text update rate is slow
    master.print(0, 0, "Counter: %d", count);
  }
    count++;
    delay(2);
  }
}

std::int32_t set_text(std::uint8_t line, std::uint8_t col, const char* str)

Sets text to the controller LCD screen.

Parameters
line The line number at which the text will be displayed [0-2]
col The column number at which the text will be displayed [0-14]
str The pre-formatted string to print to the controller
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
  int count = 0;
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  while (true) {
    if (!(count % 25)) {
      // Only print every 50ms, the controller text update rate is slow
      master.set_text(0, 0, "Example text");
    }
  count++;
  delay(2);
  }
}

std::int32_t set_text(std::uint8_t line, std::uint8_t col, const std::string& str)

std::int32_t clear_line(std::uint8_t line)

Clears an individual line of the controller screen.

Parameters
line The line number to clear [0-2]
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  master.set_text(0, 0, "Example");
  delay(100);
  master.clear_line(0);
}

std::int32_t rumble(const char* rumble_pattern)

Rumble the controller.

Parameters
rumble_pattern A string consisting of the characters '.', '-', and ' ', where dots are short rumbles, dashes are long rumbles, and spaces are pauses. Maximum supported length is 8 characters.
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
  int count = 0;
  pros::Controller master(pros::E_CONTROLLER_MASTER);
  while (true) {
  if (!(count % 25)) {
    // Only send every 50ms, the controller update rate is slow
    master.rumble(". - . -");
  }
  count++;
  delay(2);
  }
}

std::int32_t clear(void)

Clears all of the lines on the controller screen.

Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the controller port.

Example

void opcontrol() {
     pros::Controller master(pros::E_CONTROLLER_MASTER);
  master.set_text(0, 0, "Example");
  delay(100);
  master.clear();
}

double get_capacity(void)

Gets the current voltage of the battery, as reported by VEXos.

Returns The current voltage of the battery

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the battery port.

Example

void initialize() {
  printf("Battery Level: %.2f\n", get_capacity());
}

int32_t get_current(void)

Gets the current current of the battery in milliamps, as reported by VEXos.

Returns The current current of the battery

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the battery port.

Example

void initialize() {
  printf("Battery Current: %d\n", get_current());
}

double get_temperature(void)

Gets the current temperature of the battery, as reported by VEXos.

Returns The current temperature of the battery

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the battery port.

Example

void initialize() {
  printf("Battery's Temperature: %.2f\n", get_temperature());
}

int32_t get_voltage(void)

Gets the current capacity of the battery in millivolts, as reported by VEXos.

Returns The current capacity of the battery

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the battery port.

Example

void initialize() {
  printf("Battery's Voltage: %d\n", get_voltage());
}

Variable documentation

controller_id_e_t _id