Sensor de rotación#

Introducción#

The rotation class is used to control and access data from an EXP Rotation Sensor.

El Sensor de Rotación mide la rotación de un eje. Puede utilizarse en cualquier parte de un robot donde gire un eje, incluso si este no está conectado directamente a un motor.

Un motor incorpora un codificador que registra su propia rotación. El sensor de rotación funciona como un codificador externo que registra la rotación de un eje independiente.

El sensor de rotación puede devolver el ángulo, la posición y la velocidad del eje. El ángulo es la posición absoluta del eje, de 0 a 359,99 grados. No se reinicia al iniciar un proyecto ni al apagar el robot. La posición registra cuántos grados o vueltas ha girado el eje hacia adelante o hacia atrás durante un proyecto, y se puede reiniciar según sea necesario.

El sensor de rotación es compatible con ejes VEX estándar de 1/8 de pulgada y 1/4 de pulgada.

Constructores de clases#

rotation(
    int32_t index,
    bool    reverse = false );

Instructor de clase#

Destroys the rotation object and releases associated resources.

virtual ~rotation();

Parámetros#

Parámetro

Tipo

Descripción

index

int32_t

The Smart Port that the Rotation Sensor is connected to, written as PORTx, where x is the port number (for example, PORT1).

reverse

bool

Optional. Whether to reverse the Rotation Sensor output:

  • true — Reverses the direction of the reported angle and position values.
  • false (default) — Reports angle and position values in the standard direction.

Ejemplos#

// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);

Funciones de los miembros#

The rotation class includes the following member functions:

  • setPosition — Sets the Rotation Sensor’s current position to a specific value.

  • angle — Returns the shaft’s current angle from 0 to 359.99 degrees.

  • position — Returns how far the shaft has rotated in degrees or turns.

  • velocity — Returns how fast the shaft is rotating.

Before calling any rotation member functions, a rotation instance must be created, as shown below:

/* This constructor is required when using VS Code.
Rotation Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);

setPosition#

Establece la posición actual del sensor de rotación a un valor específico.

La posición indica cuánto ha girado el eje durante un proyecto. Al ajustar la posición, se modifica el valor actual de la misma sin mover el eje.

Available Functions
void setPosition(
    double        value,
    rotationUnits units );

Parameters

Parámetro

Tipo

Descripción

value

double

El valor de posición que se asignará al sensor de rotación. Puede ser un número entero o decimal.

units

rotationUnits

The position unit:

  • deg / degrees — degrees
  • turns / rev — turns

Return Values

Esta función no devuelve ningún valor.

angle#

Devuelve el ángulo actual del eje.

El indicador de ángulo muestra la posición absoluta del eje dentro de una rotación, desde 0 hasta 359,99 grados. No se reinicia al iniciar un proyecto ni al apagar el robot.

Available Functions
double angle( rotationUnits units = degrees );

Parameters

Parámetro

Tipo

Descripción

units

rotationUnits

Optional. The angle unit:

  • deg / degrees (default) — degrees
  • turns / rev — turns

Return Values

Returns a double representing the shaft’s current angle in the specified units.

Examples
// Get the current angle of the shaft
  double angle = Rotation1.angle(degrees);

  // Print the current angle of the shaft to the
  // Brain's screen.
  Brain.Screen.print(angle);

position#

Indica cuánto ha girado el eje.

A diferencia del ángulo, la posición puede superar los 359,99 grados o disminuir por debajo de los 0 grados. La posición registra cuánto gira el eje hacia adelante o hacia atrás durante un proyecto y se puede restablecer según sea necesario.

Available Functions
double position( rotationUnits units );

Parameters

Parámetro

Tipo

Descripción

units

rotationUnits

The position unit:

  • deg / degrees — degrees
  • turns / rev — turns

Return Values

Returns a double representing how far the shaft has rotated in the specified units.

velocity#

Indica la velocidad de rotación del eje.

Available Functions
double velocity( velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

units

velocityUnits

The velocity unit:

  • rpm — revolutions per minute
  • dps — degrees per second

Return Values

Returns a double representing how fast the shaft is rotating in the specified units.