旋转#
初始化旋转类#
使用以下构造函数创建旋转传感器:
rotation
构造函数在指定的端口中创建一个旋转对象,并将反向标志设置为指定的值。
范围 |
描述 |
---|---|
|
旋转传感器连接到的有效 智能端口。 |
|
设置为“true”可反转旋转传感器返回的角度和位置。默认值为“false”。 |
// Construct a Rotation Sensor "Rotation" with the
// rotation class.
rotation Rotation = rotation(PORT1, false);
当引用旋转类方法时,此“Rotation”对象将在整个 API 文档的所有后续示例中使用。
类方法#
设置反转()#
setReversed(value)
方法将旋转方向设置为反向。
参数 |
描述 |
---|---|
价值 |
用于设置方向是否反转的布尔值。 |
**返回:**无。
// Set the rotation direction to reverse.
Rotation.setReversed(true);
角度()#
angle(units)
方法返回旋转传感器测量的角度。
参数 |
描述 |
---|---|
单位 |
有效的 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()
方法将旋转传感器的位置重置为 0。
**返回:**无。
设置位置()#
setPosition(value, units)
方法用于设置旋转传感器的位置。position()
方法返回的位置将设置为该值。
参数 |
描述 |
---|---|
价值 |
要设置的位置值。 |
单位 |
有效的 rotationUnit。 |
**返回:**无。
位置()#
position(units)
方法返回旋转传感器的当前位置。
参数 |
描述 |
---|---|
单位 |
有效的 rotationUnit。 |
**返回:**以指定单位表示旋转传感器当前位置的双精度值。
速度()#
velocity(units)
方法返回旋转传感器的速度。
参数 |
描述 |
---|---|
单位 |
有效的 velocityUnit。 |
**返回:**以指定单位表示旋转传感器速度的双精度数。
已更改()#
changed(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()
方法请求从旋转传感器接收的最后状态包的时间戳。
**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。
安装()#
如果旋转传感器已连接,则 installed()
方法返回。
**返回:**如果安装了旋转传感器,则返回“true”。如果没有安装,则返回“false”。