Transmisión#

Introducción#

Un sistema de transmisión permite que el robot se mueva de forma continua o durante distancias establecidas, gire por grados o en una dirección y responda a cambios en su orientación rotacional.

Si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico, la transmisión podrá realizar movimientos de avance, retroceso y giro más precisos al rastrear el rumbo y la rotación del sensor.

La categoría Tren Motriz también incluye métodos de configuración que permiten establecer velocidades de conducción y giro, definir comportamientos de frenado, aplicar tiempos de espera para evitar bloqueos de ejecución y actualizar manualmente los valores de rumbo o rotación del robot. Estas funciones ofrecen flexibilidad al diseñar comportamientos autónomos o ajustes en tiempo real.

This page uses drivetrain as the example Drivetrain name. Replace it with your own configured name as needed.

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

Acciones: Mover o girar el robot.

  • drive – Drives the robot continuously forward or in reverse using the current drive velocity.

  • drive_for – Drives the robot forward or in reverse for a set distance.

  • turn – Rotates the robot continuously left or right using the current turn velocity.

  • turn_for – Rotates the robot left or right for a specified angle.

  • turn_to_heading – Rotates the robot to face a specific absolute heading.

  • turn_to_rotation – Rotates the robot to reach a specific cumulative rotation.

  • stop – Stops the drivetrain using the configured stopping mode.

  • calibrate_drivetrain – Calibrates the drivetrain’s configured Inertial, GPS, or Gyro Sensor.

Mutadores: configura velocidades, comportamiento de detención y tiempos de espera.

Getters – Comprueba si la transmisión se está moviendo.

  • is_done – Returns whether the drivetrain is not currently moving.

  • is_moving – Returns whether the drivetrain is currently moving.

  • heading – Returns the drivetrain’s heading angle (0 to 359.99 degrees).

  • rotation – Returns how much the drivetrain has turned since the project started.

  • velocity – Returns the drivetrain’s current velocity.

  • current – Returns the drivetrain’s current draw.

  • power – Returns the drivetrain’s power usage.

  • torque – Returns the drivetrain’s torque.

  • efficiency – Returns the drivetrain’s efficiency.

  • temperature – Returns the drivetrain motors’ temperature.

  • get_timeout – Returns the current timeout setting.

Constructor: inicializa manualmente un tren motriz.

Comportamiento#

drive#

drive moves the drivetrain forward or in reverse using the current drive velocity. This method runs continuously until another Drivetrain method interrupts it or the project stops.

Usage:
drivetrain.drive(direction, velocity, units)

Parámetros

Descripción

direction

The direction in which the robot drives:

  • FORWARD
  • REVERSE

velocity

Opcional. La velocidad a la que se moverá la transmisión, como valor de punto flotante o entero. Si la velocidad no se especifica o previamente establecida, la velocidad predeterminada es del 50%.

units

Optional. The unit to represent the velocity:

  • RPM (default) – Rotations per minute
  • PERCENT
  • VelocityUnits.DPS – Degrees per second
# Drive forward, then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()

# Drive forward at 360 degrees per second
drivetrain.drive(FORWARD, 360.0, VelocityUnits.DPS)

drive_for#

drive_for moves the drivetrain forward or in reverse for a specified distance using the current drive velocity.

Usage:
drivetrain.drive_for(direction, distance, units, velocity, units_v, wait)

Parámetros

Descripción

direction

The direction in which the robot drives:

  • FORWARD
  • REVERSE

distance

La distancia que recorrerá la transmisión.

units

The units representing the distance:

  • INCHES (default)
  • MM – Millimeters

velocity

Opcional. La velocidad a la que se moverá la transmisión, 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 to represent the velocity:

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

wait

Optional.

  • wait=True (default) – The project waits until drive_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 drive_for to finish.

# Drive forwards and backwards
drivetrain.drive_for(FORWARD, 5)
wait(1, SECONDS)
drivetrain.drive_for(REVERSE, 5)

turn#

turn rotates the drivetrain continuously left or right using the current turn velocity. The drivetrain will keep turning until another Drivetrain method runs or the project stops.

Usage:
drivetrain.turn(direction, velocity, units)

Parámetros

Descripción

direction

The direction in which to turn:

  • LEFT
  • RIGHT

velocity

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

units

Optional. The unit that represents the velocity:

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

# Turn right, then stop
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.stop()

turn_for#

turn_for rotates the drivetrain left or right for a specific number of degrees using the current turn velocity.

Usage:
drivetrain.turn_for(direction, angle, units, velocity, units_v, wait)

