Macro#
Introduction#
The VEX AIM Coding Robot includes prebuilt macros—groups of commands bundled into reusable code sequences. Each macro performs a full behavior, such as expressing an emotion or using the AI Vision Sensor to find and approach an object. Below is a list of available macros:
Emotions – Make the robot act expressively.
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.
AI Vision (Sports Ball) – Turn toward and get sports balls.
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 to collect a sports ball.
AI Vision (Orange Barrel) – Turn toward and get orange barrels.
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 to collect an orange barrel.
AI Vision (Blue Barrel) – Turn toward and get blue barrels.
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 to collect a blue barrel.
AI Vision (AIM Robot) – Turn and move toward other AIM robots.
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.
AI Vision (AprilTag) – Turn and move toward AprilTags.
turn_right_until_april_tag – Turns right until AprilTag is detected.
turn_left_until_april_tag – Turns left until AprilTag is detected.
move_to_april_tag – Moves toward AprilTag.
Emotions#
act happy#
This set of methods makes the robot act happy.
# 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#
This set of methods makes the robot act sad.
# 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#
This set of methods makes the robot act silly.
# 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#
This set of methods makes the robot act angry.
# 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#
This set of methods makes the robot act excited.
# 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)
AI Vision (Sports Ball)#
turn right until sports ball#
This set of methods makes the robot turn right until the AI Vision Sensor detects a sports ball.
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#
This set of methods makes the robot turn left until the AI Vision Sensor detects a sports ball.
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#
This set of methods makes the robot move to collect a sports ball.
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)
AI Vision (Orange Barrel)#
turn right until orange barrel#
This set of methods makes the robot turn right until the AI Vision Sensor detects an orange barrel.
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#
This set of methods makes the robot turn left until the AI Vision Sensor detects an orange barrel.
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#
This set of methods makes the robot move to collect an orange barrel.
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)
AI Vision (Blue Barrel)#
turn right until blue barrel#
This set of methods makes the robot turn right until the AI Vision Sensor detects a blue barrel.
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#
This set of methods makes the robot turn left until the AI Vision Sensor detects a blue barrel.
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#
This set of methods makes the robot move to collect a blue barrel.
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)
AI Vision (AIM Robot)#
turn right until AIM robot#
This set of methods makes the robot turn right until the AI Vision Sensor detects a VEX AIM Coding Robot.
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#
This set of methods makes the robot turn left until the AI Vision Sensor detects a VEX AIM Coding Robot.
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#
This set of methods makes the robot move towards a VEX AIM Coding Robot.
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)
AI Vision (AprilTag)#
turn right until AprilTag#
This set of methods makes the robot turn right until the AI Vision Sensor detects AprilTag ID 0. 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 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#
This set of methods makes the robot turn left until the AI Vision Sensor detects AprilTag ID 0. 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 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#
This set of methods makes the robot move towards AprilTag ID 0. 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 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)