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.

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 la 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 specific angle forever.

  • move_for — Moves the robot at a specific 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 forever.

  • turn_for — Turns the robot left or right for a specific number of degrees.

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

  • stop_all_movement — Stops all movement of the robot.

Mutadores: Establece los valores de movimiento del robot.

Funciones de obtención: devuelven el estado y la posición del robot.

Comportamiento#

move_at#

move_at moves the robot forever at a specific angle. The angle is relative to the current position of the robot. The robot will continue to move until it is given another action, like moving at a different angle, turning, or stopping.

Uso:

robot.move_at(angle, velocity, units)

Parámetros

Descripción

angle

El ángulo, en grados, que describe el movimiento del robot. Puede ser un número entero o decimal entre -360 y 360.

velocity

Optional. The velocity to move with from 0% to 100% when using PERCENT, or from 0 to 200 millimeters per second when using MMPS. This can be an integer or decimal (float). If no velocity is provided, the robot moves at the current move velocity.

units

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

# 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 specific distance. The angle is relative to the current position of the robot. The project will wait until the robot is done moving before the next line of code runs.

Uso:

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

Parámetros

Descripción

distance

La distancia que recorre el robot, en milímetros (mm). Puede ser un número entero o decimal (flotante).

angle

El ángulo, en grados, que describe el movimiento del robot. Puede ser un número entero o decimal entre -360 y 360.

velocity

Optional. The velocity to move with from 0% to 100% when using PERCENT, or from 0 to 200 millimeters per second when using MMPS. This can be an integer or decimal (float). If no velocity is provided, the robot moves at the current move velocity.

units

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

wait

Optional. wait=True (default) makes the project wait until the robot is done moving before the next line of code runs. wait=False makes the next line of code run right away.

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

A vector is a way to describe how fast something moves, and what direction it moves in. move_with_vectors moves the robot using vector-based motion. The robot combines forward, rightward, and rotation velocity values to create on smooth movement. The robot will continue to move using this vector until it is given another action, like moving at a different angle, turning, or stopping.

Note: This method sets movement and turn velocity values directly, so it does not use set_move_velocity or set_turn_velocity.

Uso:

robot.move_with_vectors(forward, rightward, rotation)

Parámetros

Descripción

forward

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.

rightward

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.

rotation

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 turns the robot left or right forever. The robot will continue to turn until it is given another action, like moving or stopping.

Uso:

robot.turn(direction, velocity, units)

Parámetros

Descripción

direction

The direction the robot turns: LEFT or RIGHT.

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, or from 0 to 150 degrees per second when using DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units

Optional. The velocity unit: DPS (degrees per second, 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 left or right for a specific number of degrees. The turn is relative to the current direction the robot is facing. The project will wait until the robot is done turning before the next line of code runs.

Uso:

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

Parámetros

Descripción

direction

The direction the robot turns: LEFT or RIGHT.

angle

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

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, or from 0 to 150 degrees per second when using DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units

Optional. The velocity unit: DPS (degrees per second, default) or PERCENT.

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

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

A heading is the direction the robot is facing, measured in degrees. turn_to turns the robot to face a specific heading. The robot will turn the shortest direction to reach the target heading.

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

heading

La dirección hacia la que debe apuntar el robot, desde -360 hasta 360 grados.

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, or from 0 to 150 degrees per second when using DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units

Optional. The velocity unit: DPS (degrees per second, default) or PERCENT.

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

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

velocity

The velocity to move with from 0% to 100% when using PERCENT, or from 0 to 200 millimeters per second when using MMPS. This can be an integer or decimal (float).

units

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

# 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 tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.

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

velocity

The velocity to turn with from 0% to 100% when using PERCENT, or from 0 to 150 degrees per second when using DPS. This can be an integer or decimal (float).

units

Optional. The velocity unit: DPS (degrees per second, default) or PERCENT.

# 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 changes the robot’s current x and y position to new values.

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

x

El valor de la posición x que se establecerá para el robot, en mm. Puede ser un número entero o decimal (flotante).

y

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

At the beginning of a project, the robot’s x-position is set to 0. The x-position changes as the robot moves left or right and can be set using the set_xy_position method.

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 current y-coordinate in millimeters.

At the beginning of a project, the robot’s y-position is set to 0. The y-position changes as the robot moves forward or reverse and can be set using the set_xy_position method.

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 whether the robot is moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is moving.

  • False — The robot is not moving.

This method works together with Motion methods that have the wait parameter, such as 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 returns whether the robot is turning, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is turning.

  • False — The robot is not turning.

This method works together with Motion methods that have the wait parameter, such as turn_for and 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 returns whether the robot is neither moving nor turning, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is not moving or turning.

  • False — The robot is 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()