Motor y Grupo Motor#

Introducción#

Motors and motor groups control how parts of a robot move. A Motor controls one configured Smart Motor, while a MotorGroup controls multiple configured Smart Motors together so they move in tandem. Motors and motor groups can be used to raise an arm, turn a claw, spin a wheel, or move another part of a build. Two or four motors can work together as a drivetrain to move and turn the whole robot.

Each motor or motor group is configured in the Devices window. Depending on the build, motor and motor group names can change. This page uses motor_1 and motor_group_1 as example names. Replace them with your own configured names as needed.

Un motor VEX EXP que muestra la dirección de avance indicada por un signo más y una flecha que indica que está girando hacia la izquierda, o en sentido contrario a las agujas del reloj. Un motor VEX EXP que muestra la dirección inversa indicada por un signo menos y una flecha que indica que está girando hacia la derecha, o en el sentido de las agujas del reloj.

By default, FORWARD spins a motor counterclockwise, and REVERSE spins a motor clockwise. If a motor is set to reverse, those directions will be switched.

Existen muchas maneras de codificar motores y grupos de motores. A continuación se muestra una lista de todos los métodos para codificar motores y grupos de motores:

Acciones: Detener y hacer girar motores y grupos de motores.

  • spin — Spins a motor or motor group forward or reverse forever.

  • spin_for — Spins a motor or motor group for a specific distance.

  • spin_to_position — Spins a motor or motor group to a specific position.

  • stop — Stops a motor or motor group from spinning.

Motadores: ajustan la configuración del motor y del grupo de motores.

  • set_position — Changes the motor or motor group’s current position to a new value.

  • set_velocity — Tells a motor or motor group how fast to spin.

  • set_stopping — Sets how a motor or motor group will stop moving: by braking, coasting, or holding.

  • set_max_torque — Sets how hard a motor or motor group is allowed to push while spinning.

  • set_timeout — Sets how much time a motor or motor group will try to finish a movement.

  • set_reversed — Changes whether a motor’s spin direction is reversed.

  • reset_position — Changes a motor or motor group’s current position to 0.

Obtenedores: compruebe el estado del motor y del grupo de motores.

  • is_done — Returns whether the motor or motor group is finished moving, as a Boolean value.

  • is_spinning — Returns whether the motor or motor group is spinning, as a Boolean value.

  • position — Returns the motor or motor group’s current position.

  • velocity — Returns how fast the motor or motor group is spinning.

  • current — Returns how much electrical current the motor or motor group is using.

  • power — Returns how much power the motor or motor group is using.

  • torque — Returns how much torque the motor or motor group is using.

  • efficiency — Returns how efficiently the motor or motor group is using power.

  • temperature — Returns the temperature of the motor or motor group.

  • count — Returns the number of motors in a motor group.

  • get_timeout — Returns the motor or motor group’s current timeout duration.

Constructores: Inicialice y configure manualmente los motores y los grupos de motores.

Comportamiento#

spin#

spin spins a motor or motor group forward or reverse forever. The motor or motor group will continue to spin until it is given another action, like spinning in a different direction or stopping.

Usage:
motor_1.spin(direction, velocity, units)

Parámetros

Descripción

direction

The direction the motor or motor group spins: FORWARD or REVERSE.

velocity

Optional. The velocity to spin with from 0% to 100% when using PERCENT. This can be an integer or decimal (float).
If VOLT is used in units, this value can be from -12.0 to 12.0. A negative value spins opposite the given direction.

units

Optional. The velocity unit:

  • PERCENT
  • RPM (default) — Rotations per minute
  • VelocityUnits.DPS — Degrees per second
  • VOLT — Voltage

# Spin the motor, then stop
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()

spin_for#

spin_for spins a motor or motor group for a specific distance. The spin is relative to the current position of the motor or motor group. The project will wait until the motor or motor group is done spinning before the next line of code runs.

Usage:
motor_1.spin_for(direction, angle, units, velocity, units_v, wait)

Parámetros

Descripción

direction

The direction the motor or motor group spins: FORWARD or REVERSE.

angle

The distance the motor or motor group spins. This can be an integer or decimal (float).

units

Optional. The distance unit: DEGREES (default) or TURNS.

velocity

Optional. The velocity to spin with from 0% to 100% when using PERCENT. This can be an integer or decimal (float).

units_v

Optional. The velocity unit:

  • PERCENT
  • RPM (default) — Rotations per minute

wait

Optional.

  • wait=True (default) — Makes the project wait until the motor or motor group is done spinning before the next line of code runs.
  • wait=False — Makes the next line of code run right away.

# Spin the motor forward once, then reset
motor_1.spin_for(FORWARD, 90, DEGREES)
wait(1, SECONDS)
motor_1.spin_for(REVERSE, 90, DEGREES)

