伺服#

初始化伺服类#

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

Servo(port)

此构造函数使用一个参数:

范围

描述

port

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

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

# Create the Brain.
brain = Brain()
# Construct a Servo Output "servo" with the Servo class.
servo = Servo(brain.three_wire_port.a)

当引用 Servo 类方法时,此 API 文档中的所有后续示例中都将使用此 Servo 对象。

类方法#

set_position()#

set_position(value, units) 方法设置伺服器的位置。

参数

描述

价值

伺服的新值。

单位

**可选。**有效的 RotationUnits 类型。默认值为 PERCENT

**返回:**无。

# Set the Servo Output to 10 degrees.
servo.set_position(10, DEGREES)