伺服电机#

介绍#

VEX 三线伺服电机 是一款三线设备,可以根据 V5 控制器的控制信号旋转到特定位置。

VEX 三线伺服电机。

本页面使用 servo_motor 作为示例伺服电机名称。请根据需要将其替换为您自己配置的名称。

以下是可用方法列表:

  • set_position – 将伺服电机移动到 0 到 100 度之间的指定位置。

构造函数 - 手动初始化伺服电机。

  • Servo – 创建一个伺服电机。

设置位置#

set_position 将伺服电机移动到 0 到 100 度之间的指定位置。

注意:伺服电机在开始每个项目之前,都会自动将自身居中于 50 度,然后再进行任何运动。

伺服电机示意图,显示其旋转角度,从左侧的 100 度到中间的 50 度,再到右侧的 0 度。

Usage:
servo_motor.set_position(value, units)

参数

描述

value

The position value to set for the Servo Motor. This can be an integer or decimal (float) from 0 to 100.

units

位置单位: DEGREES 或 PERCENT (默认值)。

构造函数#

构造函数用于手动创建 Servo 对象,这是在 VEXcode 之外配置伺服电机所必需的。

Servo#

Servo 创建一个伺服电机。

Usage:
Servo(port)

范围

描述

port

The 3-Wire Port that the Servo Motor is connected to:

  • On the V5 Brain – Ports.PORTx where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create a Servo Motor in Port A
servo_motor = Servo(brain.three_wire_port.a)