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.
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.
set_move_velocity – Sets the default movement speed.
set_turn_velocity – Sets the default turn speed.
set_xy_position – Sets the robot’s current position.
Getters – Devuelven el estado y la posición del robot.
get_x_position – Returns the robot’s x-coordinate.
get_y_position – Returns the robot’s y-coordinate.
is_move_active – Returns whether the robot is currently moving.
is_turn_active – Returns whether the robot is currently turning.
is_stopped – Returns whether the robot is stopped.
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 |
---|---|
|
El ángulo, como un número entero o flotante, en el que se mueve el robot, que varía entre -360 y 360 grados. |
|
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:
|
|
Opcional. La unidad de velocidad es |
# 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 |
---|---|
|
La distancia, en número entero o flotante, que se moverá el robot, medida en milímetros (mm). |
|
El ángulo, como un número entero o flotante, en el que se mueve el robot, que varía entre -360 y 360 grados. |
|
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 %. |
|
Opcional. La unidad de velocidad es |
|
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#
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 |
---|---|
|
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. |
|
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. |
|
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 |
---|---|
|
La dirección en la que gira el robot: |
|
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 %. |
|
Opcional. grados por segundo |
# 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 |
---|---|
|
La dirección en la que gira el robot: |
|
El ángulo, como un número entero o flotante, en el que se mueve el robot, que varía entre -360 y 360 grados. |
|
Opcional. La velocidad a la que girará el robot. Si no se especifica, la velocidad predeterminada es el 50 % o cualquier velocidad. |
|
Opcional. grados por segundo |
|
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#
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 |
---|---|
|
El rumbo que tomará el robot será de –360 a 360 grados. |
|
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 %. |
|
Opcional. grados por segundo |
|
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
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 |
---|---|
|
Establece la velocidad de movimiento predeterminada. |
|
Opcional. La unidad de velocidad es |
# 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 |
---|---|
|
Establece la velocidad de giro predeterminada. |
|
Opcional. grados por segundo |
# 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 |
---|---|
|
La nueva coordenada x en mm como un entero. |
|
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()