编码器#
初始化编码器类#
使用以下构造函数创建编码器传感器:
Encoder(port)
此构造函数使用一个参数:
范围 |
描述 |
|---|---|
|
The 3-Wire Port “pair” that the Encoder Sensor is connected to, 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 Encoder Class constructor.
# Create the Brain.
brain = Brain()
# Construct an Encoder Sensor "encoder" with the
# Encoder class.
encoder = Encoder(brain.three_wire_port.a)
This encoder object will be used in all subsequent examples throughout this API documentation when referring to Encoder class methods.
类方法#
reset_position()#
The reset_position() method resets the position of the Encoder to 0.
**返回:**无。
set_position()#
The set_position(value, units) method sets the position of the Encoder.
参数 |
描述 |
|---|---|
|
要设置的位置值。 |
|
Optional. A valid |
**返回:**无。
# Set the value of Encoder's position to 180 degrees.
encoder.set_position(180)
position()#
The position(units) method returns the current position of the Encoder.
参数 |
描述 |
|---|---|
|
Optional. A valid |
**返回:**编码器当前位置的指定单位值。
# Get the current Encoder position.
value = encoder.position()
velocity()#
The velocity(units) method returns the current velocity of the Encoder.
参数 |
描述 |
|---|---|
|
Optional. A valid |
返回: 以指定单位表示的编码器当前速度值。
# Get the current Encoder velocity in rpm.
value = encoder.velocity()