旋转#

初始化旋转类#

使用以下构造函数创建旋转传感器:

The rotation constructor creates a rotation object in the specified Port with the reverse flag set to the specified value.

范围

描述

port

旋转传感器连接到的有效 智能端口

reverse

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 = rotation(PORT1, false);

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

类方法#

setReversed()#

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

参数

描述

价值

用于设置方向是否反转的布尔值。

**返回:**无。

// Set the rotation direction to reverse.
Rotation.setReversed(true);

angle()#

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

参数

描述

单位

有效的 rotationUnit

**返回:**以指定单位表示旋转传感器测量的角度的双精度数。

// Get the current angle of the Rotation Sensor
double angle = Rotation.angle(degrees);

// Print the current angle of the Rotation Sensor to the
// Brain's screen.
Brain.Screen.print(angle);

resetPosition()#

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

**返回:**无。

setPosition()#

The setPosition(value, units) method sets the position of the Rotation Sensor. The position returned by the position() method is set to this value.

参数

描述

价值

要设置的位置值。

单位

有效的 rotationUnit

**返回:**无。

position()#

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

参数

描述

单位

有效的 rotationUnit

**返回:**以指定单位表示旋转传感器当前位置的双精度值。

velocity()#

The velocity(units) method returns the velocity of the Rotation Sensor.

参数

描述

单位

有效的 velocityUnit

**返回:**以指定单位表示旋转传感器速度的双精度数。

changed()#

The changed(callback) method registers a callback function for when the value measured by the Rotation Sensor changes.

参数

描述

打回来

当旋转传感器测量的值发生变化时调用的回调函数。

**返回:**无。

// Define the rotationChanged function with a void
// return type, showing it doesn't return a value.
void rotationChanged() {
  // The Brain will print that the value of the Rotation Sensor
  // changed on the Brain's screen.
  Brain.Screen.print("Rotation Sensor value changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run rotationChanged when the value of the
  // Rotation Sensor changes.
  Rotation.changed(rotationChanged);
}

timestamp()#

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

**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。

installed()#

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

Returns: true if the Rotation Sensor is installed. false if it is not.