Grupo Motor y Motor#

Introducción#

Los métodos de Motor y Grupo de Motores permiten controlar y supervisar motores individuales o grupos de motores en el robot V5. Estos métodos permiten girar, detener o mover los motores a posiciones específicas, además de informar sobre su velocidad, par, potencia y temperatura.

This page uses motor_1 and motor_group_1 as the example motor and motor group name respectively. Replace them with your own configured names as needed.

A continuación se muestra una lista de los métodos disponibles:

Acciones – Controlar el movimiento de los motores.

  • spin – Rotates the selected motor or motor group indefinitely.

  • spin_for – Rotates a motor or motor group for a specific distance in degrees or turns.

  • spin_to_position – Rotates a motor or motor group to a set position.

  • stop – Stops a specific motor or motor group from spinning.

Mutadores – Cambian los atributos de los motores.

  • set_position – Sets the position (encoder value) of a motor or motor group.

  • set_velocity – Sets the speed of a motor or motor group as a percentage.

  • set_stopping – Sets the stop behavior (brake, coast, or hold) or the motor or motor group.

  • set_max_torque – Limits the maximum torque the motor or motor group can apply.

  • set_timeout – Limits how long a motor or motor group function waits before giving up if movement is blocked.

  • set_reversed – Sets only a motor to have its direction be reversed.

  • reset_position – Sets only a motor’s position to 0.

Obtenedores: devuelven datos de los motores.

  • is_done – Returns a Boolean indicating whether the motor or motor group is no longer spinning.

  • is_spinning – Returns a Boolean indicating whether the motor or motor group is currently spinning.

  • position – Returns the motor’s or motor group’s current rotational position in degrees or turns.

  • velocity – Returns the motor’s or motor group’s current velocity in % or rpm.

  • current – Returns the current drawn by the motor or motor group.

  • power – Returns the amount of electrical power the motor or motor group is consuming.

  • torque – Returns the amount of torque currently being applied by the motor or motor group.

  • efficiency – Returns the current efficiency of the motor or motor group.

  • temperature – Returns the current temperature of the motor or motor group.

  • count – Returns the amount of motors in a motor group.

  • get_timeout – Returns only a motor’s current timeout duration.

Constructor – Inicializa manualmente un motor o un grupo de motores.

Comportamiento#

spin#

spin rotates a selected motor or motor group in a specified direction using the current motor velocity.

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

Parámetros

Descripción

direction

The direction in which to spin the motor or motor group:

  • FORWARD – By default, this is counterclockwise
  • REVERSE – By default, this is clockwise

velocity

Optional. The velocity at which the motor or motor group will spin as a float or integer. If the velocity is not specified or previously set, the default velocity is 50%.

If VOLT is used in units, this will accept a range from -12.0 to 12.0 where a negative value will spin opposite to the given direction.

units

Optional. The unit that represents the velocity:

  • PERCENT
  • RPM (default) – Rotations per minute
  • VelocityUnits.DPS – Degrees per second
  • VOLT – Will spin the motor or motor group at a specified voltage.

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

spin_for#

spin_for rotates a motor or motor group for a specific amount of rotation using the current motor velocity, measured in degrees or turns.

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

Parámetros

Descripción

direction

The direction in which to spin the motor or motor group:

  • FORWARD
  • REVERSE

angle

La cantidad de grados que girará el motor o el grupo de motores como un valor flotante o entero.

units

Optional. The unit that represents the rotational value:

  • DEGREES (default)
  • TURNS

velocity

Opcional. La velocidad a la que girará el motor o el grupo de motores, como valor de punto flotante o entero. Si la velocidad no se especifica o previamente establecida, la velocidad predeterminada es del 50%.

units_v

Optional. The unit that represents the velocity:

  • PERCENT
  • RPM (default) – Rotations per minute

wait

Optional.

  • wait=True (default) – The project waits until spin_for is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for spin_for to finish.

# 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 rotates a motor or motor group to a specific absolute position using the current motor velocity and motor position.

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

Parámetros

Descripción

rotation

La posición para girar el motor o el grupo de motores como un flotante o un entero.

units

The unit that represents the rotational value:

  • DEGREES
  • TURNS

velocity

Opcional. La velocidad a la que girará el motor o el grupo de motores, como valor de punto flotante o entero. Si la velocidad no se especifica o previamente establecida, la velocidad predeterminada es del 50%.

units_v

Optional. The unit that represents the velocity:

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

wait

Optional.

  • wait=True (default) – The project waits until spin_to_position is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for spin_to_position to finish.

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

stop#

stop immediately stops the selected motor or motor group.

Usage:
motor_1.stop(mode)

Parámetros

Descripción

modo

Optional. The stopping behavior to use when the motor stops:

  • BRAKE – Stops immediately.
  • COAST – Slows gradually to a stop.
  • HOLD – Stops and resists movement using motor feedback.

If the stopping mode is not specified or previously set, the default behavior is BRAKE.

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

Mutadores#

set_position#

set_position sets a specific position value to a motor or motor group, which updates the encoder reading.

Usage: motor_1.set_position(position, units)

Parámetros

Descripción

position

