Movimiento#

Introducción#

Los comandos GO Motion permiten que los motores giren, mantengan la posición y controlen la velocidad y el torque con precisión.

For the examples below, the configured motor will be named arm. They will be used in all subsequent examples throughout this API documentation when referring to Motor 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 in a specified direction indefinitely.

  • spin_for – Spins a motor for a specified distance.

  • spin_to_position – Spins a motor to an absolute position.

  • stop – Stops a motor.

Mutadores: cambian los diferentes atributos del motor.

  • set_velocity – Sets the default velocity for the motor.

  • set_max_torque – Sets the maximum torque for a motor.

  • set_position – Sets the motor’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.

Obtenedores: devuelven datos de los motores.

  • get_position – Returns a motor’s current position.

  • get_velocity – Returns a motor’s current velocity.

  • get_current – Returns the current being used by a motor.

  • is_stopped – Returns whether a motor is currently not spinning.

  • is_moving – Returns whether a motor is currently spinning.

Comportamiento#

spin#

spin hace girar el motor en una dirección específica indefinidamente.

Usage:
arm.spin(direction)

Parámetros

Descripción

direction

La dirección en la que debe girar el motor:

  • FORWARD
  • REVERSE

# Build Used: Competition Advanced 2.0
def main():
    # Spin motor in reverse, then stop
    arm.spin(REVERSE)
    wait(1, SECONDS)
    arm.stop()

# Start threads — Do not delete
start_thread(main)

spin_for#

spin_for hace girar el motor en una dirección específica para un ángulo específico.

Usage:
arm.spin_for(direction, angle, wait)

Parámetros

Descripción

direction

La dirección en la que debe girar el motor:

  • FORWARD
  • REVERSE

angle

La cantidad de grados que girará el motor como un flotante o un entero en grados.

wait

Opcional.

  • wait=True (predeterminado) – El proyecto espera hasta que spin_for se complete antes de ejecutar la siguiente línea de código.
  • wait=False - El proyecto inicia la acción y pasa a la siguiente línea de código de inmediato, sin esperar a que spin_for termine.

# Build Used: Competition Advanced 2.0
def main():
    # Spin motor in both directions
    arm.spin_for(REVERSE, 180)
    arm.spin_for(FORWARD, 180)

# Start threads — Do not delete
start_thread(main)

spin_to_position#

spin_to_position gira el motor a una posición absoluta.

Usage:
arm.spin_to_position(angle, wait)

Parámetros

Descripción

angle

La posición en la que debe girar el motor como un flotante o un número entero.

wait

Opcional.

  • wait=True (predeterminado) – El proyecto espera hasta que spin_to_position se complete antes de ejecutar la siguiente línea de código.
  • wait=False - El proyecto inicia la acción y pasa a la siguiente línea de código inmediatamente, sin esperar a que spin_to_position termine.

# Build Used: Competition Advanced 2.0
def main():
    # Put motor at 0 position after spinning
    arm.set_position(0)
    arm.spin(REVERSE)
    wait(1, SECONDS)
    arm.spin_to_position(0)

# Start threads — Do not delete
start_thread(main)

stop#

stop detiene el giro de un motor.

Usage:
arm.stop()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Spin motor in reverse, then stop
    arm.spin(REVERSE)
    wait(1, SECONDS)
    arm.stop()

# Start threads — Do not delete
start_thread(main)

Mutadores#

set_velocity#

set_velocity establece la velocidad predeterminada de un motor. Este ajuste de velocidad se utilizará en las llamadas posteriores a cualquier función de motor.

Usage:
arm.set_velocity(velocity)

Parámetros

Descripción

velocity

La velocidad a la que girará el motor expresada como porcentaje.

# Build Used: Competition Advanced 2.0
def main():
    # Spin motor at different velocities
    arm.spin_for(REVERSE, 180)
    wait(1, SECONDS)
    # Spin slower
    arm.set_velocity(20)
    arm.spin_for(FORWARD, 180)
    wait(1, SECONDS)
    # Spin faster
    arm.set_velocity(100)
    arm.spin_for(REVERSE, 180)

# Start threads — Do not delete
start_thread(main)

set_max_torque#

set_max_torque establece el torque máximo para un motor.

Usage:
arm.set_max_torque(value)

Parámetros

Descripción

value

El nuevo par máximo para un motor en forma de flotante o entero.

