Movimiento#

Introducción#

Los motores controlan el movimiento de las partes de un robot. Se pueden usar para levantar un brazo, girar una garra, hacer girar una rueda o mover otra parte de la estructura. Dos motores pueden funcionar juntos como unDrivetrain.mdde transmisión para mover y girar todo el robot.

Each motor is configured in the Devices window. Depending on the build, motor names can change. For example, the Competition Advanced 2.0 build has a motor named arm_motor. A custom robot may use different motor names.

By default, FORWARD spins a motor counterclockwise, and REVERSE spins a motor clockwise. If a motor is set to reverse in the Devices window, those directions will be switched.

Un motor VEX GO que muestra la dirección de avance indicada por un signo más y una flecha que indica que está girando hacia la izquierda, o en sentido contrario a las agujas del reloj. Un motor VEX GO que muestra la dirección inversa indicada por un signo menos y una flecha que indica que está girando hacia la derecha, o en el sentido de las agujas del reloj.

Existen muchas maneras de programar motores. A continuación se muestra una lista de todos los métodos de movimiento:

Acciones: Detener y hacer girar los motores.

  • spin — Spins a motor forward or reverse forever.

  • spin_for — Spins a motor for a specific distance.

  • spin_to_position — Spins a motor to a specific position.

  • stop — Stops a motor from spinning.

Motadores: Ajuste la configuración del motor.

  • set_velocity — Tells a motor how fast to spin.

  • set_max_torque — Sets how hard a motor is allowed to push while spinning.

  • set_position — Changes the motor’s current position to a new value.

  • set_stopping — Sets how a motor will stop moving: by braking, coasting, or holding.

  • set_timeout — Sets how much time a motor will try to finish a movement.

Obtenedores: compruebe el estado del motor.

  • get_position — Returns the motor’s current position.

  • get_velocity — Returns how fast the motor is spinning, as a percentage from -100% to 100%.

  • get_current — Returns how much power the motor is using from the battery, as a percentage from 0% to 100%.

  • is_stopped — Returns whether the motor is finished moving, as a Boolean value.

  • is_moving — Returns whether the motor is spinning, as a Boolean value.

Comportamiento#

spin#

spin spins a motor forward or reverse forever. The motor will continue to spin until it is given another action, like spinning in a different direction or stopping.

Usage:
arm_motor.spin(direction)

Parámetros

Descripción

direction

The direction the motor spins: FORWARD or REVERSE.

# Build Used: Competition Advanced 2.0
def main():
    # Raise the ArmMotor, then stop
    arm_motor.spin(REVERSE)
    wait(1, SECONDS)
    arm_motor.stop()

# Start threads — Do not delete
start_thread(main)

spin_for#

spin_for spins a motor for a specific distance. The spin is relative to the current position of the motor. The project will wait until the motor is done spinning before the next line of code runs.

Usage:
arm_motor.spin_for(direction, angle, units, wait)

Parámetros

Descripción

direction

The direction the motor spins: FORWARD or REVERSE.

angle

The distance the motor spins. DEGREES use integers. TURNS can use integers or decimals.

units

Optional. The distance unit: DEGREES (default) or TURNS.

wait

Optional. wait=True (default) makes the project wait until the motor is done spinning before the next line of code runs. wait=False makes the next line of code run right away.

# Build Used: Competition Advanced 2.0
def main():
    # Raise and lower the ArmMotor
    arm_motor.spin_for(REVERSE, 180, DEGREES)
    wait(1, SECONDS)
    arm_motor.spin_for(FORWARD, 180, DEGREES)

# Start threads — Do not delete
start_thread(main)

spin_to_position#

spin_to_position spins a motor to a specific position.

A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. At the beginning of a project, the motor position is set to 0 degrees. The motor position can also be set using the set_position method.

Los valores de posición son absolutos. Esto significa que la dirección de giro depende de la posición actual del motor.

Por ejemplo, si el motor parte de 0 grados y gira hasta una posición de 720 grados, girará dos vueltas hacia adelante. Si luego gira hasta una posición de 360 ​​grados, girará una vuelta hacia atrás, ya que 360 ​​es menor que 720.

Usage:
arm_motor.spin_to_position(angle, units, wait)

Parámetros

Descripción

angle

The position value the motor will spin to. DEGREES use integers. TURNS can use integers or decimals.

units

Optional. The position unit: DEGREES (default) or TURNS.

wait

Optional. wait=True (default) makes the project wait until the motor is done spinning before the next line of code runs. wait=False makes the next line of code run right away.

