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 |
|---|---|---|
|
|
The Smart Port that the Rotation Sensor is connected to, written as |
|
|
Optional. Whether to reverse the Rotation Sensor output:
|
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 Functionsvoid setPosition(
double value,
rotationUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
El valor de posición que se asignará al sensor de rotación. Puede ser un número entero o decimal. |
|
|
The position unit:
|
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 Functionsdouble angle( rotationUnits units = degrees );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Optional. The angle unit:
|
Returns a double representing the shaft’s current angle in the specified units.
// 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 Functionsdouble position( rotationUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The position unit:
|
Returns a double representing how far the shaft has rotated in the specified units.
velocity#
Indica la velocidad de rotación del eje.
Available Functionsdouble velocity( velocityUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The velocity unit:
|
Returns a double representing how fast the shaft is rotating in the specified units.