旋转传感器#

介绍#

V5 旋转传感器 可测量相对于其在机器人上的位置的精确旋转运动、位置和速度。

VEX V5 旋转传感器。

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

以下是可用方法列表:

  • 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 the reverse parameter to True when using the Rotation constructor.

  • changed – Registers a function to be called whenever whenever the Rotation Sensor’s value changes.

构造函数 - 手动初始化旋转传感器。

  • Rotation – Creates a Rotation Sensor.

设置位置#

set_position sets the current position of the Rotation Sensor to a value in degrees.

Usage:
rotation_sensor.set_position(position, units)

参数

描述

位置

旋转传感器的设置位置。

单位

Optional. The unit of measurement:

  • DEGREES (default)
  • TURNS

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

角度#

angle returns the current angle of the sensor as a float.

Usage:
rotation_sensor.angle(units)

参数

描述

单位

Optional. The unit of measurement:

  • DEGREES (default) – 0 to 359.99
  • TURNS

位置#

position returns the total rotational position.

Usage:
rotation_sensor.position(units)

参数

描述

单位

Optional. The unit of measurement:

  • DEGREES (default) – 0 to 359 as an integer
  • TURNS – As a float

速度#

velocity returns how fast the sensor is rotating.

Usage:
rotation_sensor.velocity(units)

参数

描述

单位

The unit of measurement:

  • VelocityUnits.RPM (default) – Rotations per minute
  • VelocityUnits.DPS – Degrees per second

重置位置#

reset_position sets the current position of the Rotation Sensor to 0.

Usage:
rotation_sensor.reset_position()

参数

描述

此方法没有参数。

设置反转#

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)

参数

描述

value

Boolean value to set the direction reversed or not:

  • True – Reverse the motor’s direction
  • False – Return the motor’s direction to its default

已更改#

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

Usage:
rotation_sensor.changed(callback, arg)

参数

描述

callback

先前定义的 函数,当旋转传感器的值发生变化时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数

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

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

构造函数#

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)

范围

描述

smartport

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

reverse

Optional. Sets whether the Rotation Sensor’s output should be inverted.

  • True
  • False (default)

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