# Build Used: Competition Advanced 2.0
def main():
    # Spin the motor at different torques
    arm.spin_for(REVERSE, 180)
    wait(1, SECONDS)
    # Less torque
    arm.set_max_torque(20)
    arm.spin_for(FORWARD, 180)
    wait(1, SECONDS)
    # More torque
    arm.set_max_torque(100)
    arm.spin_for(REVERSE, 180)

# Start threads — Do not delete
start_thread(main)

set_position#

set_position establece la posición de un motor.

Usage:
arm.set_position(position)

Parámetros

Descripción

position

La nueva posición como un entero en grados.

# Build Used: Competition Advanced 2.0
def main():
    # Position the motor at the new 0 degrees
    arm.set_position(180)
    arm.spin_to_position(0)

# Start threads — Do not delete
start_thread(main)

set_stopping#

set_stopping establece el modo de parada de un motor.

Usage:
arm.set_stopping(mode)

Parámetros

Descripción

mode

Cómo se detendrá el motor:

  • BRAKE – Se detiene inmediatamente.
  • COAST – Disminuye la velocidad gradualmente hasta detenerse.
  • HOLD – Se detiene y resiste el movimiento usando la retroalimentación del motor.

# Build Used: Competition Advanced 2.0
def main():
    # Spin motor forward then coast to a stop
    arm.set_velocity(100)
    arm.set_stopping(COAST)
    arm.spin(REVERSE)
    wait(2, SECONDS)
    arm.stop()

# Start threads — Do not delete
start_thread(main)

set_timeout#

set_timeout establece un límite de tiempo que una función del motor esperará para alcanzar su objetivo. Si el motor no puede completar el movimiento dentro del tiempo establecido, se detendrá automáticamente y continuará con la siguiente función.

Nota: El límite de tiempo del motor 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:
arm.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

Opcional. Unidad que representa el tiempo:

  • SECONDS
  • MSEC (predeterminado) – Milisegundos

# Build Used: Competition Advanced 2.0
def main():
    # Spin the motor for one and a half seconds then reset
    arm.set_position(0)
    arm.set_timeout(1.5, SECONDS)
    arm.spin_for(REVERSE, 1000)
    arm.spin_to_position(0)

# Start threads — Do not delete
start_thread(main)

Captadores#

get_position#

get_position returns the current position of a motor as an integer or as a float in degrees.

Usage:
arm.get_position()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Spin motor while monitoring the position
    console.print("Start: ")
    console.print(arm.get_position())
    console.new_line
    arm.spin(REVERSE)
    wait(1, SECONDS)
    arm.stop()
    console.print("After: ")
    console.print(arm.get_position())

# Start threads — Do not delete
start_thread(main)

get_velocity#

get_velocity returns the current velocity of a motor as an integer or as a float in percent.

Usage:
arm.get_velocity()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Spin the motor and display the velocity
    console.print("Start: ")
    console.print(arm.get_velocity())
    console.new_line()
    arm.spin(REVERSE)
    wait(1, SECONDS)
    console.print("Moving: ")
    console.print(arm.get_velocity())
    arm.stop()

# Start threads — Do not delete
start_thread(main)

get_current#

get_current returns the current of the motor in amps.

Usage:
arm.get_current()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Spin the motor and display the current
    console.print("Start: ")
    console.print(arm.get_current())
    console.new_line()
    arm.spin(REVERSE)
    wait(1, SECONDS)
    console.print("Moving: ")
    console.print(arm.get_current())
    arm.stop()

# Start threads — Do not delete
start_thread(main)

is_stopped#

is_stopped devuelve un valor booleano que indica si el motor está detenido.

  • True – El motor está detenido.

  • False – El motor está girando.

Usage:
arm.is_stopped()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Turn the eye light on when moving
    arm.spin_for(REVERSE, 200, wait=False)
    wait(0.1, SECONDS)
    while True:
        if arm.is_stopped():
            eye.set_light(OFF)
        else:
            eye.set_light(ON)

# Start threads — Do not delete
start_thread(main)

is_moving#

is_moving devuelve un valor booleano que indica si el motor está girando.

  • True – El motor está girando.

  • False – El motor está detenido.

Usage:
arm.is_moving()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Competition Advanced 2.0
def main():
    # Turn the eye light on while moving
    arm.spin_for(FORWARD, 200, wait=False)
    wait(0.1, SECONDS)
    while True:
        if arm.is_moving():
            eye.set_light(ON)
        else:
            eye.set_light(OFF)

# Start threads — Do not delete
start_thread(main)