在ALMemory变量中读取结果

我们创建一个到ALMemory的代理,并查看ALVisionRecognition的输出变量。

import os import sys import time import naoqi from naoqi import * count = 10 moduleName = "Python_Reco" PC_IP = "127.0.0.1" # Replace here with your computer's IP address NAO_IP = "nao.local" # Replace here with your NAOqi's IP address PORT = 9559 # ALMemory variable where the ALVisionRecognition module # outputs its results. memValue = "PictureDetected" class myModule(ALModule): """python class myModule test auto documentation""" def dataChanged(self, strVarName, value, strMessage): """callback when data change""" print "datachanged", strVarName, " ", value, " ", strMessage global count count = count-1 broker = ALBroker("pythonBroker", PC_IP,9999, NAO_IP,9559) pythonModule = myModule(moduleName) # Create a proxy to ALMemory try: memoryProxy = ALProxy("ALMemory", NAO_IP, PORT) except RuntimeError,e: print "Error when creating ALMemory proxy:" exit(1) # Have the python module called back when picture recognition results change. try: memoryProxy.subscribeToEvent(memValue, moduleName, "dataChanged") except RuntimeError,e: print "Error when subscribing to event" exit(1) # Let the picture recognition run for a little while. while count>0: time.sleep(5) # Indicate from the event try: memoryProxy.unsubscribeToEvent(memValue, moduleName) except RuntimeError,e: print "Error when subscribing to event" exit(1) print 'end of vision_recognition python script'





Copyright © 2010 Aldebaran-Robotics - 版权所有