spin_to_position#

spin_to_position spins a motor or motor group to a specific position.

A motor or motor group’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. At the beginning of a project, the motor or motor group position is set to 0 degrees. The motor or motor group position can also be set using the set_position method.

Los valores de posición son absolutos. Esto significa que la dirección del giro depende de la posición actual del motor o grupo de motores.

Usage:
motor_1.spin_to_position(rotation, units, velocity, units_v, wait)

Parámetros

Descripción

rotation

The position value the motor or motor group will spin to. This can be an integer or decimal (float).

units

The position unit: DEGREES or TURNS.

velocity

Optional. The velocity to spin with from 0% to 100% when using PERCENT. This can be an integer or decimal (float).

units_v

Optional. The velocity unit:

  • PERCENT
  • RPM — Rotations per minute
  • VelocityUnits.DPS — Degrees per second

wait

Optional.

  • wait=True (default) — Makes the project wait until the motor or motor group is done spinning before the next line of code runs.
  • wait=False — Makes the next line of code run right away.

# Spin the motor to the new 0 position
motor_1.set_position(180, DEGREES)
motor_1.spin_to_position(0, DEGREES)

stop#

stop stops a motor or motor group from spinning.

Usage:
motor_1.stop(mode)

Parámetros

Descripción

mode

Optional. How the motor or motor group will stop:

  • BRAKE — Stops immediately.
  • COAST — Slows to a stop.
  • HOLD — Stops immediately and holds the motor’s position.

# Spin the motor, then stop
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()

Mutadores#

set_position#

A motor or motor group’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. set_position changes the motor or motor group’s current position to a new value.

Por ejemplo, si un motor o grupo de motores ha girado 180 grados, al ajustar la posición a 0 grados, dicha posición volverá a su estado original. A continuación, el motor o grupo de motores podrá girar a posiciones que se ajusten a ese nuevo valor.

Usage:
motor_1.set_position(position, units)

Parámetros

Descripción

position

The position value to set for the motor or motor group. This can be an integer or decimal (float).

units

Optional. The position unit: DEGREES (default) or TURNS.

# Spin the motor to the new 0 position
motor_1.set_position(180, DEGREES)
motor_1.spin_to_position(0, DEGREES)

set_velocity#

set_velocity tells a motor or motor group how fast to spin. A higher percentage makes the motor or motor group spin faster and a lower percentage makes the motor or motor group spin slower.

Cada proyecto comienza con cada motor o grupo de motores girando al 50% de su velocidad por defecto.

Nota: Una mayor velocidad hace que el motor o grupo de motores gire más rápido, pero puede ser menos preciso. Una menor velocidad hace que el motor o grupo de motores gire más lento, pero puede ser más preciso.

Usage:
motor_1.set_velocity(velocity, units)

Parámetros

Descripción

velocity

The speed the motor or motor group will spin at. PERCENT uses values from 0% to 100%. RPM uses values from 0 to 127. This can be an integer or decimal (float).

units

Optional. The velocity unit:

  • PERCENT
  • RPM (default) — Rotations per minute
  • VelocityUnits.DPS — Degrees per second

# Spin forward at the default velocity
motor_1.spin_for(FORWARD, 100)
wait(1, SECONDS)

# Spin slower
motor_1.set_velocity(20, PERCENT)
motor_1.spin_for(FORWARD, 100)
wait(1, SECONDS)

# Spin faster
motor_1.set_velocity(100, PERCENT)
motor_1.spin_for(FORWARD, 100)
wait(1, SECONDS)

set_stopping#

set_stopping sets how a motor or motor group will stop moving: by braking, coasting, or holding.

Usage:
motor_1.set_stopping(mode)

Parámetros

Descripción

mode

How the motor or motor group will stop:

  • BRAKE — Stops immediately.
  • COAST — Slows to a stop.
  • HOLD — Stops immediately and holds the motor’s position.

set_max_torque#

El par motor indica la fuerza con la que un motor o un grupo de motores puede empujar o tirar mientras gira.

set_max_torque sets the most torque a motor or motor group is allowed to use.

Un porcentaje mayor permite que el motor o grupo de motores empuje con más fuerza, como al levantar un objeto pesado. Un porcentaje menor limita la fuerza que puede ejercer el motor o grupo de motores. Esto puede ayudar a proteger al robot si el motor o grupo de motores se atasca o alcanza el límite de su recorrido.

Cada proyecto comienza con el par motor de cada motor o grupo de motores al 50% por defecto.

Usage:
motor_1.set_max_torque(value, units)

Parámetros

Descripción

value

The max torque the motor or motor group can use. PERCENT uses integers from 0% to 100%. For TorqueUnits.NM, use a float from 0.0 to 2.1 (Newton-meters). For TorqueUnits.INLB, use a float from 0.0 to 22.0 (inch-pounds).

