Macro#

Introducción#

El robot de codificación VEX AIM incluye macros predefinidas: grupos de comandos agrupados en secuencias de código reutilizables. Cada macro realiza un comportamiento completo, como expresar una emoción o usar el sensor de visión de IA para encontrar y acercarse a un objeto. A continuación, se muestra una lista de macros disponibles:

Emociones: Haz que el robot actúe de forma expresiva.

Visión de IA (pelota deportiva): gira hacia adelante y obtén pelotas deportivas.

Visión de IA (Barril naranja): gira hacia los barriles naranjas y obténlos.

Visión de IA (barril azul): gira hacia los barriles azules y obtén los barriles azules.

Visión de IA (robot AIM): gira y muévete hacia otros robots AIM.

AI Vision (AprilTag) – Gira y muévete hacia AprilTags.

Emociones#

act happy#

Este conjunto de métodos hace que el robot actúe feliz.

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

Este conjunto de métodos hace que el robot actúe triste.

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

Este conjunto de métodos hace que el robot actúe de manera tonta.

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

Este conjunto de métodos hace que el robot actúe enojado.

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

Este conjunto de métodos hace que el robot actúe excitado.

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

Este conjunto de métodos hace que el robot gire a la derecha hasta que el sensor de visión IA detecte una pelota deportiva.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

turn left until sports ball#

Este conjunto de métodos hace que el robot gire a la izquierda hasta que el sensor de visión IA detecte una pelota deportiva.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

get sports ball#

Este conjunto de métodos hace que el robot se mueva para recoger una pelota deportiva.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.

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

Este conjunto de métodos hace que el robot gire a la derecha hasta que el sensor de visión IA detecte un barril naranja.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

turn left until orange barrel#

Este conjunto de métodos hace que el robot gire a la izquierda hasta que el sensor de visión IA detecte un barril naranja.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

get orange barrel#

Este conjunto de métodos hace que el robot se mueva para recoger un barril naranja.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.

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

Este conjunto de métodos hace que el robot gire a la derecha hasta que el sensor de visión IA detecte un barril azul.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

turn left until blue barrel#

Este conjunto de métodos hace que el robot gire a la izquierda hasta que el sensor de visión IA detecte un barril azul.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

get blue barrel#

Este conjunto de métodos hace que el robot se mueva para recoger un barril azul.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.

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

Este conjunto de métodos hace que el robot gire a la derecha hasta que el sensor de visión IA detecte un robot codificador VEX AIM.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

turn left until AIM robot#

Este conjunto de métodos hace que el robot gire a la izquierda hasta que el sensor de visión IA detecte un robot codificador VEX AIM.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

move to AIM robot#

Este conjunto de métodos hace que el robot se mueva hacia un robot de codificación VEX AIM.

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.

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

Este conjunto de métodos hace que el robot gire a la derecha hasta que el sensor de visión de IA detecte el ID 0 de AprilTag. Para cambiar hasta qué AprilTag girará el robot, reemplace el 0 en TAG0 con cualquier número entre 0 y 37 (las AprilTags 5 a 37 se pueden usar con AprilTags impresas de AIM Printables.)

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

turn left until AprilTag#

Este conjunto de métodos hace que el robot gire a la izquierda hasta que el sensor de visión de IA detecte el ID 0 de AprilTag. Para cambiar hasta qué AprilTag girará el robot, reemplace el 0 en TAG0 con cualquier número entre 0 y 37 (las AprilTags 5 a 37 se pueden usar con AprilTags impresas de AIM Printables.)

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s turn velocity with set_turn_velocity.

# 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.heading() + vision_data[0].bearing)
        break
    wait(20, MSEC)

move to AprilTag#

Este conjunto de métodos hace que el robot se mueva hacia el ID 0 de AprilTag. Para cambiar a qué AprilTag se moverá el robot, reemplace el 0 en TAG0 con cualquier número entre 0 y 37 (las AprilTags 5 a 37 se pueden usar con las AprilTags impresas de AIM Printables.)

Note: If the robot appears to be having difficulties with detecting objects, try lowering the robot’s move and turn velocities with set_move_velocity and set_turn_velocity.

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