Sensor de rotación#
Introducción#
El sensor de rotación V5 mide el movimiento de rotación preciso, la posición y la velocidad en relación con su posición en el robot.

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 current position of the Rotation Sensor to a specific value.angle– Returns the current angle of the sensor between 0 and 359.99 degrees.position– Returns the total rotational position in degrees or turns.velocity– Returns how fast the sensor is rotating.reset_position– Sets the current position of the Rotation Sensor to 0.set_reversed– Inverts the Rotation Sensor output so positive values become negative, and negative values become positive. This method works the same as setting thereverseparameter toTruewhen using theRotationconstructor.changed– Registers a function to be called whenever whenever the Rotation Sensor’s value changes.
Constructor – Inicializa manualmente un sensor de rotación.
Rotation– Creates a Rotation Sensor.
establecer_posición#
set_position sets the current position of the Rotation Sensor to a value in degrees.
Usage:
rotation_sensor.set_position(position, units)
Parámetros |
Descripción |
|---|---|
posición |
La posición donde se debe colocar el sensor de rotación. |
unidades |
Optional. The unit of measurement:
|
# Set the Rotation Sensor to 2.5 Turns
rotation_sensor.set_position(2.5, TURNS)
ángulo#
angle returns the current angle of the sensor as a float.
Usage:
rotation_sensor.angle(units)
Parámetros |
Descripción |
|---|---|
unidades |
Optional. The unit of measurement:
|
posición#
position returns the total rotational position.
Usage:
rotation_sensor.position(units)
Parámetros |
Descripción |
|---|---|
unidades |
Optional. The unit of measurement:
|
velocidad#
velocity returns how fast the sensor is rotating.
Usage:
rotation_sensor.velocity(units)
Parámetros |
Descripción |
|---|---|
unidades |
The unit of measurement:
|
restablecer_posición#
reset_position sets the current position of the Rotation Sensor to 0.
Usage:
rotation_sensor.reset_position()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
conjunto_invertido#
set_reversed inverts the Rotation Sensor output so 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:
motor_1.set_reversed(value)
Parámetros |
Descripción |
|---|---|
|
Boolean value to set the direction reversed or not:
|
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 |
|---|---|
|
Una función previamente definida que se ejecuta cuando cambia el valor del sensor de rotación. |
|
Opcional. Una tupla que contiene los argumentos que se pasan 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, which are necessary for configuring a Rotation Sensor outside of VEXcode.
Rotation#
Rotation creates a Rotation Sensor.
Usage:
Rotation(smartport)
Parámetro |
Descripción |
|---|---|
|
The Smart Port that the Rotation Sensor is connected to, written as |
|
Optional. Sets whether the Rotation Sensor’s output should be inverted.
|
# Create an inverted Rotation Sensor in Port 10
rotation_sensor = Rotation(Ports.PORT10, True)