Movimiento#

Introducción#

El robot codificador VEX AIM cuenta con un sistema de propulsión holonómico que le permite moverse en cualquier dirección y rotar de forma independiente. El movimiento proporciona métodos de movimiento, giro, ajuste de velocidad y seguimiento de posición.

Esfera de brújula circular de 0 a 315 grados que rodea una pantalla gris oscuro con pantalla azul marino. La parte frontal del robot apunta a 0 grados en la esfera de brújula.

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

Acciones: Mover y girar el robot.

  • move_at – Moves the robot at a specified angle.

  • move_for – Moves the robot at an angle for a specific distance.

  • move_with_vectors – Moves the robot using vector-based x, y, and rotation values.

  • turn – Turns the robot left or right.

  • turn_for – Turns the robot a set number of degrees.

  • turn_to – Turns the robot to face a specific heading.

  • stop_all_movement – Stops all movement of the robot.

Mutadores: establecen velocidades de movimiento y giro predeterminadas.

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

Comportamiento#

move_at#

move_at moves the robot at a specified angle (from -360 to 360 degrees) and velocity (from 0 to 100 in PERCENT or 0 to 200 in MMPS).

Uso:

robot.move_at(angle, velocity, units)

Parámetros

Descripción

angle

El ángulo, como un número entero o flotante, en el que se mueve el robot, que varía entre -360 y 360 grados.

velocity

Opcional. La velocidad, como un número entero o de punto flotante, a la que se moverá el robot. Si no se especifica la velocidad, la predeterminada es del 50 %. El rango puede ser:

  • de 0 a 100 en PERCENT.
  • de 0 a 200 en MMPS.

units

Opcional. La unidad de velocidad es PERCENT (por defecto) o milímetros por segundo MMPS.

# 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#

move_for mueve el robot en un ángulo específico durante una distancia especificada.

Uso:

robot.move_for(distance, angle, velocity, units, wait)

Parámetros

Descripción

distance

La distancia, en número entero o flotante, que se moverá el robot, medida en milímetros (mm).

angle

El ángulo, como un número entero o flotante, en el que se mueve el robot, que varía entre -360 y 360 grados.

velocity

Opcional. La velocidad, como un número entero o de punto flotante, a la que se moverá el robot. Si no se especifica, la velocidad predeterminada es del 50 %.

units

Opcional. La unidad de velocidad es PERCENT (por defecto) o milímetros por segundo MMPS.

wait

Opcional.

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

# 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#

move_with_vectors moves the robot using vector-based motion, combining horizontal (X-axis) and vertical (Y-axis) movement and having the robot to rotate at the same time.

Uso:

robot.move_with_vectors(x, y, r)

Parámetros

Descripción

x

Velocidad del robot en el eje X (movimiento lateral). Acepta un valor de -100 a 100 como porcentaje, donde los valores negativos se desplazan a la izquierda y los positivos a la derecha.

y

Velocidad del robot en el eje Y (movimiento hacia adelante y hacia atrás). Acepta un valor de -100 a 100 como porcentaje, donde los valores negativos indican retroceso y los positivos avance.

r

Velocidad de rotación del robot. Acepta un valor de -100 a 100 como porcentaje, donde los valores negativos giran en sentido antihorario y los positivos 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()

turn#

turn gira el robot en una dirección específica.

Uso:

robot.turn(direction, velocity, units)

Parámetros

Descripción

direction

La dirección en la que gira el robot: LEFT o RIGHT.

velocity

Opcional. La velocidad, en forma de entero o punto flotante, a la que gira el robot. Si no se especifica, la velocidad predeterminada es del 50 %.

units

Opcional. grados por segundo PERCENT (predeterminado) o DPS.

# 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 gira el robot en una dirección específica por una distancia establecida en relación a su dirección de orientación actual.

Uso:

robot.turn_for(direction, angle, velocity, units, wait)

Parámetros

Descripción

direction

La dirección en la que gira el robot: LEFT o RIGHT.

angle

El ángulo, como un número entero o flotante, en el que se mueve el robot, que varía entre -360 y 360 grados.

velocity

Opcional. La velocidad a la que girará el robot. Si no se especifica, la velocidad predeterminada es el 50 % o cualquier velocidad.

units

Opcional. grados por segundo PERCENT (predeterminado) o DPS.

wait

Opcional.

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

# 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#

turn_to se utiliza para girar el robot para que mire hacia una dirección específica.

Uso:

robot.turn_to(heading, velocity, units, wait)

Parámetros

Descripción

heading

El rumbo que tomará el robot será de –360 a 360 grados.

velocity

Opcional. La velocidad, como un número entero o de punto flotante, a la que girará el robot. Si no se especifica, la velocidad predeterminada es del 50 %.

units

Opcional. grados por segundo PERCENT (predeterminado) o DPS.

wait

Opcional.

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

# 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 se utiliza para detener 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 anula la velocidad predeterminada para todos los métodos de movimiento posteriores del proyecto. La velocidad de movimiento predeterminada es del 50 % (100 milímetros por segundo).

Uso:

robot.set_move_velocity(velocity, units)

Parámetros

Descripción

velocity

Establece la velocidad de movimiento predeterminada.

units

Opcional. La unidad de velocidad es PERCENT (por defecto) o MMPS.

# 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#

set_turn_velocity anula la velocidad predeterminada para todos los métodos de giro subsiguientes del proyecto. La velocidad de giro predeterminada es del 50 % (75 grados por segundo).

Uso:

robot.set_turn_velocity(velocity, units)

Parámetros

Descripción

velocity

Establece la velocidad de giro predeterminada.

units

Opcional. grados por segundo PERCENT (predeterminado) o DPS.

# 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 establece la posición actual del robot según los valores especificados. Esto actualiza sus coordenadas internas.

Uso:

robot.set_xy_position(x, y)

Parámetros

Descripción

x

La nueva coordenada x en mm como un entero.

y

La nueva coordenada y en mm como un entero.

# 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 del robot como un entero en milímetros.

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 del robot como un entero en milímetros.

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 actualmente.

  • True – El robot se está moviendo.

  • False – El robot no se mueve.

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 actualmente.

  • True – El robot está girando.

  • False – El robot no está girando.

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 está detenido.

  • True – El robot está completamente detenido.

  • False – El robot está actualmente en movimiento 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()