Motor#

Introducción#

El motor inteligente IQ puede girar, mantener la posición y controlar la velocidad y el par con precisión. Puede usarse individualmente o como parte de un grupo de motores.

For the examples below, the configured motor will be named motor_1, and the configured motor group will be named motor_group_1. They will be used in all subsequent examples throughout this API documentation when referring to Motor and MotorGroup class methods.

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

Acciones – Controlar el movimiento de los motores.

  • spin – Spins a motor or motor group in a specified direction indefinitely.

  • spin_for – Spins a motor or motor group for a specified distance.

  • spin_to_position – Spins a motor to an absolute position.

  • stop – Stops a motor or motor group with configurable behavior.

Mutadores: cambian los diferentes atributos del motor.

  • set_velocity – Sets the default velocity for the motor or motor group.

  • set_max_torque – Sets the maximum torque for a motor or motor group.

  • set_position – Sets the motor or motor group’s position to a specific value.

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

  • set_timeout – Limits how long a motor 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.

  • position – Returns a motor or motor group’s current position.

  • velocity – Returns a motor or motor group’s current velocity.

  • current – Returns the current being used by a motor or motor group.

  • is_done – Returns whether a motor or motor group is currently not spinning.

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

  • direction – Returns the spin direction of a motor or motor group.

  • power – Returns the amount of power being used by a motor or motor group.

  • torque – Returns the torque generated by a motor or motor group.

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

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

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

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

Constructores: inicializan y configuran manualmente motores y grupos de motores.

Comportamiento#

spin#

spin spins a motor or motor group in the specified direction indefinitely.

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

Parámetros

Descripción

direction

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

  • FORWARD
  • REVERSE

velocity

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

units

Optional. The unit that represents the velocity:

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

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

spin_for#

spin_for spins a motor or motor group in a specified direction for a set distance relative to its current position.

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 no se especifica la velocidad, la predeterminada es el 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, then put it 
# at 90 degrees
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.spin_to_position(90, DEGREES)

# Spin the motor and different 
# velocities
# Using default velocity
motor_1.spin_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Spin slower
motor_1.spin_for(REVERSE, 150, MM, 20, PERCENT)
wait(1, SECONDS)
# Spin faster
motor_1.spin_for(FORWARD, 150, MM, 100, PERCENT)

spin_to_position#

spin_to_position spins a motor and motor group to an absolute 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 no se especifica la velocidad, la predeterminada es el 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 forward, then 
# put it at 90 degrees
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.spin_to_position(90, DEGREES)

# Spin forward then quickly reverse 
# to 0 degrees
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.spin_to_position(0, DEGREES, 100, PERCENT, wait=True)

stop#

stop stops a motor or motor group.

Usage:
motor_1.stop(mode)

Parámetros

Descripción

mode

Optional. How the motor or motor group will stop:

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

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

# Spin the motor and coast to a stop
motor_1.set_velocity(100, PERCENT)
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.stop(COAST)

Mutadores#

set_velocity#

set_velocity sets the default velocity for a motor or motor group. This velocity setting will be used for subsequent calls to any motor functions if a specific velocity is not provided.

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 (Rotations per minute)
  • VelocityUnits.DPS (Degrees per second)

# Spin the motor and 
# different velocities
# Using default velocity
motor_1.spin_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Spin slower
motor_1.set_velocity(20, PERCENT)
motor_1.spin_for(REVERSE, 150, MM)
wait(1, SECONDS)
# Spin faster
motor_1.set_velocity(100, PERCENT)
motor_1.spin_for(FORWARD, 150, MM)

set_max_torque#

set_max_torque sets the maximum torque for a motor or motor group. The torque can be set as torque, current, or a percent of maximum torque.

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

The unit that represents the torque:

  • PERCENT
  • TorqueUnits.NM (Newton Meters)
  • TorqueUnits.INLB (Inch Pounds)

# Spin the motor at different 
# torque values
# Default
motor_1.spin_to_position(45, DEGREES)
# Spin at a lower torque
motor_1.set_max_torque(20, PERCENT)
motor_1.spin_to_position(0, DEGREES)
# Spin at te max torque
motor_1.set_max_torque(100, PERCENT)
motor_1.spin_to_position(45, DEGREES)

set_position#

set_position sets the position of a motor or motor group.

Usage:
motor_1.set_position(position, units)

Parámetros

Descripción

position

La nueva posición como un entero.

units

The unit that represents the rotational value:

  • DEGREES
  • TURNS

# Position the motor at the 
# new 0 degrees
motor_1.set_position(180, DEGREES)
motor_1.spin_to_position(0)

set_stopping#

set_stopping sets the stopping mode for a motor or motor group.

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.

# Spin the motor and coast to a stop
motor_1.set_velocity(100, PERCENT)
motor_1.set_stopping(COAST)
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.stop()

set_timeout#

set_timeout sets a time limit for how long a motor 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 function.

Nota: El límite de tiempo del motor o del grupo de motores se utiliza para evitar que las funciones del motor que no alcanzan su posición objetivo detengan la ejecución del resto del proyecto.

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

