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 Brain, or a 3-Wire Expander. |
Primero se debe crear un Brain o un 3-Wire Expander antes de poder usarlos para crear un objeto con el constructor de la clase Encoder.
# 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 |
---|---|
valor |
El valor de posición a establecer. |
unidades |
Optional. A valid RotationUnits type. The default is |
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 |
---|---|
unidades |
Optional. A valid RotationUnits type. The default is |
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 |
---|---|
unidades |
Optional. A valid VelocityUnits type. The default is |
Devuelve: El valor de la velocidad actual del codificador en las unidades especificadas.
# Get the current Encoder velocity in rpm.
value = encoder.velocity()