旋转#

要使旋转命令在 VEXcode V5 中显示,必须在“设备”窗口中配置旋转传感器。

更多信息,请参阅以下文章:

初始化旋转类#

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

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

范围

描述

port

A valid Smart Port that the Rotation Sensor is connected to.

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.

参数

描述

value

一个布尔值,用于设置是否反转方向。

**返回值:**无。

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

angle()#

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

参数

描述

units

A valid 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.

参数

描述

value

要设置的位置值。

units

A valid rotationUnit.

**返回值:**无。

position()#

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

参数

描述

units

A valid rotationUnit.

返回值: 一个双精度浮点数,表示旋转传感器的当前位置,单位为指定单位。

velocity()#

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

参数

描述

units

A valid velocityUnit.

返回值: 一个双精度浮点数,表示旋转传感器的速度,单位为指定单位。

changed()#

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

参数

描述

callback

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

**返回值:**无。

// 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.