Motor#
Inicializando la clase Motor#
Un objeto EXP Motor se crea utilizando el siguiente constructor:
Motor(port, gears, reverse)
Este constructor toma tres parámetros como máximo.
Parámetro |
Descripción |
---|---|
|
El puerto al que está conectado el motor en el cerebro EXP. |
|
Optional. Sets the gear setting installed in the Motor, the default is |
|
Optional. Sets whether the Motor’s spin should be reversed, the default is |
# Construct a Motor object named motor_1 in Port 1 on
# the EXP Brain which has the reverse flag set to True.
motor_1 = Motor(Ports.PORT1, True)
This motor_1
object will be used in all subsequent examples throughout this API documentation when referring to Motor class methods.
Métodos de clase#
spin()#
The spin(direction, velocity, units)
method is used to spin a Motor in the specified direction until a spin or stop command is used, or the project is stopped.
Esta es una función sin espera y permite que el siguiente comando se ejecute sin demora.
Parámetros |
Descripción |
---|---|
dirección |
Un DirectionType válido. |
velocidad |
Optional. The velocity at which the Motor will spin. The default velocity set by the |
unidades |
Optional. A valid VelocityUnit or |
Devoluciones: Ninguna.
# Spin motor_1 forward.
motor_1.spin(FORWARD)
spin_to_position()#
The spin_to_position(rotation, units, velocity, units_v, wait)
method is used to spin a Motor to an absolute position using the provided arguments.
This function can be a waiting or non-waiting command depending on if the wait
parameter is set to True
.
Parámetros |
Descripción |
---|---|
rotación |
La posición a la que debe girar el motor. |
unidades |
Optional. A valid RotationUnit. The default is |
velocidad |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
unidades_v |
Optional. A valid VelocityUnit or |
esperar |
Optional. Determines whether the command will block subsequent commands ( |
Devoluciones: Ninguna.
# Spin motor_1 to the position 90 degrees at 100 RPM.
motor_1.spin_to_position(90, DEGREES, 100, RPM)
spin_for()#
The spin_for(direction, value, units, velocity, units_v, wait)
method is used to spin the Motor for a specific duration, rotations, or until a specific encoder value is reached. The position is relative to the current position of the Motor.
This can be a waiting or non-waiting command depending on if the wait
parameter is used.
Parámetros |
Descripción |
---|---|
dirección |
Un DirectionType válido. |
valor |
El valor al que debe girar el motor. |
unidades |
Optional. A valid RotationUnit. The default is |
velocidad |
Optional. The velocity with which the Motor will spin. The default velocity set by the |
unidades_v |
Optional. A valid VelocityUnit or |
esperar |
Optional. Determines whether the command will block subsequent commands ( |
Devoluciones: Ninguna.
# Spin motor_1 forward for 10 turns at 100 percent velocity.
motor_1.spin_for(FORWARD, 10, TURNS, 100, PERCENT)
stop()#
The stop(mode)
method is used to stop a Motor, setting them to 0 velocity and configuring the current stopping mode.
Parámetros |
Descripción |
---|---|
modo |
Optional. A valid BrakeType. The default is |
Devoluciones: Ninguna.
# Spin motor_1 forward for 2.5 seconds.
motor_1.spin(FORWARD)
wait(2.5, SECONDS)
# Stop motor_1 using the HOLD brake type.
motor_1.stop(HOLD)
set_velocity()#
The set_velocity(velocity, units)
method is used to set the default velocity for a Motor. This velocity setting will be used for subsequent calls to any motion functions if a specific velocity is not provided.
Parámetros |
Descripción |
---|---|
velocidad |
La nueva velocidad a establecer para el motor. |
unidades |
A valid VelocityUnit or |
Devoluciones: Ninguna.
# Spin motor_1 forward at 75 percent velocity
motor_1.set_velocity(75, PERCENT)
motor_1.spin(FORWARD)
set_reversed()#
The set_reversed(value)
method sets the Motor direction to be reversed. This command works the same as setting the reverse
parameter to True
when constructing a Motor.
Parámetros |
Descripción |
---|---|
valor |
Valor booleano para establecer la dirección invertida o no. |
Devoluciones: Ninguna.
set_stopping()#
The set_stopping(mode)
method is used to set the stopping mode for a Motor.
Parámetros |
Descripción |
---|---|
modo |
Un BrakeType válido. |
Devoluciones: Ninguna.
reset_position()#
The reset_position()
method resets the Motor position to 0. The position that is returned by the motor_1.position()
function will be updated to 0.
Devoluciones: Ninguna.
set_position()#
The set_position(value, units)
method is used to set the position of a Motor. The position that is returned by the motor_1.position()
function will be updated to this new value.
Parámetros |
Descripción |
---|---|
valor |
La nueva posición a fijar para el motor. |
unidades |
Una RotationUnit válida. |
Devoluciones: Ninguna.
set_timeout()#
The set_timeout(value, units)
method is used to set the timeout for a Motor. The position that is returned by the motor_1.get_timeout()
function will be updated to this new value.
Parámetros |
Descripción |
---|---|
valor |
El nuevo tiempo de espera que se debe establecer para el motor. |
unidades |
Optional. A valid TimeUnit. The default is |
Devoluciones: Ninguna.
get_timeout()#
The get_timeout()
method returns the current timeout for a Motor.
Devuelve: El valor de tiempo de espera actual en milisegundos.
is_spinning()#
The is_spinning()
method returns the current status of the motor_1.spin_to_position()
or motor_1.spin_for()
commands. This function is used when False
has been passed as the wait parameter in either command.
Returns: True
if the Motor is still spinning. False
if the Motor has completed the move or a timeout has occurred.
is_done()#
The is_done()
method returns the current status of the motor_1.spin_to_position()
or motor_1.spin_for()
commands. This function is used when False
has been passed as the wait parameter in either command.
Returns: True
if the Motor is still spinning. False
if the Motor has completed the move or a timeout has occurred.
set_max_torque()#
The set_max_torque(value, units)
method is used to set the maximum torque for a Motor. The torque can be set as torque, current, or a percent of maximum torque.
Parámetros |
Descripción |
---|---|
valor |
El nuevo par máximo para un motor. |
unidades |
A valid TorqueUnit, |
Devoluciones: Ninguna.
direction()#
The direction()
method returns the current direction the Motor is spinning in.
Devuelve: El DirectionType actual en el que está girando el motor.
position()#
The position(units)
method returns the current position of the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid RotationUnit. The default is |
Devuelve: La posición actual del motor en las unidades especificadas.
velocity()#
The velocity(units)
method returns the current velocity of the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid VelocityUnit. The default is |
Devuelve: La velocidad actual del motor en las unidades especificadas.
current()#
The current(units)
method returns the current being used by the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. The only valid units for current are |
Devuelve: La corriente que consume el motor en las unidades especificadas.
power()#
The power(units)
method returns the power being consumed by the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. The only valid units for power are |
Devuelve: La potencia consumida por el motor en las unidades especificadas.
torque()#
The torque(units)
method returns the torque being generated by the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid TorqueUnit. The default is |
Devuelve: El torque generado por el motor en las unidades especificadas.
efficiency()#
The efficiency(units)
method returns the efficiency of the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. The only valid unit for efficiency is |
Devuelve: La eficiencia del motor como porcentaje.
temperature()#
The temperature(units)
method returns the temperature of the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid TemperatureUnit. The default is |
Devuelve: La temperatura del motor en las unidades especificadas.
command()#
The command(units)
method returns the last velocity sent to the Motor.
Parámetros |
Descripción |
---|---|
unidades |
Optional. A valid VelocityUnit. The default is |
Devuelve: La velocidad del comando del motor en las unidades especificadas.
installed()#
The installed()
method returns if the Motor is connected to the EXP Brain.
Returns: True
if the Motor is connected. False
if it is not.
timestamp()#
The timestamp()
method returns the timestamp of the last received status packet from the Motor.
Devuelve: La marca de tiempo del último paquete de estado recibido en milisegundos.