# Spin the motor half a second and reset
motor_1.set_timeout(0.5, SECONDS)
motor_1.spin_for(FORWARD, 10, TURNS)
motor_1.spin_to_position(0)

set_reversed#

set_reversed sets the motor to be 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

Boolean value to set the direction reversed or not:

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

# Change the reverse direction while spinning
motor_1.spin_for(FORWARD, 45)
motor_1.set_reversed(True)
motor_1.spin_for(FORWARD, 45)

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.

# Reset the motor position after spinning
motor_1.spin(FORWARD)
wait(2, SECONDS)
motor_1.stop()
brain.screen.print(motor_1.position())
brain.screen.next_row()
wait(1, SECONDS)
motor_1.reset_position()
brain.screen.print(motor_1.position())

Captadores#

position#

position returns the current position of a motor or motor group as an integer or as a float.

Usage:
motor_1.position(units)

Parámetros

Descripción

units

Optional. The unit that represents the rotational value:

  • DEGREES (default)
  • TURNS

# Spin the motor and display the 
# ending position
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()
brain.screen.print(motor_1.position())

velocity#

velocity returns the current velocity of a motor or motor group as an integer or as a float.

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)

# Display the motor's velocity before 
# and after spinning
brain.screen.print(motor_1.velocity())
brain.screen.next_row()
motor_1.spin(FORWARD)
wait(1, SECONDS)
brain.screen.print(motor_1.velocity())
motor_1.stop()

current#

current returns the current of the motor or motor group in amps.

Usage:
motor_1.current(units)

Parámetros

Descripción

units

Optional. The unit that represents the current:

  • CurrentUnits.AMP – Amps
# Example coming soon

is_done#

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

  • True – The motor or motor group is not spinning.

  • False – The motor or motor group is spinning.

Usage:
motor_1.is_done()

Parámetros

Descripción

Este método no tiene parámetros.

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

is_spinning#

is_spinning returns a Boolean indicating whether a motor or motor group is currently spinning.

  • True – The motor or motor group is spinning.

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

Usage:
motor_1.is_spinning()

Parámetros

Descripción

Este método no tiene parámetros.

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

direction#

direction returns the current direction a motor or motor group is spinning in.

  • FORWARD

  • REVERSE

Usage:
motor_1.direction()

Parámetros

Descripción

Este método no tiene parámetros.

# Spin the motor and print the spin direction
motor_1.set_position(50, DEGREES)
motor_1.spin_to_position(0, DEGREES)
if motor_1.direction() == DirectionType.FORWARD:
    brain.screen.print('FORWARD')
elif motor_1.direction() == DirectionType.REVERSE:
    brain.screen.print('REVERSE')
else:
    brain.screen.print("Not Spinning.")

power#

power returns the current power of the motor in watts.

Usage:
motor_1.power()

Parámetros

Descripción

Este método no tiene parámetros.

# Example coming soon

torque#

torque returns the current torque of the motor.

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
# Example coming soon

efficiency#

efficiency returns the current efficiency of the motor in percent.

Usage:
motor_1.efficiency()

Parámetros

Descripción

Este método no tiene parámetros.

# Example coming soon

temperature#

temperature returns the current temperature of the motor.

Usage:
motor_1.temperature(units)

Parámetros

Descripción

units

Optional. The units that represent the temperature:

  • TemperatureUnits.CELSIUS (default)
  • TemperatureUnits.FAHRENHEIT
# Example coming soon

count#

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

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

Usage:
motor_group_1.count()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the amount of motors in the group
brain.screen.print(motor_group_1.count())

get_timeout#

get_timeout returns the current timeout for a motor in milliseconds.

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

Usage:
motor_1.get_timeout()

Parámetros

Descripción

Este método no tiene parámetros.

# Spin the motor half a second and reset, then display the timeout
motor_1.set_timeout(0.5, SECONDS)
motor_1.spin_for(FORWARD, 10, TURNS)
motor_1.spin_to_position(0)
brain.screen.print(motor_1.get_timeout())

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 motor.

Usage:
motor_1 = Motor(port, gears, reverse)

Parámetro

Descripción

port

Which Smart Port that the motor is connected to as Ports.PORT followed by the port number, ranging from 1 to 12.

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.

  • True – Motor is reversed
  • False (default) – Motor is not reversed

# Construct a Motor object named motor_1 in Port 1 on 
# the IQ (2nd gen) Brain which has the reverse flag set to True
motor_1 = Motor(Ports.PORT1, 1.0, True)

# Spin the motor forward for some time
motor_1.spin(FORWARD)
wait(1, SECONDS)
motor_1.stop()

Motor Group#

MotorGroup creates a motor group.

Usage:
motor_group_1 = MotorGroup(motors)

Parámetro

Descripción

motors

The names of previously created Motor objects to be put in the motor group. Up to 12 Motor objects can be added to the group.

# Construct a motor group with 2 motors
motor_group_1_motor_a = Motor(Ports.PORT1, False)
motor_group_1_motor_b = Motor(Ports.PORT6, True)
motor_group_1 = MotorGroup(motor_group_1_motor_a, motor_group_1_motor_b)

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