Transmisión#

Introducción#

El tren motriz controla el movimiento de un robot, permitiéndole avanzar, girar y detenerse con precisión.

También puede funcionar como un sistema de transmisión inteligente cuando se configura con un sensor giroscópico o un sensor inercial cerebral.

For the examples below, the configured drivetrain will be named drivetrain and will be used in all subsequent examples throughout this API documentation when referring to DriveTrain and SmartDrive class methods.

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

Acciones: Mover y girar el robot.

  • drive – Mueve el tren motriz en una dirección específica indefinidamente.

  • drive_for – Mueve el sistema de transmisión durante una distancia determinada.

  • turn – Gira la transmisión hacia la izquierda o hacia la derecha indefinidamente.

  • turn_for – Gira la transmisión durante una distancia determinada.

  • turn_to_heading – Gira el sistema de transmisión inteligente hacia un rumbo específico mediante sensores.

  • turn_to_rotation – Gira la transmisión inteligente a un valor de rotación específico.

  • stop – Detiene una transmisión con un comportamiento configurable.

  • calibrate_drivetrain – Calibrar el sensor inercial.

Mutadores: establecen velocidades de movimiento y giro predeterminadas.

  • set_drive_velocity – Establece la velocidad de movimiento predeterminada para el tren motriz.

  • set_turn_velocity – Establece la velocidad de movimiento de giro para el tren motriz.

  • set_stopping – Establece el comportamiento de detención (frenado, inercia o retención).

  • set_timeout – Limita el tiempo que una función de transmisión espera antes de darse por vencida si se bloquea el movimiento.

  • set_heading – Establece el rumbo de una transmisión inteligente en un valor específico.

  • set_rotation – Establece el valor de rotación de una transmisión inteligente en un valor específico.

  • set_turn_threshold – Establece el umbral de giro para una transmisión inteligente.

  • set_turn_constant – Establece la constante de giro para una transmisión inteligente.

  • set_turn_direction_reverse – Establece una transmisión inteligente para que su dirección se invierta.

Getters – Devuelven el estado y la posición del robot.

  • heading – Devuelve el rumbo actual de un sistema de transmisión inteligente.

  • rotación – Devuelve el valor de rotación actual de una transmisión inteligente.

  • velocidad – Devuelve la velocidad actual de un sistema de transmisión.

  • current – Devuelve la corriente del sistema de transmisión.

  • is_moving – Devuelve si un tren motriz se está moviendo actualmente.

  • is_done – Devuelve si un tren motriz no se está moviendo actualmente.

  • is_turning – Devuelve si un tren motriz está girando actualmente.

  • potencia – Devuelve la cantidad de energía utilizada por un sistema de transmisión.

  • torque – Devuelve el torque generado por un sistema de transmisión.

  • eficiencia – Devuelve la eficiencia de un sistema de transmisión.

  • temperatura – Devuelve la temperatura de la transmisión.

Constructores: inicializan y configuran manualmente la transmisión.

  • DriveTrain – Crea un tren de transmisión básico.

  • SmartDrive – Crea un sistema de transmisión configurado con un sensor giroscópico o un sensor inercial cerebral.

Comportamiento#

drive#

drive moves the drivetrain in a specified direction indefinitely.

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

Parámetros

Descripción

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

velocity

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

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

# Drive slowly in reverse then stop
drivetrain.drive(REVERSE, 20, PERCENT)
wait(2, SECONDS)
drivetrain.stop()

drive_for#

drive_for moves the drivetrain in a specified direction for a set distance.

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

Parámetros

Descripción

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

distance

La distancia que debe recorrer el tren motriz, expresada en forma de número flotante o entero.

units

The unit that represents the distance:

  • MM – Millimeters
  • INCHES (default)
  • DistanceUnits.CM – Centimeters

velocity

Opcional. La velocidad a la que se moverá la transmisión, 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
  • 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 forward and backward
drivetrain.drive_for(FORWARD, 10)
drivetrain.drive_for(REVERSE, 10)

# Quickly drive forward and backward
drivetrain.drive_for(FORWARD, 200, MM, 100, PERCENT)
drivetrain.drive_for(REVERSE, 200, MM, 100, PERCENT)

turn#

turn turns the drivetrain left or right indefinitely.

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 no se especifica la velocidad, la predeterminada es el 50 %.

units

Optional. The unit that represents the velocity:

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

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

# Quickly turn right and left, then stop
drivetrain.turn(RIGHT, 100, PERCENT)
wait(2, SECONDS)
drivetrain.turn(LEFT, 100, PERCENT)
wait(2, SECONDS)
drivetrain.stop()

turn_for#

turn_for turns the drivetrain left or right for a specified angle or rotations.

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 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
  • 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 the robot right and left