La nueva posición como un entero.

units

Optional. The unit that represents the rotational value:

  • DEGREES (default)
  • 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 sets the default spinning speed for all subsequent motor or motor group functions in the project.

Usage:
motor_1.set_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad a la que el motor o el grupo de motores girará como un flotante o un entero.

units

Optional. The unit that represents the velocity:

  • 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 behaves when it stops.

Usage:
motor_1.set_stopping(mode)

Parámetros

Descripción

mode

How the motor or motor group will stop:

  • BRAKE – Stops immediately.
  • COAST – Slows gradually to a stop.
  • HOLD – Stops and resists movement using motor feedback.

set_max_torque#

set_max_torque sets how much force a motor or motor group can exert.

Usage:
motor_1.set_max_torque(value, units)

Parámetros

Descripción

value

El nuevo par máximo para un motor o grupo de motores en forma de valor flotante o entero.

units

Optional. The unit that represents the torque:

  • PERCENT
  • TorqueUnits.NM (default) – Newton Meters
  • TorqueUnits.INLB – Inch Pounds
  • CurrentUnits.AMP

set_timeout#

set_timeout sets a time limit for how long a motor or motor group function will wait to reach its target. If the motor or motor group cannot complete the movement within the set time, it will stop automatically and continue with the next block.

Usage:
motor_1.set_timeout(value, units)

Parámetros

Descripción

value

El número máximo de segundos que una función de motor se ejecutará antes de detenerse y pasar a la siguiente función como un entero o un punto flotante.

units

Optional. The unit that represents the time:

  • SECONDS
  • MSEC (default) – Milliseconds

set_reversed#

set_reversed sets the motor to be reversed so that the FORWARD direction will spin clockwise. 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

Boolean value to set the direction reversed or not:

  • True – Reverse the motor’s direction
  • False – Return the motor’s direction to its default

reset_position#

reset_position sets the motor or motor group’s position to 0.

Usage:
motor_1.reset_position()

Parámetros

Descripción

Este método no tiene parámetros.

Captadores#

is_done#

is_done returns a Boolean indicating whether the motor or motor group is not spinning.

  • True - The motor is not spinning.

  • False - The motor is spinning.

Note: is_done only detects movement from methods that have a wait parameter.

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 a Boolean indicating whether the motor or motor group is spinning.

  • True - The motor is spinning.

  • False - The motor is not spinning.

Note: is_spinning only detects movement from methods that have a wait parameter.

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#

position returns the total distance the selected motor or motor group has rotated. This value can be positive or negative depending on the motor’s or motor group’s configuration.

Usage:
motor_1.position(units)

Parámetros

Descripción

units

Optional. The unit that represents the rotational value:

  • DEGREES (default)
  • 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 the current rotational speed of the motor or motor group in a range from -100% to 100% or -127 rpm to 127 rpm.

Usage:
motor_1.velocity(units)

Parámetros

Descripción

units

Optional. The unit that represents the velocity:

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

current#

current returns the amount of electrical current the motor or motor group in a range from 0.0 to 1.2 amps (amperes).

Usage:
motor_1.current(units)

Parámetros

Descripción

units

Optional. The unit that represents the current:

  • CurrentUnits.AMP (default) – Amps

power#

power returns the amount of electrical power the motor or motor group is consuming in a range from 0.0 to 22.0 watts.

Usage:
motor_1.power(units)

Parámetros

Descripción

units

Optional. The unit that represents the power:

  • PowerUnits.WATT (default) – Watt

torque#

torque returns the amount of torque currently being applied by the motor or motor group in a range from 0.0 to 22.0 inch-pounds (InLb) or 0.0 to 2.1 Newton-meters (Nm).

Usage:
motor_1.torque(units)

Parámetros

Descripción

units

The unit that represents the torque:

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

efficiency#

efficiency returns the current efficiency of the motor or motor group as a percent.

Usage:
motor_1.efficiency(units)

Parámetros

Descripción

units

Optional. The unit that represents the efficiency:

  • PERCENT (default)

temperature#

temperature returns the current temperature of the motor or motor group.

Usage:
motor_1.temperature(units)

Parámetros

Descripción

units

Optional. The units that represent the temperature:

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

count#

count returns the number of motors in a motor group as an integer.

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 currently set timeout in milliseconds.

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, which are necessary for configuring a motor or motor group outside of VEXcode.

Motor#

Motor creates a single 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 number of the port.

gears

Optional. The motor’s gear ratio:

  • GearSetting.RATIO_1_1 (default) – 1:1 Ration
  • GearSetting.RATIO_2_1 – 2:1 Ratio
  • GearSetting.RATIO_3_1 – 3:1 Ratio

reverse

Optional. Sets whether the motor’s spin should be reversed.

  • TrueFORWARD will spin clockwise
  • False (default) – FORWARD will 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
- 2:1 ratio
- Reversed
"""
motor_1 = Motor(Ports.PORT1, GearSetting.RATIO_2_1, True)

MotorGroup#

MotorGroup creates a motor group.

Usage:
MotorGroup(motors)

Parámetro

Descripción

motors

The names of previously created Motor objects to be 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)