伺服#
初始化伺服类#
使用以下构造函数创建伺服输出:
The servo constructor creates a servo object in the specified Three Wire Port.
范围 |
描述 |
|---|---|
|
The 3-Wire Port to use for the Servo Output, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the servo Class constructor.
// Create the Brain.
brain Brain;
// Construct a Servo Output "Servo" with the servo class.
servo Servo = servo(Brain.ThreeWirePort.A);
This Servo object will be used in all subsequent examples throughout this API documentation when referring to servo class methods.
类方法#
setPosition()#
该方法通过以下方式调用:
The setPosition(value, units) method sets the position of the Servo using a percentage.
参数 |
描述 |
|---|---|
|
伺服器的整数值。 |
|
The only valid unit for the units in this usecase is |
**返回:**无。
// Set the servo position to 10 percent.
Servo.setPosition(10, percent);
The setPosition(value, units) method sets the position of the Servo using a Rotation Unit.
参数 |
描述 |
|---|---|
|
伺服器的双倍值。 |
|
A valid |
**返回:**无。
// Set the servo position to 45.5 degrees.
Servo.setPosition(45.5, degrees);