宏#
介绍#
VEX AIM 编码机器人包含预置宏——将多组命令捆绑成可重复使用的代码序列。每个宏执行一个完整的行为,例如表达情绪或使用 AI 视觉传感器查找并接近物体。以下是可用宏的列表:
情感——让机器人表现出情感。
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 视觉(运动球)——转向并获取运动球。
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.
人工智能视觉(橙色桶)——转向并获取橙色桶。
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.
人工智能视觉(蓝色桶)——转向并获取蓝色桶。
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 视觉(AIM 机器人)——转向并向其他 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.
AI 视觉(AprilTag)——转向并朝 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.
情绪#
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#
这套方法让机器人表现得悲伤起来。
# 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#
这套方法让机器人做出傻乎乎的行为。
# 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#
这套方法让机器人表现出愤怒。
# 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#
这套方法让机器人表现得兴奋不已。
# 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视觉(运动球)#
turn right until sports ball#
这组方法使机器人向右转,直到AI视觉传感器检测到运动球。
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#
这组方法使机器人向左转,直到AI视觉传感器检测到运动球。
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#
这组方法使机器人移动去收集运动球。
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视觉(橙色桶)#
turn right until orange barrel#
这组方法使机器人向右转,直到AI视觉传感器检测到橙色桶。
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#
这组方法使机器人向左转,直到AI视觉传感器检测到橙色桶。
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#
这组方法让机器人移动去收集一个橙色的桶。
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)
人工智能视觉(蓝桶)#
turn right until blue barrel#
这组方法使机器人向右转,直到AI视觉传感器检测到蓝色桶。
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#
这组方法使机器人向左转动,直到AI视觉传感器检测到蓝色桶。
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#
这组方法让机器人移动去收集蓝色桶。
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)
人工智能视觉(AIM机器人)#
turn right until AIM robot#
这组方法使机器人向右转,直到 AI 视觉传感器检测到 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#
这组方法使机器人向左转动,直到 AI 视觉传感器检测到 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#
这套方法让机器人向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)
人工智能视觉(AprilTag)#
turn right until AprilTag#
这组方法使机器人向右转动,直到 AI 视觉传感器检测到 AprilTag ID 0。要更改机器人将转到哪个 AprilTag,请将 0
中的 TAG0
替换为 0
到 37
之间的任意数字(AprilTags 5 到 37 可与 AIM Printables 中打印的 AprilTag 一起使用。)
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#
这组方法使机器人向左转动,直到 AI 视觉传感器检测到 AprilTag ID 0。要更改机器人将转向到哪个 AprilTag,请将 0
中的 TAG0
替换为 0
到 37
之间的任意数字(AprilTags 5 到 37 可与 AIM Printables 中打印的 AprilTag 一起使用。)
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#
这组方法使机器人向 AprilTag ID 0 移动。要更改机器人将移动到哪个 AprilTag,请将 0
中的 TAG0
替换为 0
到 37
之间的任意数字(AprilTags 5 到 37 可与 AIM Printables 中打印的 AprilTag 一起使用。)
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)