从robolink导入* # API与RoboDK通信从RoboDK导入* #库基本矩阵操作导入datetime从PIL导入图像导入时间#使用RoboDK API RDK = robolink() #设置变量robot = RDK。Item('Mecademic Meca500x') red = (227,0,0) # RGB值为红色绿色= (0,227,0)# RGB值为绿色蓝色= (0,0,227) #蓝色延迟RGB值= 3 # #设置程序变量启动延时秒= RDK.Item(“启动”)PP1 = RDK.Item (PP1) PP2 = RDK.Item (PP2)项目= RDK.Item(“项目”)PP4 = RDK.Item(“PP4”)PP5 = RDK.Item(“PP5”)PP6 = RDK.Item(“PP6”)PP7 = RDK.Item(“PP7”)PP8 = RDK.Item(“PP8”)PA12 = RDK.Item (PA12) PA23 = RDK.Item(“PA23”)PA34 = RDK.Item(“PA34”)PA45 = RDK.Item(“PA45”)PA56 = RDK.Item(“PA56”)PA67 = RDK.Item(“PA67”)PA78 = RDK.Item(“PA78”)PA8HOME = RDK.Item (PA8HOME) #定义子程序##用户选择要保留的颜色def get_choice(): options = ["RED", "BLUE", "GREEN"] print("Hi, Baxter将删除任何不需要的色块")print("选项是RED, GREEN和BLUE") while True: choice1 = input("你想保留哪种颜色?\n") selection = choice1.upper() #使输入大写如果选择在选项:返回选择else: print(选择,"不是一个选项。请重试")choice = get_choice() print("You have chosen",choice) #运行决策程序与轨迹StartUp.RunCode() #启动模拟file_name = RDK.getParam('PATH_OPENSTATION') + "/Image1.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) #打开图片的立方color = img.getpixel((320,240)) print(color) if choice == "BLUE" and color == BLUE: PA12.RunCode() elif choice == "BLUE" and color == BLUE:elif PA12.RunCode() = = = =“绿色”和颜色选择格林:PA12.RunCode()其他:PP1.RunCode () file_name = RDK.getParam (PATH_OPENSTATION) + " / Image2.png " RDK.Cam2D_Snapshot (file_name) time . sleep(延迟)img = Image.open (file_name) #开放立方体的照片颜色= img.getpixel((320240))打印(如果选择颜色)= = = =“红”和颜色红色:PA23.RunCode () elif选择= = = =“蓝色”和颜色蓝色:PA23.RunCode () elif = = = =“绿色”和颜色选择格林:PA23.RunCode ():PP2.RunCode() file_name = RDK.getParam('PATH_OPENSTATION') + "/Image3.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) #立方体打开图片color = img.getpixel((320,240)) print (color) if choice == "RED" and color == BLUE: PA34.RunCode() elif choice == "GREEN" and color == GREEN: PA34.RunCode() else:PP3.RunCode() file_name = RDK.getParam('PATH_OPENSTATION') + "/Image4.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) #立方打开图片color = img.getpixel((320,240)) print (color) if choice == "RED" and color == RED: PA45.RunCode() elif choice == "BLUE" and color == BLUE: PA45.RunCode() elif choice == "GREEN" and color == GREEN: PA45.RunCode() else:PP4.RunCode() file_name = RDK.getParam('PATH_OPENSTATION') + "/Image5.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) #立方打开图片color = img.getpixel((320,240)) print (color) if choice == "RED" and color == RED: PA56.RunCode() elif choice == "BLUE" and color == BLUE: PA56.RunCode() elif choice == "GREEN" and color == GREEN: PA56.RunCode() else:PP5.RunCode() file_name = RDK.getParam('PATH_OPENSTATION') + "/Image6.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) #打开方块图片color = img.getpixel((320,240)) print (color) if choice == "RED" and color == RED: PA67.RunCode() elif choice == "BLUE" and color == BLUE: PA67.RunCode() elif choice == "GREEN" and color == GREEN: PA67.RunCode()PP6.RunCode() file_name = RDK.getParam('PATH_OPENSTATION') + "/Image7.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) #立方打开图片color = img.getpixel((320,240)) print (color) if choice == "RED" and color == BLUE: PA78.RunCode() elif choice == "GREEN" and color == GREEN: PA78.RunCode() else: PP7.RunCode() file_name = RDK.getParam('PATH_OPENSTATION') + "/Image8.png" RDK.Cam2D_Snapshot(file_name) time.sleep(delay) img = Image.open(file_name) # Open picture of cube color = img.getpixel((320,240)) print (color) if choice == "RED" and color == red: PA8HOME.RunCode() elif choice == "BLUE" and color == blue: PA8HOME.RunCode() elif choice == "GREEN" and color == green: PA8HOME.RunCode() else: PP8.RunCode()