Rotación#

Inicializando la clase de rotación#

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

Rotation(port, reverse)

Este constructor utiliza un parámetro:

Parámetro

Descripción

port

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

reverse

Optional. 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(Ports.PORT1)

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

Métodos de clase#

set_reversed()#

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

Este es un método sin espera y permite que el siguiente método se ejecute sin demora.

Parámetros

Descripción

valor

True to reverse the motor direction. False to maintain the normal direction.

Devoluciones: Ninguna.

# Set the direction to be reversed.
rotation.set_reversed(True)

angle()#

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

Parámetros

Descripción

unidades

Optional. A valid RotationUnits type. The default is DEGREES.

Devuelve: El ángulo medido por el sensor de rotación en las unidades especificadas.

# Print the current angle of the Rotation Sensor to the
# Brain's screen.
brain.screen.print(rotation.angle())

restablecer_posición()#

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

Devoluciones: Ninguna.

set_position()#

The set_position(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

Optional. A valid RotationUnits type. The default is DEGREES.

Devoluciones: Ninguna.

position()#

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

Parámetros

Descripción

unidades

Optional. A valid RotationUnits type. The default is DEGREES.

Devuelve: 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

Optional. A valid VelocityUnits type. The default is RPM.

Devuelve: La velocidad del sensor de rotación en las unidades especificadas.

changed()#

The changed(callback, arg) 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.

arg

Opcional. Una tupla de argumentos para pasar a la función de devolución de llamada.

Devoluciones: Ninguna

# Define a function rotation_changed().
def rotation_changed():
    # The Brain will print that the rotation value changed
    # on the Brain's screen.
    brain.screen.print("rotation value changed")

# Run rotation_changed when the value of the
# Rotation Sensor changes.
rotation.changed(rotation_changed)

installed()#

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

Returns: True if the Rotation Sensor is installed. False if it is not.

timestamp()#

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

Devuelve: La marca de tiempo del último paquete de estado recibido en milisegundos.