Codificador#
Inicializando la clase codificador#
Un sensor codificador se crea utilizando el siguiente constructor:
Encoder(port)
Este constructor utiliza un parámetro:
Parámetro |
Descripción |
|---|---|
|
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.
Métodos de clase#
reset_position()#
The reset_position() method resets the position of the Encoder to 0.
Devoluciones: Ninguna.
set_position()#
The set_position(value, units) method sets the position of the Encoder.
Parámetros |
Descripción |
|---|---|
|
El valor de posición a establecer. |
|
Optional. A valid |
Devoluciones: Ninguna.
# 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.
Parámetros |
Descripción |
|---|---|
|
Optional. A valid |
Devuelve: El valor de la posición actual del codificador en las unidades especificadas.
# Get the current Encoder position.
value = encoder.position()
velocity()#
The velocity(units) method returns the current velocity of the Encoder.
Parámetros |
Descripción |
|---|---|
|
Optional. A valid |
Devuelve: El valor de la velocidad actual del codificador en las unidades especificadas.
# Get the current Encoder velocity in rpm.
value = encoder.velocity()