Macro#
Introducción#
Las macros de VEX AIM Python son bloques de código prediseñados que se pueden arrastrar a un proyecto de Python. Cada macro es un grupo de comandos de Python que trabajan juntos para hacer que el robot complete un comportamiento más amplio.
Estos no son métodos únicos que se llaman desde el código. En su lugar, cada macro se inserta como una secuencia de código ya preparada 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 usa esa macro.
A continuación se muestra una lista de todas las macros:
Emociones: haz que el robot actúe de manera expresiva.
act happy— Hace que el robot actúe feliz.act sad— Hace que el robot actúe triste.act silly— Hace que el robot actúe tonto.act angry— Hace que el robot actúe enojado.act excited— Hace que el robot actúe emocionado.
Visión de IA (balón deportivo): gire hacia o recoja balones deportivos.
turn right until sports ball— Gira a la derecha hasta que se detecta un balón deportivo.turn left until sports ball— Gira a la izquierda hasta que se detecte una pelota deportiva.get sports ball— Mueve el robot para recoger una pelota deportiva.
Visión de IA (barril naranja): gire hacia o recoja barriles naranjas.
turn right until orange barrel— Gira a la derecha hasta que se detecta un barril naranja.turn left until orange barrel— Gira a la izquierda hasta que se detecta un barril naranja.get orange barrel— Mueve el robot para recoger un barril naranja.
Visión de IA (barril azul): gire hacia o recoja barriles azules.
turn right until blue barrel— Gira a la derecha hasta que se detecta un barril azul.turn left until blue barrel— Gira a la izquierda hasta que se detecte un barril azul.get blue barrel— Mueve el robot para recoger un barril azul.
Visión AI (robot AIM) — Gira hacia o muévete hacia otros robots AIM.
turn right until AIM robot— Gira a la derecha hasta que se detecta otro robot AIM.turn left until AIM robot— Gira a la izquierda hasta que se detecte otro robot AIM.move to AIM robot— Se mueve hacia otro robot AIM.
Visión de IA (AprilTag): gire o avance hacia AprilTags.
turn right until AprilTag— Gira a la derecha hasta que se detecta un AprilTag.turn left until AprilTag— Gira a la izquierda hasta que se detecta un AprilTag.move to AprilTag— Avanza hacia una etiqueta de abril.
Emociones#
act happy#
Esta macro hace que el robot actúe feliz mostrando caras felices, reproduciendo un sonido feliz, cambiando los LED y moviéndose hacia adelante y hacia atrás. Úselo cuando el robot deba responder de manera alegre o positiva.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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, apagando los LED y moviéndose lentamente en diferentes direcciones. Úselo cuando el robot muestre una reacción decepcionante o de baja energía.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 tontamente girando, cambiando caras y parpadeando en diferentes colores de LED. Úselo cuando el robot deba hacer una reacción lúdica o sorprendente.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 enojado mostrando caras enojadas, reproduciendo un sonido enojado, poniendo los LED rojos y moviéndose bruscamente. Úselo cuando el robot deba mostrar una reacción de frustración o advertencia.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 excitada, reproduciendo un sonido excitado, moviéndose rápidamente de un lado a otro y parpadeando con LEDs naranjas. Úselo cuando el robot deba celebrar o reaccionar con mucha energía.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la derecha hasta que el sensor de visión AI detecta una pelota deportiva y luego gira hacia el objeto detectado. Úselo cuando el robot necesite buscar una pelota deportiva antes de moverse hacia ella o recogerla.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la izquierda hasta que el sensor de visión AI detecta una pelota deportiva y luego gira hacia el objeto detectado. Úselo cuando el robot necesite buscar una pelota deportiva antes de moverse hacia ella o recogerla.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 el robot hacia una pelota deportiva detectada hasta que el robot la haya recogido. Usa esto después de que el robot pueda ver una pelota deportiva, o después de usar una macro turn-until-sports-ball para encontrar una.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir las velocidades de movimiento y giro del robot con set_move_velocity y set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 de naranja)#
turn right until orange barrel#
Esta macro gira el robot hacia la derecha hasta que el sensor de visión AI detecta un barril naranja y luego gira hacia el objeto detectado. Úselo cuando el robot necesite buscar un barril naranja antes de moverse hacia él o recogerlo.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la izquierda hasta que el sensor de visión AI detecta un barril naranja y luego gira hacia el objeto detectado. Úselo cuando el robot necesite buscar un barril naranja antes de moverse hacia él o recogerlo.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 el robot hacia un barril naranja detectado hasta que el robot lo haya recogido. Use esto después de que el robot pueda ver un barril naranja, o después de usar una macro de barril naranja hasta que encuentre uno.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir las velocidades de movimiento y giro del robot con set_move_velocity y set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la derecha hasta que el sensor de visión AI detecta un barril azul y luego gira hacia el objeto detectado. Úselo cuando el robot necesite buscar un barril azul antes de moverse hacia él o recogerlo.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la izquierda hasta que el sensor de visión AI detecta un barril azul y luego gira hacia el objeto detectado. Úselo cuando el robot necesite buscar un barril azul antes de moverse hacia él o recogerlo.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 el robot hacia un barril azul detectado hasta que el robot lo haya recogido. Use esto después de que el robot pueda ver un barril azul, o después de usar una macro de barril azul hasta que encuentre uno.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir las velocidades de movimiento y giro del robot con set_move_velocity y set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la derecha hasta que el sensor de visión AI detecta otro robot de codificación VEX AIM y luego gira hacia él. Úselo cuando el robot necesite buscar otro robot antes de moverse hacia él.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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 gira el robot hacia la izquierda hasta que el sensor de visión AI detecta otro robot de codificación VEX AIM y luego gira hacia él. Úselo cuando el robot necesite buscar otro robot antes de moverse hacia él.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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. Use esto después de que el robot pueda ver otro robot, o después de usar una macro turn-until-AIM-robot para encontrar uno.
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir las velocidades de movimiento y giro del robot con set_move_velocity y set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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#
Esta macro gira el robot hacia la derecha hasta que el sensor de visión AI detecta AprilTag ID 0, luego gira hacia la AprilTag detectada. Úselo cuando el robot necesite buscar una etiqueta de abril antes de avanzar hacia ella. Para cambiar hasta qué etiqueta de abril girará el robot, reemplace el 0 en TAG0 con cualquier número del 0 al 37 (las etiquetas de abril del 5 al 37 se pueden usar con etiquetas de abril impresas de AIM Printables).
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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#
Esta macro gira el robot hacia la izquierda hasta que el sensor de visión AI detecta AprilTag ID 0, luego gira hacia la AprilTag detectada. Úselo cuando el robot necesite buscar una etiqueta de abril antes de avanzar hacia ella. Para cambiar hasta qué etiqueta de abril girará el robot, reemplace el 0 en TAG0 con cualquier número del 0 al 37 (las etiquetas de abril del 5 al 37 se pueden usar con etiquetas de abril impresas de AIM Printables).
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir la velocidad de giro del robot con set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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#
Esta macro mueve el robot hacia AprilTag ID 0 hasta que esté lo suficientemente cerca como para detenerse. Use esto después de que el robot pueda ver una etiqueta de abril, o después de usar una macro turn-until-AprilTag para encontrar una. Para cambiar a qué etiqueta de abril se moverá el robot, reemplace el 0 en TAG0 con cualquier número del 0 al 37 (las etiquetas de abril del 5 al 37 se pueden usar con etiquetas de abril impresas de AIM Printables).
Nota: Si el robot tiene dificultades para detectar objetos, intente reducir las velocidades de movimiento y giro del robot con set_move_velocity y set_turn_velocity.
El siguiente código muestra la secuencia de Python que se agrega a su proyecto cuando se arrastra esta macro desde la Caja de herramientas. Puedes usar la secuencia tal cual o editarla después de agregarla.
# 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)