VEX Rotation Sensor C API module

Contents

Files

file rotation.h

Functions

int32_t rotation_reset(uint8_t port)
Reset Rotation Sensor.
int32_t rotation_set_data_rate(uint8_t port, uint32_t rate)
Set the Rotation Sensor's refresh interval in milliseconds.
int32_t rotation_set_position(uint8_t port, uint32_t position)
Set the Rotation Sensor position reading to a desired rotation value.
int32_t rotation_reset_position(uint8_t port)
Reset the Rotation Sensor position to 0.
int32_t rotation_get_position(uint8_t port)
Get the Rotation Sensor's current position in centidegrees.
int32_t rotation_get_velocity(uint8_t port)
Get the Rotation Sensor's current velocity in centidegrees per second.
int32_t rotation_get_angle(uint8_t port)
Get the Rotation Sensor's current angle in centidegrees (0-36000)
int32_t rotation_set_reversed(uint8_t port, bool value)
Set the Rotation Sensor's direction reversed flag.
int32_t rotation_reverse(uint8_t port)
Reverse the Rotation Sensor's direction.
int32_t rotation_init_reverse(uint8_t port, bool reverse_flag)
Initialize the Rotation Sensor with a reverse flag.
int32_t rotation_get_reversed(uint8_t port)
Get the Rotation Sensor's reversed flag.

Defines

#define ROTATION_MINIMUM_DATA_RATE

Function documentation

int32_t rotation_reset(uint8_t port)

Reset Rotation Sensor.

Parameters
port The V5 Rotation Sensor port number from 1-21
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

#define ROTATION_PORT 1

void opcontrol() {
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_reset(ROTATION_PORT);
    }
    delay(20);
  }
}

int32_t rotation_set_data_rate(uint8_t port, uint32_t rate)

Set the Rotation Sensor's refresh interval in milliseconds.

Parameters
port The V5 Rotation Sensor port number from 1-21
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.

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

#define ROTATION_PORT 1

void initialize() {
  pros::Rotation rotation_sensor(ROTATION_PORT);
  rotation_set_data_rate(ROTATION_PORT, 5);
}

int32_t rotation_set_position(uint8_t port, uint32_t position)

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

Parameters
port The V5 Rotation Sensor port number from 1-21
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

#define ROTATION_PORT 1

void opcontrol() {
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_set_position(ROTATION_PORT, 600);
    }
  delay(20);
  }
}

int32_t rotation_reset_position(uint8_t port)

Reset the Rotation Sensor position to 0.

Parameters
port The V5 Rotation Sensor port number from 1-21
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

#define ROTATION_PORT 1

void opcontrol() {
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_reset_position(ROTATION_PORT);
    }
      delay(20);
    }
}

int32_t rotation_get_position(uint8_t port)

Get the Rotation Sensor's current position in centidegrees.

Parameters
port The V5 Rotation Sensor port number from 1-21
Returns The position value or PROS_ERR_F 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

#define ROTATION_PORT 1

void opcontrol() {
  while (true) {
    printf("Position: %d centidegrees \n", rotation_get_position(ROTATION_PORT));
    delay(20);
  }
}

int32_t rotation_get_velocity(uint8_t port)

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

Parameters
port The V5 Rotation Sensor port number from 1-21
Returns The velocity value or PROS_ERR_F 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

#define ROTATION_PORT 1

void opcontrol() {
  while (true) {
    printf("Velocity: %d centidegrees per second \n", rotation_get_velocity(ROTATION_PORT));
    delay(20);
  }
}

int32_t rotation_get_angle(uint8_t port)

Get the Rotation Sensor's current angle in centidegrees (0-36000)

Parameters
port The V5 Rotation Sensor port number from 1-21
Returns The angle value (0-36000) or PROS_ERR_F 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

#define ROTATION_PORT 1

void opcontrol() {
  while (true) {
    printf("Angle: %d centidegrees \n", rotation_get_angle(ROTATION_PORT));
    delay(20);
  }
}

int32_t rotation_set_reversed(uint8_t port, bool value)

Set the Rotation Sensor's direction reversed flag.

Parameters
port The V5 Rotation Sensor port number from 1-21
value Determines if the direction of the Rotation Sensor is reversed or not.
Returns 1 if operation succeeded 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

#define ROTATION_PORT 1

void opcontrol() {
  Rotation rotation_sensor(ROTATION_PORT);
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_set_reversed(ROTATION_PORT, true); // Reverses the Rotation Sensor on ROTATION_PORT
    }
    delay(20);
  }
}

int32_t rotation_reverse(uint8_t port)

Reverse the Rotation Sensor's direction.

Parameters
port The V5 Rotation Sensor port number from 1-21
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

#define ROTATION_PORT 1

void opcontrol() {
  Rotation rotation_sensor(ROTATION_PORT);
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_reverse(ROTATION_PORT);
    }
    delay(20);
  }
}

int32_t rotation_init_reverse(uint8_t port, bool reverse_flag)

Initialize the Rotation Sensor with a reverse flag.

Parameters
port The V5 Rotation Sensor port number from 1-21
reverse_flag Determines if the Rotation 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

#define ROTATION_PORT 1

void opcontrol() {
  Rotation rotation_sensor(ROTATION_PORT);
  bool reverse_flag = true;
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_init_reverse(ROTATION_PORT, reverse_flag);
    }
    delay(20);
  }
}

int32_t rotation_get_reversed(uint8_t port)

Get the Rotation Sensor's reversed flag.

Parameters
port The V5 Rotation Sensor port number from 1-21
Returns Boolean value of if the Rotation Sensor's direction is reversed or not 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

#define ROTATION_PORT 1

void opcontrol() {
  Rotation rotation_sensor(ROTATION_PORT);
  while (true) {

    if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
      rotation_get_reversed(ROTATION_PORT);
    }
  delay(20);
  }
}

Define documentation