units

Optional. The torque unit:

  • PERCENT
  • TorqueUnits.NM (default) — Newton meters
  • TorqueUnits.INLB — Inch pounds
  • CurrentUnits.AMP

set_timeout#

set_timeout sets how much time a motor or motor group will try to finish a movement. If the motor or motor group cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the motor or motor group from getting stuck on a movement.

Usage:
motor_1.set_timeout(value, units)

Parámetros

Descripción

value

The amount of time the motor or motor group can try to finish a movement. This can be a positive integer or decimal (float).

units

Optional. The unit of time:

  • SECONDS
  • MSEC (default) — Milliseconds

set_reversed#

set_reversed changes whether a motor’s spin direction is reversed. This method works the same as setting the reverse parameter to True when constructing a Motor.

Nota: Este método solo funcionará con un motor y no con un grupo de motores.

Usage:
motor_1.set_reversed(value)

Parámetros

Descripción

value

Whether the motor’s direction is reversed:

  • True — Reverses the motor’s direction.
  • False — Returns the motor’s direction to its default.

reset_position#

reset_position changes the motor or motor group’s current position to 0.

Usage:
motor_1.reset_position()

Parámetros

Descripción

Este método no tiene parámetros.

Getters#

is_done#

is_done returns whether the motor or motor group is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor or motor group is finished moving.

  • False — The motor or motor group is still moving.

This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.

Usage:
motor_1.is_done()

Parámetros

Descripción

Este método no tiene parámetros.

# Drive forward until the motor is done spinning
motor_1.spin_for(FORWARD, 200, wait=False)
while True:
  if motor_1.is_done():
    drivetrain.stop()
  else:
    drivetrain.drive(FORWARD)

is_spinning#

is_spinning returns whether the motor or motor group is spinning, as a Boolean value. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor or motor group is spinning.

  • False — The motor or motor group is not spinning.

This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.

Usage:
motor_1.is_spinning()

Parámetros

Descripción

Este método no tiene parámetros.

# Drive forward until the motor is done spinning
motor_1.spin_for(FORWARD, 200, wait=False)
while True:
  if motor_1.is_spinning():
    drivetrain.drive(FORWARD)
  else:
    drivetrain.stop()

position#

A motor or motor group’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. position returns the motor or motor group’s current position.

Al inicio del proyecto, la posición del motor o grupo de motores se establece en 0 grados. Si el motor o grupo de motores gira una vuelta hacia adelante, la posición será de 360 ​​grados o 1 vuelta. Si el motor o grupo de motores gira en sentido contrario, la posición será negativa.

Usage:
motor_1.position(units)

Parámetros

Descripción

units

Optional. The unit to return the motor or motor group position in: DEGREES (default) or TURNS.

# Display the motor's position after spinning
brain.screen.print(motor_1.position())
brain.screen.next_row()

motor_1.spin(FORWARD)
wait(1, SECONDS)
brain.screen.print(motor_1.position())

motor_1.stop()

velocity#

velocity returns how fast the motor or motor group is spinning, as a percentage from -100% to 100% or as rotations per minute from -127 rpm to 127 rpm.

Un valor positivo indica que el motor o el grupo de motores gira hacia adelante. Un valor negativo indica que gira en sentido inverso.

Usage:
motor_1.velocity(units)

Parámetros

Descripción

units

Optional. The velocity unit to return:

  • PERCENT
  • RPM (default) — Revolutions per minute
  • VelocityUnits.DPS — Degrees per second

current#

current returns how much electrical current the motor or motor group is using, measured in amps from 0.0 to 1.2 A. Current is the amount of electricity flowing through the motor or motor group.

Un valor de corriente más alto significa que el motor o grupo de motores está consumiendo más corriente eléctrica. Esto puede ocurrir cuando el motor o grupo de motores levanta algo pesado, empuja contra un objeto o intenta moverse cuando está atascado.

Esto permite comprobar si el motor o el grupo de motores presenta dificultades durante el movimiento. Si la corriente se mantiene alta, el motor podría calentarse o consumir energía de forma menos eficiente.

Usage:
motor_1.current(units)

Parámetros

Descripción

units

Optional. The current unit to return:

  • CurrentUnits.AMP (default) — Amps

power#

power returns how much power the motor or motor group is using, measured in watts from 0.0 to 11.0 W. Power shows how quickly the motor or motor group is using energy.

Un valor de potencia más alto significa que el motor o grupo de motores consume energía más rápidamente. Esto puede ocurrir cuando el motor o grupo de motores levanta algo pesado, empuja contra un objeto o intenta moverse cuando está atascado.

Esto puede utilizarse para comparar movimientos o comprobar si el motor o el grupo de motores presenta dificultades. Si la potencia se mantiene alta, el motor podría calentarse o consumir energía de forma menos eficiente.