drivetrain.turn_for(RIGHT, 90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_for(LEFT, 90, DEGREES)

# Quickly turn the robot right and left
drivetrain.turn_for(RIGHT, 90, DEGREES, 100, PERCENT)
wait(1, SECONDS)
drivetrain.turn_for(LEFT, 90, DEGREES, 100, PERCENT)

turn_to_heading#

turn_to_heading turns a smart drivetrain to a specified heading.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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á 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 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 turns a smart drivetrain to a specified rotational value.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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á 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 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_rotation 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 stops a drivetrain.

Usage:
drivetrain.stop(mode)

Parámetros

Descripción

mode

Optional. How the drivetrain will stop:

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

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

# Drive forward and coast to a stop
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop(COAST)

calibrate_drivetrain#

calibrate_drivetrain calibrates the Gyro Sensor or Brain Inertial Sensor that is configured with the drivetrain. Calibration should be done when the drivetrain is not moving.

Nota: El cerebro se calibrará automáticamente al inicio de cada proyecto.

Usage:
calibrate_drivetrain()

Parámetros

Descripción

Este método no tiene parámetros.

# Calibrate the DriveTrain after turning
drivetrain.turn_for(RIGHT, 90, DEGREES)
calibrate_drivetrain()
brain.screen.print("Done!")

Mutadores#

set_drive_velocity#

set_drive_velocity sets the default moving velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions if a specific velocity is not provided.

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

# Drive forward at different velocities
# Default velocity
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive slower
drivetrain.set_drive_velocity(20, PERCENT)
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive faster
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive_for(FORWARD, 150, MM)

set_turn_velocity#

set_turn_velocity sets the default turning velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions if a specific velocity is not provided.

Usage:
drivetrain.set_turn_velocity(velocity, units)

Parámetros

Descripción

velocity

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

units

Optional. The unit that represents the velocity:

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

# Turn at different velocities
# Default velocity
drivetrain.turn_for(RIGHT, 360)
wait(1, SECONDS)
# Turn slower
drivetrain.set_turn_velocity(20, PERCENT)
drivetrain.turn_for(RIGHT, 360)
wait(1, SECONDS)
# Turn faster
drivetrain.set_turn_velocity(100, PERCENT)
drivetrain.turn_for(RIGHT, 360)

set_stopping#

set_stopping sets the stopping mode for a drivetrain.

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.

# Drive forward and coast to a stop
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.set_stopping(COAST)
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()

set_timeout#

set_timeout sets a time limit for how long a drivetrain function will wait to reach its target. If the drivetrain 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 tren motriz se utiliza para evitar que las funciones del tren motriz que no alcanzan su posición objetivo detengan la ejecución del resto del proyecto.

Usage:
drivetrain.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

# Turn right after driving forward
drivetrain.set_timeout(1, SECONDS)
drivetrain.drive_for(FORWARD, 25, INCHES)
drivetrain.turn_for(RIGHT, 90)

set_heading#

set_heading sets the heading of a smart drivetrain.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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 method sets the rotation for the smart drivetrain.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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 method 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 funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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.

# Turn and display the heading with different turn thresholds
brain.screen.set_font(FontType.PROP20)
brain.screen.print("Default threshold: ")
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.print(drivetrain.heading())
brain.screen.next_row()
wait(2, SECONDS)
brain_inertial.reset_heading()
brain.screen.print("20 degree Threshold: ")
drivetrain.set_turn_threshold(20)
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.print(drivetrain.heading())

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 funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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.

# Turn and display the heading with different turn constants
brain.screen.set_font(FontType.PROP20)
brain.screen.print("Default Constant: ")
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.print(drivetrain.heading())
brain.screen.next_row()
wait(2, SECONDS)
brain_inertial.reset_heading()
brain.screen.print("0.2 Turn Constant: ")
drivetrain.set_turn_constant(0.2)
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.print(drivetrain.heading())

set_turn_direction_reverse#

set_turn_direction_reverse(value) 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 funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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

# Example coming soon

Captadores#

heading#

heading returns the current heading of a smart drivetrain as a float.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

Usage:
drivetrain.heading(units)

Parámetros

Descripción

units

Optional. The unit that represents the rotational value:

  • DEGREES (default)
  • TURNS

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

rotation#

rotation returns the current rotational value of a smart drivetrain as a float.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

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

# Display the robot's velocity before 
# and after moving
brain.screen.print(drivetrain.velocity())
brain.screen.next_row()
drivetrain.drive(FORWARD)
wait(1, SECONDS)
brain.screen.print(drivetrain.velocity())
drivetrain.stop()

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

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.

Usage:
drivetrain.is_moving()

Parámetros

Descripción

Este método no tiene parámetros.

# Stop the Drivetrain after moving 
# forward for some time
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
while drivetrain.is_moving():
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Still Moving...")
    wait (0.1, SECONDS)
    brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")

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.

Usage:
drivetrain.is_done()

Parámetros

Descripción

Este método no tiene parámetros.

# Stop the Drivetrain and turn right 
# after moving forward for some time
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
while True:
    if drivetrain.is_done():
        drivetrain.turn_for(RIGHT, 360)
        break
    else:
        brain.screen.set_cursor(1, 1)
        brain.screen.print("Still Moving...")
        wait (0.1, SECONDS)
        brain.screen.clear_screen()

is_turning#

is_moving returns a Boolean indicating whether a smart drivetrain is currently turning.

  • True – The smart drivetrain is turning.

  • False – The smart drivetrain is not turning.

Nota: Este método solo funcionará con una transmisión que haya sido configurada con un sensor giroscópico o un sensor inercial cerebral.

Usage:
drivetrain.is_turning()

Parámetros

Descripción

Este método no tiene parámetros.

# Detect when the Drivetrain is still turning
drivetrain.turn_for(RIGHT, 180, DEGREES, wait=False)
while drivetrain.is_turning():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Turning...")
    wait (0.1, SECONDS)
brain.screen.set_cursor(1, 1)
brain.screen.print("Done!")

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.

# Example coming soon

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

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.

# Example coming soon

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

Constructores#

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

Nota: Para crear un sistema de transmisión, ya se deben haber creado al menos dos objetos Motor o MotorGroup.

Drivetrain#

DriveTrain creates a drivetrain without a Gyro Sensor or Brain Inertial Sensor.

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

Parámetro

Descripción

lm

El nombre de un motor o grupo de motores izquierdo creado previamente.

rm

El nombre de un motor o grupo de motores derecho creado previamente.

wheelTravel

Opcional. La circunferencia de las ruedas del tren de potencia. 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 unit that represents the wheelTravel, trackWidth, and wheelBase values:

  • MM (default) – Millimeters
  • INCHES
  • DistanceUnits.CM – Centimeters

externalGearRatio

Opcional. La relación de transmisión se utiliza para compensar las distancias de conducción si el engranaje se utiliza como un número entero.

# Create the Motors
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT2, 1.0, True)
# Construct a 2-Motor Drivetrain "drivetrain" with the
# DriveTrain class
drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 200, 173, 76, MM, 1)

