旋转#
初始化旋转类#
使用以下构造函数创建旋转传感器:
Rotation(port, reverse)
此构造函数使用一个参数:
范围 |
描述 |
---|---|
|
旋转传感器连接到的有效 智能端口。 |
|
Optional. Set to |
# 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.
类方法#
set_reversed()#
The set_reversed(value)
method sets the rotation direction to be reversed.
这是一种非等待方法,允许下一个方法无延迟运行。
参数 |
描述 |
---|---|
价值 |
|
**返回:**无。
# Set the direction to be reversed.
rotation.set_reversed(True)
angle()#
The angle(units)
method returns the angle measured by the Rotation Sensor.
参数 |
描述 |
---|---|
单位 |
Optional. A valid RotationUnits type. The default is |
**返回:**旋转传感器以指定单位测量的角度。
# Print the current angle of the Rotation Sensor to the
# Brain's screen.
brain.screen.print(rotation.angle())
重置位置()#
The reset_position()
method resets the position of the Rotation Sensor to 0.
**返回:**无。
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.
参数 |
描述 |
---|---|
价值 |
要设置的位置值。 |
单位 |
Optional. A valid RotationUnits type. The default is |
**返回:**无。
position()#
The position(units)
method returns the current position of the Rotation Sensor.
参数 |
描述 |
---|---|
单位 |
Optional. A valid RotationUnits type. The default is |
**返回:**旋转传感器的当前位置(以指定的单位表示)。
velocity()#
The velocity(units)
method returns the velocity of the Rotation Sensor.
参数 |
描述 |
---|---|
单位 |
Optional. A valid VelocityUnits type. The default is |
**返回:**以指定单位表示的旋转传感器的速度。
changed()#
The changed(callback, arg)
method registers a callback function for when the value measured by the Rotation Sensor changes.
参数 |
描述 |
---|---|
打回来 |
当旋转传感器测量的值发生变化时调用的回调函数。 |
arg |
**可选。**传递给回调函数的参数元组。 |
**返回:**无
# 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.
**返回:**最后接收的状态包的时间戳(以毫秒为单位)。