Usage:
motor_1.power(units)

Parámetros

Descripción

units

Optional. The power unit to return:

  • PowerUnits.WATT (default) — Watt

torque#

El par motor indica la fuerza con la que un motor o un grupo de motores gira, empuja o tira mientras gira.

torque returns how much torque the motor or motor group is using, measured in inch-pounds (InLb) from 0.0 to 22.0 or Newton-meters (Nm) from 0.0 to 2.1.

Un valor de par motor más elevado indica que el motor o el grupo de motores ejerce mayor fuerza de empuje o tracción. Esto puede ocurrir cuando el motor o el grupo de motores levanta un objeto pesado, empuja contra él o intenta moverse cuando está atascado.

Esto puede utilizarse para comprobar si el motor o el grupo de motores tiene dificultades o para comparar la cantidad de impulso que necesitan los diferentes movimientos.

To set the torque of a motor or motor group, use set_max_torque.

Usage:
motor_1.torque(units)

Parámetros

Descripción

units

The torque unit to return:

  • TorqueUnits.NM (default) — Newton meters
  • TorqueUnits.INLB — Inch pounds

efficiency#

efficiency returns how efficiently the motor or motor group is using power, as a percentage from 0% to 100%.

La eficiencia indica cuánta potencia del motor o grupo de motores se utiliza para el movimiento. Un valor de eficiencia más alto significa que se utiliza más potencia del motor o grupo de motores para moverse. Un valor de eficiencia más bajo puede ocurrir cuando el motor o grupo de motores trabaja intensamente pero no se mueve mucho, como cuando está atascado o empujando contra un objeto.

Esto puede utilizarse para comparar movimientos o comprobar si el motor o el grupo de motores está desperdiciando energía en lugar de utilizarla para el movimiento.

Usage:
motor_1.efficiency(units)

Parámetros

Descripción

units

Optional. The efficiency unit to return:

  • PERCENT (default)

temperature#

temperature returns the temperature of the motor or motor group.

La temperatura del motor indica qué tan caliente está el motor o el grupo de motores. Una temperatura más alta significa que el motor o el grupo de motores se está calentando durante su funcionamiento. El motor debe mantenerse por debajo de los 55 °C para seguir funcionando a pleno rendimiento.

Si el motor o el grupo motor se sobrecalienta, reducirá su corriente máxima para protegerse. A 70 °C, el motor dejará de funcionar hasta que se enfríe.

Esto puede utilizarse para comprobar si el motor o el grupo de motores se calienta demasiado durante movimientos repetitivos, funcionamientos prolongados o cuando ejerce presión contra un objeto.

Usage:
motor_1.temperature(units)

Parámetros

Descripción

units

Optional. The temperature unit to return:

  • TemperatureUnits.CELSIUS (default)
  • TemperatureUnits.FAHRENHEIT
  • PERCENT

count#

count returns the number of motors in a motor group.

Nota: Este método solo funcionará con un grupo motor.

Usage:
motor_group_1.count()

Parámetros

Descripción

Este método no tiene parámetros.

get_timeout#

get_timeout returns the motor or motor group’s current timeout in milliseconds.

Usage:
motor_1.get_timeout()

Parámetros

Descripción

Este método no tiene parámetros.

Constructores#

Constructors are used to manually create Motor and MotorGroup objects outside of the Devices window.

Motor#

Motor creates a motor.

Usage:
Motor(port, gears, reverse)

Parámetro

Descripción

port

The Smart Port that the motor is connected to, written as Ports.PORTx, where x is the port number.

gears

Optional. The motor’s gear ratio:

  • GearSetting.RATIO_18_1 (default) — 18:1 ratio
  • GearSetting.RATIO_36_1 — 36:1 ratio
  • GearSetting.RATIO_6_1 — 6:1 ratio

reverse

Optional. Sets whether the motor’s spin direction is reversed:

  • True — Makes FORWARD spin clockwise.
  • False (default) — Makes FORWARD spin counterclockwise.

# Create a Motor in Port 1 with default values
motor_1 = Motor(Ports.PORT1)

"""
Create a motor with the following values:
- In Port 1
- 36:1 ratio
- Reversed
"""
motor_1 = Motor(Ports.PORT1, GearSetting.RATIO_36_1, True)

MotorGroup#

MotorGroup creates a motor group.

Usage:
MotorGroup(motors)

Parámetro

Descripción

motors

The names of previously created Motor objects to put in the motor group, separated by commas (,). Up to 12 Motor objects can be added to the group.

# Create the Motors
motor_1 = Motor(Ports.PORT1)
motor_2 = Motor(Ports.PORT2)

# Create a Motor Group
motor_group_1 = MotorGroup(motor_1, motor_2)