Sensor de rotación#

Introducción#

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.

El sensor de rotación VEX EXP.

This page uses rotation_sensor as the example Rotation Sensor name. Replace it with your own configured name as needed.

A continuación se muestra una lista de los métodos disponibles:

  • set_position — 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.

  • reset_position — Resets the Rotation Sensor’s current position to 0.

  • set_reversed — Sets whether the Rotation Sensor’s output is reversed.

  • changed — Registers a function to run whenever the Rotation Sensor’s value changes.

Constructor: Inicializa manualmente un sensor de rotación.

  • Rotation — Creates a Rotation Sensor.

posición_de_establecer#

set_position sets the Rotation Sensor’s current position to a value.

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.

Usage:
rotation_sensor.set_position(position, units)

Parámetros

Descripción

position

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

units

Optional. The position unit: DEGREES (default) or TURNS.

# Set the Rotation Sensor to 2.5 Turns
rotation_sensor.set_position(2.5, TURNS)

ángulo#

angle returns the shaft’s current angle as a float.

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.

Usage:
rotation_sensor.angle(units)

Parámetros

Descripción

units

Optional. The angle unit: DEGREES (default) or TURNS.

posición#

position returns how far the shaft has rotated.

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.

Usage:
rotation_sensor.position(units)

Parámetros

Descripción

units

Optional. The position unit: DEGREES (default) or TURNS.

velocidad#

velocity returns how fast the shaft is rotating.

Usage:
rotation_sensor.velocity(units)

Parámetros

Descripción

units

The velocity unit: VelocityUnits.RPM (revolutions per minute) or VelocityUnits.DPS (degrees per second).

restablecer_posición#

reset_position resets the Rotation Sensor’s current position to 0.

Usage:
rotation_sensor.reset_position()

Parámetros

Descripción

Este método no tiene parámetros.

set_reversed#

set_reversed sets whether the Rotation Sensor’s output is reversed.

When reversed, positive values become negative and negative values become positive. This method works the same as setting the reverse parameter to True when using the Rotation constructor.

Usage:
rotation_sensor.set_reversed(value)

Parámetros

Descripción

value

Whether to reverse the Rotation Sensor output: True or False.

cambió#

changed registers a function to be called whenever the Rotation Sensor’s value changes.

Usage:
rotation_sensor.changed(callback, arg)

Parámetros

Descripción

callback

Una función definida previamente que se ejecuta cuando cambia el valor del sensor de rotación.

arg

Opcional. Una tupla que contiene los argumentos que se pasarán a la función de devolución de llamada. Consulte Uso de funciones con parámetros para obtener más información.

def my_function():
  brain.screen.print("Rotated!")

# Call my_function whenever rotation_sensor's value changes
rotation_sensor.changed(my_function)

Constructor#

Constructors are used to manually create Rotation objects, such as when configuring a Rotation Sensor outside of VEXcode.

Rotation#

Rotation creates a Rotation Sensor object.

Usage:
Rotation(smartport)

Parámetro

Descripción

smartport

The Smart Port that the Rotation Sensor is connected to, written as Ports.PORTx, where x is the port number.

reverse

Optional. Whether to reverse the Rotation Sensor output: True or False (default).

# Create an inverted Rotation Sensor in Port 10
rotation_sensor = Rotation(Ports.PORT10, True)