Encoder#
Initializing the Encoder Class#
An Encoder Sensor is created by using the following constructor:
Encoder(port)
This constructor uses one parameter:
Parameter |
Description |
---|---|
|
The 3-Wire Port “pair” that the Encoder Sensor is connected to, whether it’s a port on the Brain, or a 3-Wire Expander. |
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.
Class Methods#
reset_position()#
The reset_position()
method resets the position of the Encoder to 0.
Returns: None.
set_position()#
The set_position(value, units)
method sets the position of the Encoder.
Parameters |
Description |
---|---|
value |
The position value to set. |
units |
Optional. A valid RotationUnits type. The default is |
Returns: None.
# 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.
Parameters |
Description |
---|---|
units |
Optional. A valid RotationUnits type. The default is |
Returns: The value of the current position of the Encoder in the specified units.
# Get the current Encoder position.
value = encoder.position()
velocity()#
The velocity(units)
method returns the current velocity of the Encoder.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnits type. The default is |
Returns: The value of the current velocity of the Encoder in the specified units.
# Get the current Encoder velocity in rpm.
value = encoder.velocity()