rotación#

Inicializando la clase de rotación#

Un sensor de rotación se crea utilizando el siguiente constructor:

The rotation constructor creates a rotation object in the specified Port with the reverse flag set to the specified value.

Parámetro

Descripción

port

Un Puerto inteligente válido al que está conectado el sensor de rotación.

reverse

Set to true to reverse the angle and position returned by the Rotation Sensor. The default is false.

// Construct a Rotation Sensor "Rotation" with the
// rotation class.
rotation Rotation = rotation(PORT1, false);

This Rotation object will be used in all subsequent examples throughout this API documentation when referring to rotation class methods.

Métodos de clase#

setReversed()#

The setReversed(value) method sets the rotation direction to be reversed.

Parámetros

Descripción

valor

Un valor booleano para establecer si la dirección se invierte o no.

Devoluciones: Ninguna.

// Set the rotation direction to reverse.
Rotation.setReversed(true);

angle()#

The angle(units) method returns the angle measured by the Rotation Sensor.

Parámetros

Descripción

unidades

Una rotationUnit válida.

Devuelve: Un doble que representa el ángulo medido por el sensor de rotación en las unidades especificadas.

// Get the current angle of the Rotation Sensor
double angle = Rotation.angle(degrees);

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

resetPosition()#

The resetPosition() method resets the position of the Rotation Sensor to 0.

Devoluciones: Ninguna.

setPosition()#

The setPosition(value, units) method sets the position of the Rotation Sensor. The position returned by the position() method is set to this value.

Parámetros

Descripción

valor

El valor de posición a establecer.

unidades

Una rotationUnit válida.

Devoluciones: Ninguna.

position()#

The position(units) method returns the current position of the Rotation Sensor.

Parámetros

Descripción

unidades

Una rotationUnit válida.

Devuelve: Un doble que representa la posición actual del sensor de rotación en las unidades especificadas.

velocity()#

The velocity(units) method returns the velocity of the Rotation Sensor.

Parámetros

Descripción

unidades

Una velocityUnit válida.

Devuelve: Un doble que representa la velocidad del sensor de rotación en las unidades especificadas.

changed()#

The changed(callback) method registers a callback function for when the value measured by the Rotation Sensor changes.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando cambie el valor medido por el sensor de rotación.

Devoluciones: Ninguna.

// Define the rotationChanged function with a void
// return type, showing it doesn't return a value.
void rotationChanged() {
  // The Brain will print that the value of the Rotation Sensor
  // changed on the Brain's screen.
  Brain.Screen.print("Rotation Sensor value changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run rotationChanged when the value of the
  // Rotation Sensor changes.
  Rotation.changed(rotationChanged);
}

timestamp()#

The timestamp() method requests the timestamp of the last received status packet from the Rotation Sensor.

Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.

installed()#

The installed() method returns if the Rotation Sensor is connected.

Returns: true if the Rotation Sensor is installed. false if it is not.