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.
Motor– Creates a single motor.MotorGroup– Creates a motor group.
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 |
|---|---|
|
The direction in which to spin the motor or motor group:
|
|
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%. |
|
Optional. The unit that represents the velocity:
|
# 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 |
|---|---|
|
The direction in which to spin the motor or motor group:
|
|
La cantidad de grados que girará el motor o el grupo de motores como un valor flotante o entero. |
|
Optional. The unit that represents the rotational value:
|
|
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%. |
|
Optional. The unit that represents the velocity:
|
|
Optional.
|
# 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 |
|---|---|
|
La posición para girar el motor o el grupo de motores como un flotante o un entero. |
|
The unit that represents the rotational value:
|
|
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%. |
|
Optional. The unit that represents the velocity:
|
|
Optional.
|
# 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:
If the stopping mode is not specified or previously set, the default behavior is |
# 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 |
|---|---|
|
La nueva posición como un entero. |
|
Optional. The unit that represents the rotational value:
|
# 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 |
|---|---|
|
La velocidad a la que el motor o el grupo de motores girará como un flotante o un entero. |
|
Optional. The unit that represents the velocity:
|
# 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 |
|---|---|
|
How the motor or motor group will stop:
|
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 |
|---|---|
|
El nuevo par máximo para un motor o grupo de motores en forma de valor flotante o entero. |
|
Optional. The unit that represents the torque:
|
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 |
|---|---|
|
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. |
|
Optional. The unit that represents the time:
|
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 |
|---|---|
|
Boolean value to set the direction reversed or not:
|
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 |
|---|---|
|
Optional. The unit that represents the rotational value:
|
# 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 |
|---|---|
|
Optional. The unit that represents the velocity:
|
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 |
|---|---|
|
Optional. The unit that represents the current:
|
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 |
|---|---|
|
Optional. The unit that represents the power:
|
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 |
|---|---|
|
The unit that represents the torque:
|
efficiency#
efficiency returns the current efficiency of the motor or motor group as a percent.
Usage:
motor_1.efficiency(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The unit that represents the efficiency:
|
temperature#
temperature returns the current temperature of the motor or motor group.
Usage:
motor_1.temperature(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The units that represent the temperature:
|
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 |
|---|---|
|
The Smart Port that the motor is connected to, written as |
|
Optional. The motor’s gear ratio:
|
|
Optional. Sets whether the motor’s spin should be reversed.
|
# 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 |
|---|---|
|
The names of previously created |
# 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)