伺服#

初始化伺服类#

使用以下构造函数创建伺服输出:

servo 构造函数在指定的三线端口中创建一个伺服对象。

范围

描述

端口

用于伺服输出的 3 线端口,无论它是 大脑 上的端口,还是 3 线扩展器 上的端口。

必须先创建 Brain3-Wire Expander,然后才能使用伺服类构造函数创建对象。

// Create the Brain.
brain Brain;
// Construct a Servo Output "Servo" with the servo class.
servo Servo = servo(Brain.ThreeWirePort.A);

当引用伺服类方法时,此“Servo”对象将在整个 API 文档的所有后续示例中使用。

类方法#

设置位置()#

该方法通过以下方式调用:

setPosition(value, units) 方法使用百分比设置伺服器的位置。

参数

描述

价值

伺服器的整数值。

单位

此用例中唯一有效的单位是“百分比”。

**返回:**无。

// Set the servo position to 10 percent.
Servo.setPosition(10, percent);

setPosition(value, units) 方法使用旋转单位设置伺服器的位置。

参数

描述

价值

伺服器的双倍值。

单位

有效的 rotationUnit

**返回:**无。

// Set the servo position to 45.5 degrees.
Servo.setPosition(45.5, degrees);