Movimiento#
Introducción#
El robot de codificación VEX AIM utiliza un sistema de propulsión holonómico para moverse hacia adelante, hacia atrás, a la izquierda, a la derecha o en ángulo, además de poder girar de forma independiente. Los métodos de movimiento controlan cómo se desplaza y gira el robot, su velocidad y el seguimiento de sus posiciones en los ejes x e y.

A continuación se muestra una lista de los métodos disponibles:
Acciones: Mover y girar el robot.
move_at— Mueve el robot en un ángulo específico indefinidamente.move_for— Mueve el robot en un ángulo específico durante una distancia específica.move_with_vectors— Mueve el robot usando valores x, y y de rotación basados en vectores.turn— Gira el robot a la izquierda o a la derecha indefinidamente.turn_for— Gira el robot hacia la izquierda o hacia la derecha un número específico de grados.turn_to— Gira el robot para que mire hacia una dirección específica.stop_all_movement— Detiene todo movimiento del robot.
Mutadores: Establece los valores de movimiento del robot.
set_move_velocity— Indica al robot a qué velocidad debe moverse.set_turn_velocity— Indica al robot a qué velocidad debe girar.set_xy_position— Cambia la posición x e y actual del robot a nuevos valores.
Funciones de obtención: devuelven el estado y la posición del robot.
get_x_position— Devuelve la coordenada x actual del robot.get_y_position— Devuelve la coordenada y actual del robot.is_move_active— Devuelve si el robot se está moviendo.is_turn_active— Devuelve si el robot está girando.is_stopped— Devuelve si el robot no se está moviendo ni girando.
Comportamiento#
move_at#
move_at mueve el robot indefinidamente en un ángulo específico. El ángulo es relativo a la posición actual del robot. El robot continuará moviéndose hasta que se le indique otra acción, como moverse en un ángulo diferente, girar o detenerse.
Uso:
robot.move_at(angle, velocity, units)
Parámetros |
Descripción |
|---|---|
|
El ángulo, en grados, que describe el movimiento del robot. Puede ser un número entero o decimal entre -360 y 360. |
|
Opcional. La velocidad de movimiento varía entre 0 % y 100 % al usar |
|
Opcional. La unidad de velocidad: |
# Move right, then move forward and stop.
robot.move_at(90)
wait(1,SECONDS)
robot.move_at(0)
wait(1,SECONDS)
robot.stop_all_movement()
# Move right slowly, move in reverse quickly and stop.
robot.move_at(90, 25)
wait(2, SECONDS)
robot.move_at(180, 100, PERCENT)
wait(1, SECONDS)
robot.stop_all_movement()
# Move diagonally to the right and stop.
robot.move_at(45.33)
wait(1,SECONDS)
robot.stop_all_movement()
move_for#
La instrucción move_for mueve el robot en un ángulo específico y a una distancia determinada. El ángulo es relativo a la posición actual del robot. El programa esperará a que el robot termine de moverse antes de ejecutar la siguiente línea de código.
Uso:
robot.move_for(distance, angle, velocity, units, wait)
Parámetros |
Descripción |
|---|---|
|
La distancia que recorre el robot, en milímetros (mm). Puede ser un número entero o decimal (flotante). |
|
El ángulo, en grados, que describe el movimiento del robot. Puede ser un número entero o decimal entre -360 y 360. |
|
Opcional. La velocidad de movimiento varía entre 0 % y 100 % al usar |
|
Opcional. La unidad de velocidad: |
|
Opcional. |
# Move right, then move forward.
robot.move_for(50, 90)
robot.move_for(100, 0)
# Move in reverse slowly, then move forward quickly.
robot.move_for(100, 180, 25)
robot.move_for(100, 0, 100, PERCENT)
# Drive forward and blink all LEDs red.
robot.move_for(100, 0, wait=False)
robot.led.on(ALL_LEDS, RED)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, BLACK)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, RED)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, BLACK)
move_with_vectors#
Un vector es una forma de describir la velocidad y la dirección del movimiento. El robot se mueve move_with_vectors que reciba otra acción, como cambiar de ángulo, girar o detenerse.
Nota: Este método establece directamente los valores de velocidad de movimiento y giro, por lo que no utiliza set_move_velocity ni set_turn_velocity.
Uso:
robot.move_with_vectors(forward, rightward, rotation)
Parámetros |
Descripción |
|---|---|
|
La velocidad del robot a lo largo del eje Y, desde -100% hasta 100%. Los valores negativos hacen que el robot retroceda y los valores positivos lo hacen avanzar. |
|
La velocidad del robot a lo largo del eje x, desde -100% hasta 100%. Los valores negativos mueven al robot hacia la izquierda y los valores positivos hacia la derecha. |
|
La velocidad de giro del robot, de -100% a 100%. Los valores negativos hacen que el robot gire en sentido antihorario y los valores positivos lo hacen girar en sentido horario. |
# Move at 15°
robot.move_with_vectors(48.3, 12.95, 0)
wait(2, SECONDS)
robot.stop_all_movement()
# Move at 45° while turning counterclockwise.
robot.move_with_vectors(50, 50, -30)
wait(2, SECONDS)
robot.stop_all_movement()
# Scaling movement using the controller joystick
while True:
# Move forward (and backwards) slower than axis1 input
forward = controller.axis1.position() * 0.7
# Move right (and left) faster than axis2 input
rightward = controller.axis2.position() * 1.5
robot.move_with_vectors(forward, rightward, 0)
wait(5, MSEC)
turn#
turn hace que el robot gire hacia la izquierda o hacia la derecha indefinidamente. El robot seguirá girando hasta que se le dé otra acción, como moverse o detenerse.
Uso:
robot.turn(direction, velocity, units)
Parámetros |
Descripción |
|---|---|
|
La dirección en la que gira el robot: |
|
Opcional. La velocidad de giro varía entre 0 % y 100 % al usar |
|
Opcional. La unidad de velocidad: |
# Turn left, then stop.
robot.turn(LEFT)
wait(1, SECONDS)
robot.stop_all_movement()
# Turn left quickly, turn right slowly, then stop.
robot.turn(LEFT, 80)
wait(2, SECONDS)
robot.turn(RIGHT, 20, PERCENT)
wait(3, SECONDS)
robot.stop_all_movement()
turn_for#
turn_for hace girar el robot hacia la izquierda o hacia la derecha un número específico de grados. El giro es relativo a la dirección actual en la que apunta el robot. El programa esperará a que el robot termine de girar antes de ejecutar la siguiente línea de código.
Uso:
robot.turn_for(direction, angle, velocity, units, wait)
Parámetros |
Descripción |
|---|---|
|
La dirección en la que gira el robot: |
|
El número de grados que gira el robot, que oscila entre -360 y 360 grados. Puede ser un número entero o decimal (de coma flotante). |
|
Opcional. La velocidad de giro varía entre 0 % y 100 % al usar |
|
Opcional. La unidad de velocidad: |
|
Opcional. |
# Turn left, then turn around to the right.
robot.turn_for(LEFT, 90)
robot.turn_for(RIGHT, 180)
# Turn left quickly, then turn right slowly.
robot.turn_for(LEFT, 90, 100)
robot.turn_for(RIGHT, 180, 15, PERCENT)
# Turn right and blink all LEDs blue.
robot.turn_for(RIGHT, 180, wait=False)
robot.led.on(ALL_LEDS, BLUE)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, BLUE)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
turn_to#
El rumbo indica la dirección hacia la que apunta el robot, medida en grados. El comando turn_to gira el robot para que apunte hacia un rumbo específico. El robot girará en la dirección más corta para alcanzar el rumbo deseado.
La dirección inicial del robot es de 0 grados.
El proyecto esperará a que el robot termine de girar antes de ejecutar la siguiente línea de código.
Uso:
robot.turn_to(heading, velocity, units, wait)
Parámetros |
Descripción |
|---|---|
|
La dirección hacia la que debe apuntar el robot, desde -360 hasta 360 grados. |
|
Opcional. La velocidad de giro varía entre 0 % y 100 % al usar |
|
Opcional. La unidad de velocidad: |
|
Opcional. |
# Turn to face each cardinal directions.
robot.turn_to(90)
wait(2, SECONDS)
robot.turn_to(180)
wait(2, SECONDS)
robot.turn_to(270)
wait(2, SECONDS)
robot.turn_to(0)
# Turn to face backward slowly, then face forward quickly.
robot.turn_to(180, 25)
wait(1, SECONDS)
robot.turn_to(0, 90, PERCENT)
# Turn around quickly and blink all LEDs green.
robot.turn_to(180, 100, wait=False)
robot.led.on(ALL_LEDS, GREEN)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, GREEN)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
stop_all_movement#
stop_all_movement detiene todo movimiento del robot.
Uso:
robot.stop_all_movement()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Turn right, then stop moving
robot.turn(RIGHT)
wait(1, SECONDS)
robot.stop_all_movement()
Mutadores#
set_move_velocity#
set_move_velocity tells the robot how fast to move. A higher percentage makes the robot move faster and a lower percentage makes the robot move slower.
Todos los proyectos comienzan con el robot moviéndose al 50% de su velocidad por defecto.
Una velocidad de movimiento del 100% equivale a 200 milímetros por segundo.
Uso:
robot.set_move_velocity(velocity, units)
Parámetros |
Descripción |
|---|---|
|
La velocidad de movimiento varía entre 0% y 100% al usar |
|
Opcional. La unidad de velocidad: |
# Move forward at the default velocity,
robot.set_move_velocity(50)
robot.move_for(100, 0)
wait(1, SECONDS)
# Move slower than the default velocity
robot.set_move_velocity(20)
robot.move_for(100, 0)
wait(1, SECONDS)
# Move faster than the default velocity
robot.set_move_velocity(100)
robot.move_for(100, 0)
set_turn_velocity#
El valor set_turn_velocity indica al robot la velocidad de giro. Un porcentaje mayor hace que el robot gire más rápido y un porcentaje menor hace que gire más lento.
Por defecto, cada proyecto comienza con el robot girando al 50 % de su velocidad (75 grados por segundo).
Uso:
robot.set_turn_velocity(velocity, units)
Parámetros |
Descripción |
|---|---|
|
La velocidad de giro varía entre 0% y 100% al usar |
|
Opcional. La unidad de velocidad: |
# Turn around at default velocity
robot.set_turn_velocity(50)
robot.turn_for(RIGHT, 180)
wait(1, SECONDS)
# Turn around slower than the default velocity
robot.set_turn_velocity(20)
robot.turn_for(RIGHT, 180)
wait(1, SECONDS)
# Turn around faster than the default velocity
robot.set_turn_velocity(100)
robot.turn_for(RIGHT, 180)
set_xy_position#
set_xy_position cambia la posición x e y actual del robot a nuevos valores.
Por ejemplo, si el robot se ha alejado de su punto de partida, al establecer x en 0 e y en 0, la ubicación actual del robot se convierte en la nueva posición (0, 0). A partir de ese nuevo valor, el robot puede rastrear posiciones futuras.
Uso:
robot.set_xy_position(x, y)
Parámetros |
Descripción |
|---|---|
|
El valor de la posición x que se establecerá para el robot, en mm. Puede ser un número entero o decimal (flotante). |
|
El valor de la posición Y que se debe establecer para el robot, en mm. Puede ser un número entero o decimal (flotante). |
# Set the robot's current position
# Move forward and print the new coordinate
robot.set_xy_position(100, 50)
robot.move_for(150, 0)
robot.screen.print("X:", robot.get_x_position())
robot.screen.next_row()
robot.screen.print("Y:", robot.get_y_position())
Captadores#
get_x_position#
get_x_position devuelve la coordenada x actual del robot en milímetros.
Al inicio de un proyecto, la posición x del robot se establece en 0. La posición x cambia a medida que el robot se mueve hacia la izquierda o hacia la derecha y se puede establecer utilizando el método set_xy_position.
Uso:
robot.get_x_position()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Print the start and end x-value
# of the robot's position after moving
robot.screen.print("Start X:", robot.get_x_position())
robot.move_for(200, 90)
robot.screen.next_row()
robot.screen.print("End X:", robot.get_x_position())
get_y_position#
get_y_position devuelve la coordenada y actual del robot en milímetros.
Al inicio de un proyecto, la posición y del robot se establece en 0. La posición y cambia a medida que el robot se mueve hacia adelante o hacia atrás y se puede establecer utilizando el método set_xy_position.
Uso:
robot.get_y_position()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Print the start and end y-value
# of the robot's position after moving
robot.screen.print("Start Y:", robot.get_y_position())
robot.move_for(200, 0)
robot.screen.next_row()
robot.screen.print("End Y:", robot.get_y_position())
is_move_active#
is_move_active devuelve un valor booleano que indica si el robot se está moviendo. Esto se puede usar para controlar la sincronización de otros comportamientos en función del movimiento del robot.
True— El robot se está moviendo.False— El robot no se está moviendo.
Este método funciona junto con los métodos Motion que tienen el parámetro wait , como move_for.
Uso:
robot.is_move_active()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Blink all the LEDs when the robot is moving.
robot.move_for(200, 0, wait=False)
while robot.is_move_active():
robot.led.on(ALL_LEDS, ORANGE)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, CYAN)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
is_turn_active#
is_turn_active devuelve un valor booleano que indica si el robot está girando. Esto se puede usar para controlar la sincronización de otros comportamientos en función del movimiento del robot.
True— El robot está girando.False— El robot no está girando.
Este método funciona junto con los métodos Motion que tienen el parámetro wait , como turn_for y turn_to.
Uso:
robot.is_turn_active()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Blink all the LEDs while the robot is turning
robot.turn_for(RIGHT, 180, wait=False)
while robot.is_turn_active():
robot.led.on(ALL_LEDS, GREEN)
wait(0.5, SECONDS)
robot.led.on(ALL_LEDS, CYAN)
wait(0.5, SECONDS)
robot.led.off(ALL_LEDS)
is_stopped#
is_stopped devuelve un valor booleano que indica si el robot no se mueve ni gira. Esto permite controlar la sincronización de otras acciones en función del movimiento del robot.
True— El robot no se mueve ni gira.False— El robot se está moviendo o girando.
Uso:
robot.is_stopped()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Blink all the LEDs while the robot is moving or turning
def light_show():
# Flash LEDs while the robot is moving or turning
while not robot.is_stopped():
robot.led.on(ALL_LEDS, GREEN)
wait(.5, SECONDS)
robot.led.on(ALL_LEDS, PURPLE)
wait(.5, SECONDS)
robot.led.off(ALL_LEDS)
robot.move_for(200, 0, wait=False)
light_show()
robot.turn_for(RIGHT, 180, wait=False)
light_show()