# Build Used: Competition Advanced 2.0
def main():
    # Return ArmMotor to 0 degrees after raising
    arm_motor.spin_for(REVERSE, 180, DEGREES)
    wait(1, SECONDS)
    arm_motor.spin_to_position(0, DEGREES)

# Start threads — Do not delete
start_thread(main)

stop#

stop detiene el giro de un motor.

Usage:
arm_motor.stop()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Raise the ArmMotor
    arm_motor.spin(REVERSE)
    wait(1, SECONDS)
    arm_motor.stop()

# Start threads — Do not delete
start_thread(main)

Mutadores#

set_velocity#

set_velocity tells a motor how fast to spin. A higher percentage makes the motor spin faster and a lower percentage makes the motor spin slower.

Cada proyecto comienza con cada motor girando al 50% de su velocidad máxima por defecto.

Nota: Una mayor velocidad hace que el motor gire más rápido, pero puede ser menos preciso. Una menor velocidad hace que el motor gire más lento, pero puede ser más preciso.

Usage:
arm_motor.set_velocity(velocity)

Parámetros

Descripción

velocity

The velocity to spin with from 0% to 100%. This can be an integer or decimal (float).

# Build Used: Competition Advanced 2.0
def main():
    # Move the ArmMotor at different velocities
    arm_motor.spin_for(REVERSE, 180, DEGREES)
    wait(1, SECONDS)
    # Move slow
    arm_motor.set_velocity(20)
    arm_motor.spin_for(FORWARD, 180, DEGREES)
    wait(1, SECONDS)
    # Move fast
    arm_motor.set_velocity(100)
    arm_motor.spin_for(REVERSE, 180, DEGREES)

# Start threads — Do not delete
start_thread(main)

set_max_torque#

El par motor es una fuerza de giro. Indica la fuerza con la que un motor puede empujar o tirar al girar.

set_max_torque sets the most torque a motor is allowed to use.

Un porcentaje mayor permite que el motor empuje con más fuerza, como al levantar un objeto pesado. Un porcentaje menor limita la fuerza que puede ejercer el motor. Esto puede ayudar a proteger al robot si el motor se atasca o llega al límite de su recorrido.

Cada proyecto comienza con el par motor de cada motor al 50% por defecto.

Usage:
arm_motor.set_max_torque(value)

Parámetros

Descripción

value

The max torque the motor can use from 0% to 100%. This can be an integer or decimal (float).

# Build Used: Competition Advanced 2.0
def main():
    # Move the ArmMotor at different torques
    arm_motor.spin_for(REVERSE, 180, DEGREES)
    wait(1, SECONDS)
    # Move with less torque
    arm_motor.set_max_torque(20)
    arm_motor.spin_for(FORWARD, 180, DEGREES)
    wait(1, SECONDS)
    # Move with maximum torque
    arm_motor.set_max_torque(100)
    arm_motor.spin_for(REVERSE, 180, DEGREES)

# Start threads — Do not delete
start_thread(main)

set_position#

A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. set_position changes the motor’s current position to a new value.

Por ejemplo, si un motor ha girado 180 grados, al ajustar la posición a 0 grados, dicha posición volverá a su estado original. A partir de ahí, el motor podrá girar a posiciones que dependan de ese nuevo valor.

Usage:
arm_motor.set_position(position, units)

Parámetros

Descripción

position

The position value to set for the motor. DEGREES use integers. TURNS can use integers or decimals.

units

Optional. The position unit: DEGREES (default) or TURNS.

# Build Used: Competition Advanced 2.0
def main():
    # Return ArmMotor to 0 degrees after raising
    arm_motor.set_position(0, DEGREES)
    arm_motor.spin_for(REVERSE, 180, DEGREES)
    wait(1, SECONDS)
    arm_motor.spin_to_position(0, DEGREES)

# Start threads — Do not delete
start_thread(main)

set_stopping#

set_stopping sets how a motor will stop moving: by braking, coasting, or holding.

Usage:
arm_motor.set_stopping(mode)

Parámetros

Descripción

mode

How the motor will stop:

  • BRAKE — Stops immediately.
  • COAST — Slows to a stop.
  • HOLD — Stops immediately and holds the motor’s position.

For example, if a Competition Advanced 2.0 build is used and arm_motor is set to HOLD, the motor will hold the arm at its current position until another arm movement happens. This means the motor will work against gravity to keep the arm in the air if the motor was stopped with the arm raised.

If this method is not used, the motor will use BRAKE when stopping.