drivetrain.drive_for(FORWARD, 200, MM)
drivetrain.drive_for(REVERSE, 200, MM)

# Create the left Motors and group them under the
# MotorGroup "left_motors"
left_motor_a = Motor(Ports.PORT1, 1.0, False)
left_motor_b = Motor(Ports.PORT2, 1.0, False)
left_drive_smart = MotorGroup(left_motor_a, left_motor_b)
# Create the right Motors and group them under the
# MotorGroup "right_motors"
right_motor_a = Motor(Ports.PORT3, 1.0, True)
right_motor_b = Motor(Ports.PORT4, 1.0, True)
right_drive_smart = MotorGroup(right_motor_a, right_motor_b)
# Construct a 4-Motor Drivetrain "drivetrain" with the
# DriveTrain class
drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 200, 173, 76, MM, 1)

drivetrain.drive_for(FORWARD, 200, MM)
drivetrain.drive_for(REVERSE, 200, MM)

Smart Drivetrain#

SmartDrive creates a drivetrain with a Gyro Sensor or Brain Inertial Sensor.

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

Parámetro

Descripción

lm

El nombre de un motor o grupo de motores izquierdo creado previamente.

rm

El nombre de un motor o grupo de motores derecho creado previamente.

g

El nombre de un Sensor inercial o Sensor giroscópico creado previamente.

wheelTravel

Opcional. La circunferencia de las ruedas del tren de potencia. 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 unit that represents the wheelTravel, trackWidth, and wheelBase values:

  • MM (default) – Millimeters
  • INCHES
  • DistanceUnits.CM – Centimeters

externalGearRatio

Opcional. La relación de transmisión se utiliza para compensar las distancias de conducción si el engranaje se utiliza como un número entero.

# Construct a SmartDrive Drivetrain with 2 motors
brain_inertial = Inertial()
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT6, 1.0, True)

drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)

drivetrain.drive_for(FORWARD, 200, MM)
drivetrain.drive_for(REVERSE, 200, MM)

Si va a crear un sistema de transmisión inteligente con varios motores, deberá crear los Motores por separado antes de agruparlos en un Grupo de motores.

# Construct a SmartDrive Drivetrain with 4 motors
brain_inertial = Inertial()
left_motor_a = Motor(Ports.PORT1, 1.0, False)
left_motor_b = Motor(Ports.PORT2, 1.0, False)
left_drive_smart = MotorGroup(left_motor_a, left_motor_b)

right_motor_a = Motor(Ports.PORT5, 1.0, True)
right_motor_b = Motor(Ports.PORT6, 1.0, True)
right_drive_smart = MotorGroup(right_motor_a, right_motor_b)

drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)

drivetrain.drive_for(FORWARD, 200, MM)
drivetrain.drive_for(REVERSE, 200, MM)