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. This name is 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:
Actions — Control the movement of motors.
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.
Mutators — Change the motor’s different attributes.
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.
Getters — Return data from motors.
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 |
|---|---|
|
La dirección en la que debe girar el motor:
|
# 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 |
|---|---|
|
La dirección en la que debe girar el motor:
|
|
The number of degrees the motor will spin as a float or integer. |
|
Optional.
|
# 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 |
|---|---|
|
La posición en la que debe girar el motor como un flotante o un número entero. |
|
Optional.
|
# 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 |
|---|---|
|
The velocity at which the motor will spin as a percent. |
# 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 |
|---|---|
|
The new maximum torque for the motor as a float or integer in percent. |
# 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 |
|---|---|
|
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 |
|---|---|
|
How the motor will stop:
|
# Build Used: Competition Advanced 2.0
def main():
# Spin motor in reverse 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.
Note: The motor’s time limit prevents motor functions that do not reach their target position from blocking the execution of the rest of the project.
Usage:
arm.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:
|
# 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 the motor as an integer or 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 the motor as an integer or 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 returns a Boolean indicating whether or not the motor is stopped.
True— The motor is stopped.False— The motor is spinning.
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 returns a Boolean indicating whether or not the motor is stopped.
True— The motor is spinning.False— The motor is stopped.
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)