# Build Used: Competition Advanced 2.0
def main():
    # Move the ArmMotor, then coast to a stop
    arm_motor.set_velocity(20)
    arm_motor.set_stopping(COAST)
    arm_motor.spin(REVERSE)
    wait(1, SECONDS)
    arm_motor.stop()

# Start threads — Do not delete
start_thread(main)

set_timeout#

set_timeout sets how much time a motor will try to finish a movement. If the motor cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the motor from getting stuck on a movement.

Usage:
arm_motor.set_timeout(value, units)

Parámetros

Descripción

value

The amount of time the motor can try to finish a movement. This can be a positive integer or decimal (float).

units

Optional. The unit of time: SECONDS (default) or MSEC (milliseconds).

# Build Used: Competition Advanced 2.0
def main():
    # Move ArmMotor as far as possible for 1 second before resetting
    arm_motor.set_position(0, DEGREES)
    arm_motor.set_timeout(1, SECONDS)
    arm_motor.spin_for(REVERSE, 180, DEGREES)
    arm_motor.spin_to_position(0, DEGREES)

# Start threads — Do not delete
start_thread(main)

Captadores#

get_position#

A motor’s position is how far it has spun, measured in DEGREES or TURNS. One turn is equal to 360 degrees. get_position returns the motor’s current position.

Al inicio del proyecto, la posición del motor se establece en 0 grados. Si el motor gira una vuelta hacia adelante, la posición será de 360 ​​grados o 1 vuelta. Si el motor gira en la dirección opuesta, la posición será negativa.

Usage:
arm_motor.get_position(units)

Parámetros

Descripción

units

Optional. The unit to return the motor position in: DEGREES (default) or TURNS.

# Build Used: Competition Advanced 2.0
def main():
    # Display how far the ArmMotor moves after one second
    arm_motor.set_position(0, DEGREES)
    console.print("Start: ")
    console.print(arm_motor.get_position(DEGREES))
    console.new_line()
    arm_motor.spin(REVERSE)
    wait(1, SECONDS)
    arm_motor.stop()
    console.print("After: ")
    console.print(arm_motor.get_position(DEGREES))

# Start threads — Do not delete
start_thread(main)

get_velocity#

get_velocity returns how fast the motor is spinning, as a percentage from -100% to 100%.

Un valor positivo significa que el motor gira hacia adelante. Un valor negativo significa que el motor gira hacia atrás.

Usage:
arm_motor.get_velocity()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Display the ArmMotor's velocity when it moves
    console.print("Resting: ")
    console.print(arm_motor.get_velocity())
    console.new_line()
    arm_motor.spin(REVERSE)
    wait(1, SECONDS)
    console.print("Moving: ")
    console.print(arm_motor.get_velocity())
    arm_motor.stop()

# Start threads — Do not delete
start_thread(main)

get_current#

get_current returns how much power the motor is using from the battery, as a percentage from 0% to 100%.

Un valor de corriente más alto significa que el motor está consumiendo más energía. Esto puede ocurrir cuando el motor levanta algo pesado, empuja contra un objeto o intenta moverse cuando está atascado.

Usage:
arm_motor.get_current()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Display the motor's current when it moves
    console.print("Resting: ")
    console.print(arm_motor.get_current())
    console.new_line()
    arm_motor.spin(REVERSE)
    wait(1, SECONDS)
    console.print("Moving: ")
    console.print(arm_motor.get_current())
    arm_motor.stop()

# Start threads — Do not delete
start_thread(main)

is_stopped#

is_stopped returns whether the motor is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor is finished moving.

  • False — The motor is still moving.

This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.

Usage:
arm_motor.is_stopped()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Turn the Eye Sensor's light on while ArmMotor is moving
    arm_motor.spin_for(REVERSE, 180, DEGREES, wait=False)
    wait(0.1, SECONDS)
    while True:
        if arm_motor.is_stopped():
            eye.set_light(OFF)
        else:
            eye.set_light(ON)

# Start threads — Do not delete
start_thread(main)

is_moving#

is_moving returns whether the motor is spinning, as a Boolean value. This can be used to control the timing of other behaviors based on the motor’s movement.

  • True — The motor is spinning.

  • False — The motor is not spinning.

This method works together with the following Motion methods that have the wait parameter: spin_for and spin_to_position.

Usage:
arm_motor.is_moving()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Turn the Eye Sensor's light on while ArmMotor is moving
    arm_motor.spin_for(REVERSE, 180, DEGREES, wait=False)
    wait(0.1, SECONDS)
    while True:
        if arm_motor.is_moving():
            eye.set_light(ON)
        else:
            eye.set_light(OFF)

# Start threads — Do not delete
start_thread(main)