Macro#
Introducción#
Las macros de Python de VEX AIM son bloques de código predefinidos que se pueden arrastrar a un proyecto de Python. Cada macro es un grupo de comandos de Python que trabajan juntos para que el robot realice una acción más compleja.
No se trata de métodos individuales que se llaman desde el código. En cambio, cada macro se inserta como una secuencia de código predefinida que se puede usar tal cual o editar después de agregarla a un proyecto.
En esta página, cada bloque de código Python muestra la secuencia de código real que se inserta cuando se utiliza esa macro.
A continuación se muestra una lista de todas las macros:
Emociones: Haz que el robot actúe de forma expresiva.
act happy— Makes the robot act happy.act sad— Makes the robot act sad.act silly— Makes the robot act silly.act angry— Makes the robot act angry.act excited— Makes the robot act excited.
Visión por IA (Balón deportivo): Gira hacia los balones deportivos o recógelos.
turn right until sports ball— Turns right until a sports ball is detected.turn left until sports ball— Turns left until a sports ball is detected.get sports ball— Moves the robot to collect a sports ball.
Visión por IA (Barril Naranja): Gira hacia los barriles naranjas o recógelos.
turn right until orange barrel— Turns right until an orange barrel is detected.turn left until orange barrel— Turns left until an orange barrel is detected.get orange barrel— Moves the robot to collect an orange barrel.
Visión con IA (Barril Azul): Gira hacia los barriles azules o recógelos.
turn right until blue barrel— Turns right until a blue barrel is detected.turn left until blue barrel— Turns left until a blue barrel is detected.get blue barrel— Moves the robot to collect a blue barrel.
Visión por IA (Robot AIM): Gira o muévete hacia otros robots AIM.
turn right until AIM robot— Turns right until another AIM Robot is detected.turn left until AIM robot— Turns left until another AIM Robot is detected.move to AIM robot— Moves toward another AIM Robot.
Visión por IA (AprilTag): Gire o muévase hacia las etiquetas AprilTag.
turn right until AprilTag— Turns right until an an AprilTag is detected.turn left until AprilTag— Turns left until an an AprilTag is detected.move to AprilTag— Moves toward an AprilTag.
Emociones#
act happy#
Esta macro hace que el robot actúe con alegría mostrando caras felices, reproduciendo un sonido alegre, cambiando los LED y moviéndose de un lado a otro. Úsala cuando el robot deba responder de forma alegre o positiva.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# act happy
robot.screen.show_emoji(HAPPY)
wait(.5,SECONDS)
robot.sound.play(ACT_HAPPY)
wait(115, MSEC)
robot.screen.show_emoji(HAPPY, LOOK_RIGHT)
robot.led.on(ALL_LEDS, YELLOW)
robot.turn_for(RIGHT, 4, 100)
robot.led.on(ALL_LEDS, WHITE)
robot.screen.show_emoji(HAPPY, LOOK_LEFT)
robot.turn_for(RIGHT, -8, 100)
robot.led.on(ALL_LEDS, YELLOW)
robot.screen.show_emoji(HAPPY, LOOK_RIGHT)
robot.turn_for(RIGHT, 4, 100)
wait(100,MSEC)
for i in range(3):
robot.screen.show_emoji(QUIET)
robot.led.on(ALL_LEDS, WHITE)
robot.move_for(1,-90)
robot.screen.show_emoji(HAPPY)
robot.led.on(ALL_LEDS, YELLOW)
robot.move_for(1,90)
robot.stop_all_movement()
robot.led.off(ALL_LEDS)
wait(.5,SECONDS)
act sad#
Esta macro hace que el robot actúe triste mostrando caras tristes, reproduciendo un sonido triste, atenuando los LED y moviéndose lentamente en diferentes direcciones. Úsala cuando el robot deba mostrar una reacción de decepción o desánimo.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# act sad
robot.screen.show_emoji(SAD)
wait(.5,SECONDS)
robot.sound.play(ACT_SAD)
wait(115, MSEC)
robot.led.on(ALL_LEDS, Color(0, 0, 250))
robot.screen.show_emoji(SAD, LOOK_RIGHT)
robot.move_for(11, 135, 70)
robot.led.on(ALL_LEDS, Color(0, 0, 100))
robot.screen.show_emoji(SAD, LOOK_FORWARD)
robot.move_for(11, 315, 70)
robot.led.on(ALL_LEDS, Color(0, 0, 50))
robot.screen.show_emoji(SAD, LOOK_LEFT)
robot.move_for(11, 225, 70)
robot.led.on(ALL_LEDS, Color(0, 0, 10))
robot.screen.show_emoji(SAD, LOOK_FORWARD)
robot.move_for(11, 45, 70)
wait(.5,SECONDS)
robot.led.off(ALL_LEDS)
act silly#
Esta macro hace que el robot actúe de forma graciosa: gira, cambia de cara y parpadea con diferentes colores de LED. Úsala cuando el robot deba tener una reacción divertida o sorprendente.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# act silly
robot.screen.show_emoji(SILLY)
wait(.5,SECONDS)
robot.sound.play(ACT_SILLY)
wait(115,MSEC)
robot.turn_for(RIGHT, 360, 100, wait=False)
face_list = [SILLY, HAPPY, EXCITED, PROUD, THRILLED, LAUGHING]
colors = [BLUE, CYAN, GREEN, ORANGE, PURPLE, RED, WHITE, YELLOW]
while robot.is_turn_active():
robot.screen.show_emoji(SILLY)
robot.led.on(ALL_LEDS, random.choice(colors))
wait(110,MSEC)
robot.screen.show_emoji(random.choice(face_list))
wait(110,MSEC)
robot.screen.show_emoji(SILLY)
robot.led.off(ALL_LEDS)
wait(.5,SECONDS)
act angry#
Esta macro hace que el robot actúe con enfado: muestra caras de enfado, emite un sonido de enfado, enciende los LED en rojo y se mueve bruscamente. Úsala cuando el robot deba mostrar una reacción de frustración o advertencia.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# act angry
robot.screen.show_emoji(ANGRY)
wait(.5,SECONDS)
robot.sound.play(ACT_ANGRY)
wait(115,MSEC)
robot.led.on(ALL_LEDS, RED)
robot.move_for(25, 0, 50)
wait(50,MSEC)
for i in range(5):
robot.screen.show_emoji(ANNOYED)
robot.move_for(5, 180, 50)
robot.screen.show_emoji(ANGRY)
wait(50,MSEC)
wait(.5,SECONDS)
robot.led.off(ALL_LEDS)
act excited#
Esta macro hace que el robot actúe emocionado mostrando una cara de alegría, emitiendo un sonido de emoción, moviéndose rápidamente de un lado a otro y haciendo parpadear LEDs naranjas. Úsala cuando el robot deba celebrar o reaccionar con mucha energía.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# act excited
robot.screen.show_emoji(EXCITED)
wait(.5,SECONDS)
robot.sound.play(ACT_EXCITED)
wait(115, MSEC)
for angle in [3,-3,2,-2,2,-2,2,-2,1,-1]:
if angle > 0:
robot.screen.show_emoji(EXCITED, LOOK_RIGHT)
robot.led.on(LED4, ORANGE)
robot.led.on(LED5, ORANGE)
robot.led.on(LED6, ORANGE)
robot.led.off(LED1)
else:
robot.screen.show_emoji(EXCITED, LOOK_LEFT)
robot.led.on(LED1, ORANGE)
robot.led.on(LED2, ORANGE)
robot.led.on(LED3, ORANGE)
robot.led.off(LED6)
robot.turn_for(RIGHT, angle)
robot.led.off(ALL_LEDS)
robot.screen.show_emoji(EXCITED, LOOK_FORWARD)
wait(.5,SECONDS)
Visión de IA (Balón deportivo)#
turn right until sports ball#
Esta macro hace girar el robot hacia la derecha hasta que el sensor de visión con IA detecta una pelota deportiva; entonces, gira hacia el objeto detectado. Úsela cuando el robot necesite buscar una pelota deportiva antes de acercarse a ella o recogerla.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn right until sports ball is detected
robot.turn(RIGHT)
while True:
vision_data = robot.vision.get_data(SPORTS_BALL)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
turn left until sports ball#
Esta macro hace girar el robot hacia la izquierda hasta que el sensor de visión con IA detecta una pelota deportiva; entonces, gira hacia el objeto detectado. Úsela cuando el robot necesite buscar una pelota deportiva antes de acercarse a ella o recogerla.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn left until sports ball is detected
robot.turn(LEFT)
while True:
vision_data = robot.vision.get_data(SPORTS_BALL)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
get sports ball#
Esta macro mueve al robot hacia una pelota deportiva detectada hasta que la recoge. Úsala después de que el robot vea una pelota deportiva o después de usar una macro de giro hasta encontrar una.
Note: If the robot has difficulty detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Get sports ball
while True:
vision_data = robot.vision.get_data(SPORTS_BALL)
if vision_data[0].exists:
if robot.has_sports_ball():
robot.stop_all_movement()
break
else:
robot.move_at(vision_data[0].bearing)
else:
robot.move_at(0)
wait(20, MSEC)
Visión de IA (Barril naranja)#
turn right until orange barrel#
Esta macro hace girar el robot hacia la derecha hasta que el sensor de visión con IA detecta un barril naranja; entonces, gira hacia el objeto detectado. Úsela cuando el robot necesite buscar un barril naranja antes de acercarse a él o recogerlo.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn right until orange barrel is detected
robot.turn(RIGHT)
while True:
vision_data = robot.vision.get_data(ORANGE_BARREL)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
turn left until orange barrel#
Esta macro hace girar el robot hacia la izquierda hasta que el sensor de visión con IA detecta un barril naranja; entonces, gira hacia el objeto detectado. Úsala cuando el robot necesite buscar un barril naranja antes de acercarse a él o recogerlo.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn left until orange barrel is detected
robot.turn(LEFT)
while True:
vision_data = robot.vision.get_data(ORANGE_BARREL)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
get orange barrel#
Esta macro mueve al robot hacia un barril naranja detectado hasta que lo recoja. Úsela después de que el robot vea un barril naranja o después de usar una macro de giro hasta encontrar uno.
Note: If the robot has difficulty detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Get orange barrel
while True:
vision_data = robot.vision.get_data(ORANGE_BARREL)
if vision_data[0].exists:
if robot.has_orange_barrel():
robot.stop_all_movement()
break
else:
robot.move_at(vision_data[0].bearing)
else:
robot.move_at(0)
wait(20, MSEC)
Visión de IA (Barril Azul)#
turn right until blue barrel#
Esta macro hace girar el robot hacia la derecha hasta que el sensor de visión con IA detecta un barril azul, momento en el que gira hacia el objeto detectado. Úsela cuando el robot necesite buscar un barril azul antes de acercarse a él o recogerlo.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn right until blue barrel is detected
robot.turn(RIGHT)
while True:
vision_data = robot.vision.get_data(BLUE_BARREL)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
turn left until blue barrel#
Esta macro hace girar el robot hacia la izquierda hasta que el sensor de visión con IA detecta un barril azul; entonces, gira hacia el objeto detectado. Úsala cuando el robot necesite buscar un barril azul antes de acercarse a él o recogerlo.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn left until blue barrel is detected
robot.turn(LEFT)
while True:
vision_data = robot.vision.get_data(BLUE_BARREL)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
get blue barrel#
Esta macro mueve al robot hacia un barril azul detectado hasta que lo recoja. Úsala después de que el robot vea un barril azul, o después de usar una macro de giro hasta encontrar un barril azul.
Note: If the robot has difficulty detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Get blue barrel
while True:
vision_data = robot.vision.get_data(BLUE_BARREL)
if vision_data[0].exists:
if robot.has_blue_barrel():
robot.stop_all_movement()
break
else:
robot.move_at(vision_data[0].bearing)
else:
robot.move_at(0)
wait(20, MSEC)
Visión de IA (robot AIM)#
turn right until AIM robot#
Esta macro hace girar el robot hacia la derecha hasta que el sensor de visión de IA detecta otro robot de codificación VEX AIM, momento en el que gira hacia él. Úsela cuando el robot necesite buscar otro robot antes de acercarse.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn right until AIM robot is detected
robot.turn(RIGHT)
while True:
vision_data = robot.vision.get_data(AIM_ROBOT)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
turn left until AIM robot#
Esta macro hace girar el robot hacia la izquierda hasta que el sensor de visión de IA detecta otro robot de codificación VEX AIM, momento en el que gira hacia él. Úsela cuando el robot necesite buscar otro robot antes de acercarse.
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn left until AIM robot is detected
robot.turn(LEFT)
while True:
vision_data = robot.vision.get_data(AIM_ROBOT)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
move to AIM robot#
Esta macro mueve el robot hacia otro robot de codificación VEX AIM hasta que esté lo suficientemente cerca como para detenerse. Úsela después de que el robot pueda ver a otro robot, o después de usar una macro de giro hasta encontrar un robot AIM.
Note: If the robot has difficulty detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Move to AIM robot
while True:
vision_data = robot.vision.get_data(AIM_ROBOT)
if vision_data[0].exists:
if vision_data[0].width >= 140:
robot.stop_all_movement()
break
else:
robot.move_at(vision_data[0].bearing)
else:
robot.move_at(0)
wait(20, MSEC)
Visión de IA (AprilTag)#
turn right until AprilTag#
This macro turns the robot to the right until the AI Vision Sensor detects AprilTag ID 0, then turns toward the detected AprilTag. Use it when the robot needs to search for an AprilTag before moving toward it. To change which AprilTag the robot will turn until, replace the 0 in TAG0 with any number from 0 to 37 (AprilTags 5 through 37 can be used with printed AprilTags from AIM Printables.)
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn right until AprilTag ID 0 is detected
robot.turn(RIGHT)
while True:
vision_data = robot.vision.get_data(TAG0)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
turn left until AprilTag#
This macro turns the robot to the left until the AI Vision Sensor detects AprilTag ID 0, then turns toward the detected AprilTag. Use it when the robot needs to search for an AprilTag before moving toward it. To change which AprilTag the robot will turn until, replace the 0 in TAG0 with any number from 0 to 37 (AprilTags 5 through 37 can be used with printed AprilTags from AIM Printables.)
Note: If the robot has difficulty detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Turn left until AprilTag ID 0 is detected
robot.turn(LEFT)
while True:
vision_data = robot.vision.get_data(TAG0)
if vision_data[0].exists:
# Turn to the object by adding your current heading and the vision bearing offset
robot.turn_to(robot.inertial.get_heading() + vision_data[0].bearing)
break
wait(20, MSEC)
move to AprilTag#
This macro moves the robot toward AprilTag ID 0 until it is close enough to stop. Use this after the robot can see an AprilTag, or after using a turn-until-AprilTag macro to find one. To change which AprilTag the robot will move to, replace the 0 in TAG0 with any number from 0 to 37 (AprilTags 5 through 37 can be used with printed AprilTags from AIM Printables.)
Note: If the robot has difficulty detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.
El código que aparece a continuación muestra la secuencia de Python que se añade a tu proyecto al arrastrar esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de añadirla.
# Move to AprilTag ID 0
while True:
vision_data = robot.vision.get_data(TAG0)
if vision_data[0].exists:
if vision_data[0].width >= 60:
robot.stop_all_movement()
break
else:
robot.move_at(vision_data[0].bearing)
else:
robot.move_at(0)
wait(20, MSEC)