VEX Rotation Sensor C++ API module

Contents

Files

file rotation.hpp

Classes

class pros::v5::Rotation

Functions

Rotation(const std::int8_t port)
Constructs a new Rotation Sensor object.
Rotation(const Device& device)
std::int32_t reset() virtual
Reset the Rotation Sensor.
std::int32_t set_data_rate(std::uint32_t rate) const virtual
Set the Rotation Sensor's refresh interval in milliseconds.
std::int32_t set_position(std::uint32_t position) const virtual
Set the Rotation Sensor position reading to a desired rotation value.
std::int32_t reset_position(void) const virtual
Reset the Rotation Sensor position to 0.
static std::vector<Rotation> get_all_devices()
Gets all rotation sensors.
std::int32_t get_position() const virtual
Get the Rotation Sensor's current position in centidegrees.
std::int32_t get_velocity() const virtual
Get the Rotation Sensor's current velocity in centidegrees per second.
std::int32_t get_angle() const virtual
Get the Rotation Sensor's current position in centidegrees.
std::int32_t set_reversed(bool value) const virtual
Set the Rotation Sensor's direction reversed flag.
std::int32_t reverse() const virtual
Reverse the Rotation Sensor's direction.
std::int32_t get_reversed() const virtual
Get the Rotation Sensor's reversed flag.

Function documentation

Rotation(const std::int8_t port)

Constructs a new Rotation Sensor object.

Parameters
port The V5 port number from 1 to 21, or from -21 to -1 for reversed Rotation Sensors.

ENXIO - The given value is not within the range of V5 ports |1-21|. ENODEV - The port cannot be configured as a Rotation Sensor

Example

void opcontrol() {
     pros::Rotation rotation_sensor(1); //Creates a Rotation Sensor on port 1
  pros::Rotation reversed_rotation_sensor(-2); //Creates a reversed Rotation Sensor on port 2
}

Rotation(const Device& device)

std::int32_t reset() virtual

Reset the Rotation Sensor.

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

Reset the current absolute position to be the same as the Rotation Sensor angle.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
  pros::Rotation rotation_sensor(1);
  pros::Controller master (E_CONTROLLER_MASTER);
  while (true) {
    if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
         rotation_sensor.reset();
    }
    pros::delay(20);
  }
}

std::int32_t set_data_rate(std::uint32_t rate) const virtual

Set the Rotation Sensor's refresh interval in milliseconds.

Parameters
rate The data refresh interval in milliseconds
Returns 1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

The rate may be specified in increments of 5ms, and will be rounded down to the nearest increment. The minimum allowable refresh rate is 5ms. The default rate is 10ms.

As values are copied into the shared memory buffer only at 10ms intervals, setting this value to less than 10ms does not mean that you can poll the sensor's values any faster. However, it will guarantee that the data is as recent as possible.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void initialize() {
  pros::Rotation rotation_sensor(1);
  rotation_sensor.set_data_rate(5);
}

std::int32_t set_position(std::uint32_t position) const virtual

Set the Rotation Sensor position reading to a desired rotation value.

Parameters
position The position in terms of ticks
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: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
  pros::Rotation rotation_sensor(1);
  pros::Controller master (E_CONTROLLER_MASTER);
  while (true) {
    if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
         rotation_sensor.set_position(600);
    }
    pros::delay(20);
  }
}

std::int32_t reset_position(void) const virtual

Reset the Rotation Sensor position to 0.

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: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
  pros::Rotation rotation_sensor(1);
  pros::Controller master (E_CONTROLLER_MASTER);
  while (true) {
    if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
         rotation_sensor.reset_position();
    }
    pros::delay(20);
  }
}

static std::vector<Rotation> get_all_devices()

Gets all rotation sensors.

Returns A vector of Rotation sensor objects.

Example

void opcontrol() {
  std::vector<Rotation> rotation_all = pros::Rotation::get_all_devices();  // All rotation sensors that are connected
}

std::int32_t get_position() const virtual

Get the Rotation Sensor's current position in centidegrees.

Returns The position value or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
     pros::Rotation rotation_sensor(1);
  while (true) {
    printf("Position: %d Ticks \n", rotation_sensor.get_position());
    delay(20);
  }
}

std::int32_t get_velocity() const virtual

Get the Rotation Sensor's current velocity in centidegrees per second.

Returns The velocity value or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
     pros::Rotation rotation_sensor(1);
  while (true) {
    printf("Velocity: %d centidegrees per second \n", rotation_sensor.get_velocity));
    delay(20);
  }
}

std::int32_t get_angle() const virtual

Get the Rotation Sensor's current position in centidegrees.

Returns The angle value or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
     pros::Rotation rotation_sensor(1);
  while (true) {
    printf("Angle: %d centidegrees \n", rotation_sensor.get_angle());
    delay(20);
  }
}

std::int32_t set_reversed(bool value) const virtual

Set the Rotation Sensor's direction reversed flag.

Parameters
value Determines if the direction of the rotational sensor is reversed or not.
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: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
  pros::Rotation rotation_sensor(1);
  pros::Controller master (E_CONTROLLER_MASTER);
  while (true) {
    if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
         rotation_sensor.set_reversed(true); // Reverses the Rotation Sensor
    }
    pros::delay(20);
  }
}

std::int32_t reverse() const virtual

Reverse the Rotation Sensor's direction.

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: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
  pros::Rotation rotation_sensor(1);
  pros::Controller master (E_CONTROLLER_MASTER);
  while (true) {
    if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
         rotation_sensor.reverse();
    }
    pros::delay(20);
  }
}

std::int32_t get_reversed() const virtual

Get the Rotation Sensor's reversed flag.

Returns Reversed value or PROS_ERR if the operation failed, setting errno.

This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports (1-21). ENODEV - The port cannot be configured as an Rotation Sensor

Example

void opcontrol() {
     pros::Rotation rotation_sensor(1);
  while (true) {
    printf("Reversed: %d \n", rotation_sensor.get_reversed());
    delay(20);
  }
}