Parámetros

Descripción

direction

The direction in which to turn:

  • LEFT
  • RIGHT

angle

La cantidad de grados que girará la transmisión como un número flotante o entero.

units

The unit that represents the rotational value:

  • DEGREES (default)
  • TURNS

velocity

Opcional. La velocidad a la que girará la transmisión, 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
  • VelocityUnits.DPS – Degrees per second

wait

Optional.

  • wait=True (default) – The project waits until turn_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 turn_for to finish.

# Turn left, then turn around to the right
drivetrain.turn_for(LEFT, 90)
drivetrain.turn_for(RIGHT, 180)

turn_to_heading#

turn_to_heading rotates the drivetrain to face a specific rotational value using the current turn velocity.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.turn_to_heading(angle, units, velocity, units_v, wait)

Parámetros

Descripción

angle

El encabezado para girar la transmisión para que quede como un flotante o un entero.

units

The unit that represents the rotational value:

  • DEGREES

velocity

Opcional. La velocidad a la que girará la transmisión, 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
  • VelocityUnits.DPS – Degrees per second

wait

Optional.

  • wait=True (default) – The project waits until turn_to_heading 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 turn_to_heading to finish.

# Turn to face the cardinal directions
drivetrain.turn_to_heading(90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(180, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(270, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(0, DEGREES)

# Turn twice slowly
drivetrain.turn_to_heading(90, DEGREES, 20, PERCENT)
wait(1, SECONDS)
drivetrain.turn_to_heading(180, DEGREES, 20, PERCENT)

turn_to_rotation#

turn_to_rotation rotates the drivetrain to face a specific rotational value using the current turn velocity.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.turn_to_rotation(angle, units, velocity, units_v, wait)

Parámetros

Descripción

angle

El valor rotacional para girar la transmisión para que quede como un flotante o un entero.

units

The unit that represents the rotational value:

  • DEGREES
  • TURNS

velocity

Opcional. La velocidad a la que girará la transmisión, 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
  • VelocityUnits.DPS – Degrees per second

wait

Optional.

  • wait=True (default) – The project waits until turn_to_rotation 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 turn_to_heading to finish.

# Turn left, then spin in a circle clockwise and face right
drivetrain.turn_to_rotation(-90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_rotation(450, DEGREES)

# Turn left then slowly spin in a circle clockwise
drivetrain.turn_to_rotation(-90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_rotation(450, DEGREES, 20, PERCENT)

stop#

stop immediately stops all movement of the drivetrain.

Usage:
drivetrain.stop(mode)

Parámetros

Descripción

modo

Optional. The stopping behavior to use when the drivetrain 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.

# Drive forward, then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()

calibrate_drivetrain#

calibrate_drivetrain calibrates the drivetrain’s configured Inertial, GPS, or Gyro Sensor. All subsequent commands will wait for the calibration to complete before executing. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a specified period. During this time, the sensor must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
calibrate_drivetrain()

Parámetros

Descripción

Este método no tiene parámetros.

Mutadores#

set_drive_velocity#

set_drive_velocity sets the movement velocity as a percentage for all subsequent drive methods in the project. By default, this is 50%.

Usage:
drivetrain.set_drive_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad a la que se moverá la transmisión, como un valor flotante o entero.

units

Optional. The unit that represents the velocity:

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

# Drive forward at the default velocity
drivetrain.drive_for(FORWARD, 100, MM)
wait(1, SECONDS)

# Drive slower
drivetrain.set_drive_velocity(20, PERCENT)
drivetrain.drive_for(FORWARD, 100, MM)
wait(1, SECONDS)

# Drive faster
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive_for(FORWARD, 100, MM)
wait(1, SECONDS)

set_turn_velocity#

set_turn_velocity(velocity, units) sets the default velocity as a percentage for all subsequent turn methods in the project. By default, this is 50%.

Usage:
drivetrain.set_turn_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad a la que girará la transmisión, como un número flotante o entero.

units

Optional. The unit that represents the velocity:

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

# Turn at the default velocity
drivetrain.turn_for(RIGHT, 100)
wait(1, SECONDS)

# Turn slower
drivetrain.set_turn_velocity(20, PERCENT)
drivetrain.turn_for(RIGHT, 100)
wait(1, SECONDS)

# Turn faster
drivetrain.set_turn_velocity(100, PERCENT)
drivetrain.turn_for(RIGHT, 100)
wait(1, SECONDS)

set_stopping#

set_stopping sets how the drivetrain behaves when drivetrain movement ends.

Usage:
drivetrain.set_stopping(mode)

Parámetros

Descripción

mode

How the drivetrain will stop:

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

set_timeout#

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

Nota: El límite de tiempo del tren motriz se utiliza para evitar que los comandos del tren motriz que no alcanzan su posición objetivo detengan la ejecución de otros comandos.

Usage:
drivetrain.set_timeout(timeout, units)

Parámetros

Descripción

value

El número máximo de segundos que se ejecutará un comando de motor antes de detenerse y pasar al siguiente comando como un entero o un punto flotante.

units

Optional. The unit that represents the time:

  • SECONDS
  • MSEC (default) – Milliseconds

set_heading#

set_heading sets the robot’s current heading to a specified value.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.set_heading(heading, units)

Parámetros

Descripción

heading

El nuevo encabezado como un valor flotante o entero.

units

Optional. The unit that represents the heading:

  • DEGREES (default)
  • TURNS

# Face the new 0 degrees
drivetrain.set_heading(90, DEGREES)
drivetrain.turn_to_heading(0, DEGREES)

set_rotation#

set_rotation sets the robot’s current cumulative rotation value.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.set_rotation(rotation, units)

Parámetros

Descripción

rotation

El nuevo valor rotacional como flotante o entero.

units

Optional. The unit that represents the heading:

  • DEGREES (default)
  • TURNS

# Spin counterclockwise two times
drivetrain.set_rotation(720, DEGREES)
drivetrain.turn_to_rotation(0, DEGREES)

set_turn_threshold#

set_turn_threshold sets the turn threshold for a smart drivetrain. The threshold value is used to determine that turns are complete. If this is too large, then turns will not be accurate. If too small, then turns may not complete.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.set_turn_threshold(value)

Parámetros

Descripción

value

El umbral de giro se establece en grados, como un valor decimal o entero. El umbral de giro predeterminado es 1 grado.

set_turn_constant#

set_turn_constant sets the turn constant for a smart drivetrain. Smart drivetrains use a simple P controller when doing turns. This constant, generally known as kp, is the gain used in the equation that turns angular error into motor velocity.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.set_turn_constant(value)

Parámetros

Descripción

value

La nueva constante de giro está en el rango de 0,1 a 4,0. El valor predeterminado es 1,0.

set_turn_direction_reverse#

set_turn_direction_reverse sets the smart drivetrain to be reversed. This method works the same as setting the reverse parameter to True when constructing a SmartDrive.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.set_turn_direction_reverse(value)

Parámetros

Descripción

value

Boolean value to set the direction reversed or not:

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

Captadores#

is_done#

is_done returns a Boolean indicating whether a drivetrain is not currently moving.

  • True – The drivetrain is not moving.

  • False – The drivetrain is moving.

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

Usage:
drivetrain.is_done()

Parámetros

Descripción

Este método no tiene parámetros.

is_moving#

is_moving returns a Boolean indicating whether a drivetrain is currently moving.

  • True – The drivetrain is moving.

  • False – The drivetrain is not moving.

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

Usage:
Usage:
drivetrain.is_moving()

Parámetros

Descripción

Este método no tiene parámetros.

heading#

heading returns the drivetrain’s heading angle as a float.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.heading(units)

Parámetros

Descripción

units

Optional. The unit that represents the rotational value:

  • DEGREES (default) – 0.00 to 359.99
  • TURNS

# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print("Heading: ")
brain.screen.print(drivetrain.heading())

rotation#

rotation returns how much the drivetrain has turned since the project started as a float: positive for clockwise, negative for counterclockwise.

Nota: Este método solo está disponible si la transmisión está configurada con un Sensor inercial, Sensor GPS o Sensor giroscópico en la ventana Dispositivos.

Usage:
drivetrain.rotation(units)

Parámetros

Descripción

units

Optional. The unit that represents the rotational value:

  • DEGREES (default)
  • TURNS

# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print("Rotation: ")
brain.screen.print(drivetrain.rotation())

velocity#

velocity returns the current velocity of a drivetrain as a float.

Usage:
drivetrain.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 current of the drivetrain in amps.

Usage:
drivetrain.current(units)

Parámetros

Descripción

units

Optional. The unit that represents the current:

  • CurrentUnits.AMP – Amps

power#

power returns the average power of the drivetrain in watts.

Usage:
drivetrain.power()

Parámetros

Descripción

Este método no tiene parámetros.

torque#

torque returns the average torque of the drivetrain.

Usage:
drivetrain.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 average efficiency of the drivetrain in percent.

Usage:
drivetrain.efficiency()

Parámetros

Descripción

Este método no tiene parámetros.

temperature#

temperature returns the average temperature of the drivetrain.

Usage:
drivetrain.temperature(units)

Parámetros

Descripción

units

Optional. The units that represent the temperature:

  • TemperatureUnits.CELSIUS (default)
  • TemperatureUnits.FAHRENHEIT

get_timeout#

get_timeout returns the currently set timeout in milliseconds.

drivetrain.get_timeout()

Parámetros

Descripción

Este método no tiene parámetros.

Constructor#

Constructors are used to manually create DriveTrain and SmartDrive objects, which are necessary for configuring a drivetrain outside of VEXcode.

DriveTrain#

DriveTrain creates a drivetrain without an Inertial Sensor, GPS Sensor, or Gyro Sensor.

Usage:
DriveTrain(lm, rm, wheelTravel, trackWidth, wheelBase, units, externalGearRatio)

Parámetro

Descripción

lm

El nombre del motor o grupo de motores izquierdo.

rm

El nombre del motor o grupo de motores derecho.

wheelTravel

Opcional. Circunferencia de las ruedas motrices. El valor predeterminado es 300 milímetros.

trackWidth

Opcional. Ancho de vía de la transmisión. El valor predeterminado es 320 milímetros.

wheelBase

Opcional. Distancia entre ejes del tren motriz. La distancia predeterminada es de 320 milímetros.

units

Optional. The units that represent wheelTravel, trackWidth and wheelBase:

  • MM (default) – Millimeters
  • INCHES

externalGearRatio

Opcional. La relación de transmisión utilizada para compensar las distancias de conducción si se utilizan engranajes.

Note: Motors and/or Motor Groups must be created first before they can be used to create an object with the DriveTrain constructor.

# Create the Motors
left_motor = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)
right_motor = Motor(Ports.PORT2, GearSetting.RATIO_18_1, True)

# Create a drivetrain with default values
drivetrain = DriveTrain(left_motor, right_motor)

# Create the motors
left_motor = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)
right_motor = Motor(Ports.PORT2, GearSetting.RATIO_18_1, True)

"""
Create a drivetrain with the following values:
- wheelTravel = 319.19
- trackWidth = 295
- wheelBase = 40
- units = MM (Millimeters)
- externalGearRatio - 1
"""
drivetrain = DriveTrain(left_motor, right_motor, 319.19, 295, 40, MM, 1)

SmartDrive#

SmartDrive creates a drivetrain configured with an Inertial Sensor, GPS Sensor, or Gyro Sensor.

Usage:
SmartDrive(lm, rm, g, wheelTravel, trackWidth, wheelBase, units, externalGearRatio)

Parámetro

Descripción

lm

El nombre del Motor o Grupo Motor izquierdo.

rm

El nombre del Motor o Grupo Motor derecho.

g

El nombre del Sensor inercial, Sensor GPS o Sensor giroscópico.

wheelTravel

Opcional. Circunferencia de las ruedas motrices. El valor predeterminado es 300 milímetros.

trackWidth

Opcional. Ancho de vía del tren motriz. El valor predeterminado es 320 milímetros.

wheelBase

Opcional. Distancia entre ejes del tren motriz. La distancia predeterminada es de 320 milímetros.

units

Optional. The units that represent wheelTravel, trackWidth and wheelBase:

  • MM (default) – Millimeters
  • INCHES

externalGearRatio

Opcional. La relación de transmisión utilizada para compensar las distancias de conducción si se utilizan engranajes.

Note: Motors and/or Motor Groups must be created first before they can be used to create an object with the SmartDrive constructor.

# Create the Motors
left_motor = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)
right_motor = Motor(Ports.PORT2, GearSetting.RATIO_18_1, True)

# Create a Gyro Sensor in Port A
gyro_a = Gyro(brain.three_wire_port.a)


# Create a drivetrain with default values
drivetrain = DriveTrain(left_motor, right_motor, gyro_a)

# Create the Motors
left_motor = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)
right_motor = Motor(Ports.PORT2, GearSetting.RATIO_18_1, True)

# Create a Gyro Sensor in Port A
gyro_a = Gyro(brain.three_wire_port.a)

"""
Create a drivetrain with the following values:
- wheelTravel = 319.19
- trackWidth = 295
- wheelBase = 40
- units = MM (Millimeters)
- externalGearRatio - 1
"""
drivetrain = DriveTrain(left_motor, right_motor, gyro_a, 319.19, 295, 40, MM, 1)