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

Optional. The velocity as an integer or float number at which the robot will move. If the velocity is not specified, the default velocity is 50%. The range can be:

  • from 0 to 100 in PERCENT.
  • from 0 to 200 in MMPS.

units

Optional. The velocity unit is PERCENT (default) or millimeters per second 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 moves the robot at a specific angle for a specified distance.

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

Optional. The velocity unit is PERCENT (default) or millimeters per second MMPS.

wait

Optional.

  • wait=True (default) - The robot waits until move_for is complete before executing the next line of code.
  • wait=False - The robot starts the action and moves on to the next line of code right away, without waiting for move_for to finish.

# 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 rotate at the same time.

Uso:

robot.move_with_vectors(forward, rightward, rotation)

Parámetros

Descripción

forward

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.

rightward

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.

rotation

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 turns the robot in a specific direction.

Uso:

robot.turn(direction, velocity, units)

Parámetros

Descripción

direction

The direction in which the robot turns: LEFT or 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

Optional. Degrees per second DPS (default) or PERCENT.

# 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 turns the robot in a specified direction for a specified angle relative to its current facing direction.

Uso:

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

Parámetros

Descripción

direction

The direction in which the robot turns: LEFT or 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 del 50 %.

units

Optional. degrees per second PERCENT (default) or DPS.

wait

Optional.

  • wait=True (default) - The robot waits until turn_for is complete before executing the next line of code.
  • wait=False - The robot starts the action and moves to the next command without waiting for turn_for to finish.

# 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 is used to turn the robot to face a specific heading.

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

Optional. Degrees per second PERCENT (default) or DPS.

wait

Optional.

  • wait=True (default) - The robot waits until turn_to is complete before executing the next line of code.
  • wait=False - The robot starts the action and moves on to the next line of code right away, without waiting for turn_to to finish.

# 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 is used to stop all movement of the 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 overrides the default velocity for all subsequent movement methods in the project. The default move velocity is 50% (100 millimeters per second).

Uso:

robot.set_move_velocity(velocity, units)

Parámetros

Descripción

velocity

Establece la velocidad de movimiento predeterminada.

units

Optional. The velocity unit is PERCENT (default) or 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 overrides the default velocity for all subsequent turn methods in the project. The default turn velocity is 50% (75 degrees per second).

Uso:

robot.set_turn_velocity(velocity, units)

Parámetros

Descripción

velocity

Establece la velocidad de giro predeterminada.

units

Optional. degrees per second PERCENT (default) or 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 sets the robot’s current position to specified values. This updates the robot’s internal coordinates.

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 returns the robot’s x-coordinate as an integer in millimeters.

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 returns the robot’s y-coordinate as an integer in millimeters.

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 returns a Boolean indicating whether the robot is currently moving.

  • True – The robot is moving.

  • False – The robot is not moving.

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 returns a Boolean indicating whether the robot is currently turning.

  • True – The robot is turning.

  • False – The robot is not turning.

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 returns a Boolean indicating whether the robot is stopped.

  • True – The robot is completely stopped.

  • False – The robot is currently moving or turning.

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()