当前位置: 首页>>代码示例>>Python>>正文


Python ALProxy.subscribeToEvent方法代码示例

本文整理汇总了Python中naoqi.ALProxy.subscribeToEvent方法的典型用法代码示例。如果您正苦于以下问题:Python ALProxy.subscribeToEvent方法的具体用法?Python ALProxy.subscribeToEvent怎么用?Python ALProxy.subscribeToEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在naoqi.ALProxy的用法示例。


在下文中一共展示了ALProxy.subscribeToEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ReactionModule

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class ReactionModule(ALModule):
	""" A basic module to test events """
	
	def __init__(self, name):
		ALModule.__init__(self, name)
		self.name = name
		self.memory = ALProxy("ALMemory")
		self.motion = ALProxy("ALMotion")
		self.memory.subscribeToEvent("ColorDetectedEvent", name, "handleDetection")
		
        
	def handleDetection(self, key, value, message):
		""" A method that handles detection of the color. """
		names = ['HeadYaw', 'HeadPitch']
		times = [[0.01], [0.01]] # what is the fastest rate?
		xStep = 0.03
		yStep = 0.022
		moveX = -xStep if value[0]>0 else xStep if value[0]<0 else 0.0 # since robot camera has a mirror view, we need to alternate directions
		moveY = yStep if value[1]>0 else -yStep if value[1]<0 else 0.0
		print moveX, moveY
		self.memory.unsubscribeToEvent("ColorDetectedEvent", self.name)
		self.motion.angleInterpolation(names, [moveX, moveY], times, False)
		self.memory.subscribeToEvent("ColorDetectedEvent", self.name, "handleDetection")
		
	def disconnect(self):
		try:
			self.memory.unsubscribeToEvent("ColorDetectedEvent", self.getName())
		except BaseException, err:
			print "Error while disconnecting from color reaction module: " + str(err)
开发者ID:knawrot,项目名称:nao-objects-recognition,代码行数:31,代码来源:reaction.py

示例2: SpeechDetectionModule

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class SpeechDetectionModule(ALModule):
	""" A module that handles NAO recognition app commands. """
	
	def __init__(self, name):
		ALModule.__init__(self, name)
		self.name = name
		self.memory = ALProxy("ALMemory")
		self.asr = ALProxy("ALSpeechRecognition")
		self.asr.setLanguage("English")
		vocabulary = ["color", "text", "gesture", "phone"]
		self.asr.setVocabulary(vocabulary, False)
		self.asr.subscribe(self.getName())
		self.memory.subscribeToEvent("WordRecognized", self.getName(), "onWordRecognized")
	
	def onWordRecognized(self, key, value, message):	
		""" A method that handles command recognition. """
		global NaoWorkingMode
		if(len(value) > 1 and value[1] >= 0.5):
			print 'recognized the word :', value[0]
			NaoWorkingMode = value[0]
		else:
			print 'unsifficient threshold'
			NaoWorkingMode = None
			
	def disconnect(self):
		try:
			self.memory.unsubscribeToEvent("WordRecognized", self.getName())
			self.asr.unsubscribe(self.getName())
		except BaseException, err:
			print "Error while disconnecting from speech module: " + str(err)
开发者ID:knawrot,项目名称:nao-objects-recognition,代码行数:32,代码来源:app.py

示例3: NAOVoiceRec

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class NAOVoiceRec(ALModule):
    def __init__(self, id, ip, port, wordList, callBack, wordSpotting=True, visualExpression=True, audioExpression=False):
        super(NAOVoiceRec, self).__init__(id)
        self.id = id
        self.wordCallBack = callBack;

        #create the speech recognition proxy
        self.speechRec = ALProxy("ALSpeechRecognition", ip, port)

        #set the language
        self.speechRec.setLanguage("English")
        #load the vocabulary
        self.speechRec.setVocabulary(wordList, wordSpotting)
        self.speechRec.subscribe(id)
        # configure expressions
        self.speechRec.setVisualExpression(visualExpression)
        self.speechRec.setAudioExpression(audioExpression)

        #get the ALMemory Proxy and subscribe to the events
        self.memProx = ALProxy("ALMemory")
        self.memProx.subscribeToEvent("WordRecognized", self.id, "wordRecognized")

    def __del__(self):
        self.speechRec.unsubscribe(self.id)
        self.memProx.unsubscribeToEvent("WordRecognized", self.id)

    def wordRecognized(self, event, words, id):
        self.wordCallBack(words)
开发者ID:afranka69,项目名称:ShowRobbie,代码行数:30,代码来源:VoiceRec.py

示例4: _SubscriberModule

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class _SubscriberModule(ALModule):
    def __init__(self):
        ALModule.__init__(self)
        self.memory = ALProxy('ALMemory')
        self.dataNameToMicroEventCallback = {}
        self.dataNameToEventCallback = {}
        
    def subscribeToEvent(self, dataName, callback):
        self.dataNameToEventCallback[dataName] = callback
        self.memory.subscribeToEvent(dataName, self.moduleName, 'eventCB')
        
    def unsubscribeToEvent(self, dataName):
        if dataName in self.dataNameToEventCallback:
            self.memory.unsubscribeToEvent(dataName, self.moduleName)
            del self.dataNameToEventCallback[dataName]
        
    def eventCB(self, dataName, value, message):
        self.dataNameToEventCallback[dataName](dataName, value, message)
        
    def subscribeToMicroEvent(self, dataName, callback, cbMessage):
        self.dataNameToMicroEventCallback[dataName] = callback
        self.memory.subscribeToMicroEvent(dataName, self.moduleName, cbMessage, 'microEventCB')
        
    def unsubscribeToMicroEvent(self, dataName):
        if dataName in self.dataNameToMicroEventCallback:
            self.memory.unsubscribeToMicroEvent(dataName, self.moduleName)
            del self.dataNameToMicroEventCallback[dataName]
        
    def microEventCB(self, dataName, value, message):
        self.dataNameToMicroEventCallback[dataName](dataName, value, message)
开发者ID:AxelVoitier,项目名称:naocket,代码行数:32,代码来源:memory.py

示例5: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
    def __init__(self, name):
        ALModule.__init__(self, name)
        # No need for IP and port here because
        # we have our Python broker connected to NAOqi broker

        # HUE service
        self._hue = None
        self._teller = None

        # Create a proxy to ALTextToSpeech for later use
        global tts
        tts = ALProxy("ALTextToSpeech", NAO_IP, 9559)

        # Subscribe to the FaceDetected event:
        global memory
        self.leds = ALProxy("ALLeds", NAO_IP, 9559)
        memory = ALProxy("ALMemory")
        memory.subscribeToEvent("MiddleTactilTouched",
            "HumanGreeter",
            "onMiddleTouchSensed")
        # memory.unsubscribeToEvent("WordRecognized",
        #    "HumanGreeter")
        speechrecog = ALProxy("ALSpeechRecognition")
        speechrecog.setLanguage("French")
        wordList = ["bleu", "rouge", "vert", "jaune",
                    "porte", "température", "meteo"]

        try:
            speechrecog.setVocabulary(wordList, True)

        except Exception as ex:
            _logger.warning("Got exception: %s", ex)

        tts.say("Je suis prêt à recevoir des ordres")
开发者ID:WafaJohal,项目名称:demo-ipopo-nao,代码行数:36,代码来源:main.py

示例6: RedBallDetectionModule

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class RedBallDetectionModule(ALModule):
	""" A basic module to test events """
	
	def __init__(self, name):
		ALModule.__init__(self, name)
		self.name = name
		#self.tts = ALProxy("ALTextToSpeech")
		self.memory = ALProxy("ALMemory")
		self.motion = ALProxy("ALMotion")
		self.memory.subscribeToEvent("RedBallDetectedEvent", name, "handleBallDetection")
		
        
	def handleBallDetection(self, key, value, message):
		""" A method that handles detection of the ball. """
		names = ['HeadYaw', 'HeadPitch']
		times = [[0.01], [0.01]] # what is the fastest rate?
		xStep = 0.03
		yStep = 0.022
		moveX = -xStep if value[0]>0 else xStep if value[0]<0 else 0.0 # since robot camera has a mirror view, we need to alternate directions
		moveY = yStep if value[1]>0 else -yStep if value[1]<0 else 0.0
		print moveX, moveY
		self.memory.unsubscribeToEvent("RedBallDetectedEvent", self.name)
		self.motion.angleInterpolation(names, [moveX, moveY], times, False)
		#self.tts.say("Recevied the values! " + str(value[0]) + " " + str(value[1]))
		self.memory.subscribeToEvent("RedBallDetectedEvent", self.name, "handleBallDetection")
开发者ID:knawrot,项目名称:nao-objects-recognition,代码行数:27,代码来源:naoScript.py

示例7: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
    def __init__(self, name):
        ALModule.__init__(self, name)

        # Create proxies for the instance.
        global memory
        memory = ALProxy("ALMemory")

        self.tts = ALProxy("ALTextToSpeech")
        self.leds = ALProxy("ALLeds")
        self.motion = ALProxy("ALMotion")

        # Write empty valence and arousal values to memory.
        valence = 0
        arousal = 0
        param1 = 'null'
        current_emotion = [(valence, arousal), ("valence_mood", "arousal_mood"), ("personality"), (param1, "param2")]
        memory.insertData("Emotion/Current", current_emotion)

        # Disable ALAutonomousLife to better demonstrate emotional actions.
        self.autonomous_life = ALProxy("ALAutonomousLife")
        if (self.autonomous_life.getState() != "disabled"):
            self.autonomous_life.setState("disabled")
        time.sleep(1.0)
        self.motion.wakeUp()

        # Run behaviour when a tactile touched.
        memory.subscribeToEvent("VAChanged", self.getName(), "express_current_emotion")
开发者ID:Sandy4321,项目名称:nao-emotional-framework,代码行数:29,代码来源:standalone_emotional_demo.py

示例8: ReactToTouch

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class ReactToTouch(ALModule):
    def __init__(self, name):
        ALModule.__init__(self, name)

        global not_touched
        setNot_touched(True)
        # Subscribe to TouchChanged event:
        global memory
        self.memory = ALProxy("ALMemory", NAO_IP, 9559)
        self.memory.subscribeToEvent("TouchChanged",
            "ReactToTouch",
            "onTouched")
        print("I initialize and this works")

    def onTouched(self, strVarName, value):
        """ This will be called each time a touch
        is detected.

        """
        touched_bodies = []
        for p in value:
            if p[1]:
                touched_bodies.append(p[0])
        # Unsubscribe to the event when talking,
        # to avoid repetitions
        if len(touched_bodies)>=1:
            print("I registered a touch event")
            setNot_touched(False)
            memory.unsubscribeToEvent("TouchChanged",
                "ReactToTouch")
开发者ID:frannythebanny,项目名称:cheating-robot,代码行数:32,代码来源:touch_event.py

示例9: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class Nao:
	def __init__(self,ip,port):
		self.tts = ALProxy("ALTextToSpeech", ip, port)
		self.motion = ALProxy("ALMotion", ip, port)
		self.posture = ALProxy("ALRobotPosture", ip, port)
		self.memory = ALProxy("ALMemory")
		self.speech = ALProxy("ALSpeechRecognition",ip,port)
		
		#Word Recognition
		self.speech.setLanguage("English") 
		wordList=["hello","goodbye","yes","no", "exit", "sit down"]
		self.speech.setWordListAsVocabulary(wordList)
		self.memory.subscribeToEvent("WordRecognized","pythonModule", "onSpeechRecognized") #  event is case sensitive !


	def sit_down(self):
		self.posture.goToPosture("Sit", 0.3)
		time.sleep(0.5)
		self.motion.setStiffnesses("Body", 0.3)
		fractionMaxSpeed=0.1
		self.motion.setAngles(["LArm"],[ 0.96, 0.03,-0.71,-1.20, 0.00, 0.30],fractionMaxSpeed)
		self.motion.setAngles(["RArm"],[ 0.96,-0.05, 0.71, 1.20, 0.00, 0.30],fractionMaxSpeed)
		self.motion.setAngles(["RLeg"],[-0.84,-0.30,-1.50, 1.02, 0.92, 0.00],fractionMaxSpeed)
		self.motion.setAngles(["LLeg"],[-0.84, 0.30,-1.50, 1.02, 0.92, 0.00],fractionMaxSpeed)
		time.sleep(0.5)
		self.motion.setStiffnesses("Body", 0.0)
		time.sleep(0.25)
		
		
	def __del__(self):
		print "memory.unsubscribeToEvent(WordRecognized,pythonModule)"
		self.memory.unsubscribeToEvent("WordRecognized","pythonModule") #  event is case sensitive !		
开发者ID:nao-youbot,项目名称:NAO,代码行数:34,代码来源:hello_3.py

示例10: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
 def __init__(self, name):
     ALModule.__init__(self, name)
     self.tts = ALProxy("ALTextToSpeech")
     
     global memory
     memory = ALProxy("ALMemory")
     memory.subscribeToEvent("ALTextToSpeech/TextDone",
         "haiku_guru",
         "on_tts_text_done")
开发者ID:Avnerus,项目名称:nao-guru,代码行数:11,代码来源:haiku_guru.py

示例11: Reward

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class Reward(ALModule):

    value = 0
    event_received = False

    def __init__(self, _name):
        self.name = _name
        ALModule.__init__(self, _name)
        self.memory = ALProxy("ALMemory")
        self.speechRecognizer = ALProxy("ALSpeechRecognition")
        for subscriber in self.speechRecognizer.getSubscribersInfo():
            self.speechRecognizer.unsubscribe(subscriber[0])
        vocabulary=["bravo"]
        self.speechRecognizer.setVocabulary(vocabulary, False)

    def subscribe_to_events(self):
        self.memory.subscribeToEvent( "FrontTactilTouched", self.name, "onFrontTactilTouched" )
        self.memory.subscribeToEvent( "RearTactilTouched", self.name, "onRearTactilTouched" )
        self.speechRecognizer.subscribe("success_event")


    def unsubscribe_to_events(self):
        self.memory.unsubscribeToEvent("FrontTactilTouched", self.name)
        self.memory.unsubscribeToEvent("RearTactilTouched", self.name)
        self.speechRecognizer.unsubscribe("success_event")

    def reset(self):
        self.value = 0
        self.event_received = False
        self.unsubscribe_to_events()

    def positiveReward(self):
        self.value = 1
        self.event_received = True

    def negativeReward(self):
        self.value = -1
        self.event_received = True

    def successReward(self):
        self.value = 10
        self.event_received = True

    def onFrontTactilTouched(self, *_args):
        """
            Callback method for FrontTactilTouched event
        """
        if not(self.event_received):
            self.positiveReward()

    def onRearTactilTouched(self, *_args):
        """
            Callback method for RearTactilTouched event
        """
        if not(self.event_received):
            self.negativeReward()
开发者ID:dsapandora,项目名称:qnao,代码行数:58,代码来源:reward.py

示例12: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
 def __init__(self, name,motionMaestro):
   ALModule.__init__(self, name)
   self.motionMaestro=motionMaestro
   self.name=name
   self.tts = ALProxy("ALTextToSpeech")
   global memory
   memory = ALProxy("ALMemory")
   memory.subscribeToEvent("SonarLeftDetected",name,"sonarLeftHandler")
   memory.subscribeToEvent("SonarRightDetected",name,"sonarRightHandler")
   print "subbed to RL"
开发者ID:TabTabTab,项目名称:NAO_AI_Project,代码行数:12,代码来源:SonarRLModule.py

示例13: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
 def __init__(self, name):
     ALModule.__init__(self, name)
     
     self.tts  = ALProxy("ALTextToSpeech")
     self.tts.say("Starting speech detection")
     
     
     global memory
     memory = ALProxy("ALMemory")
     memory.subscribeToEvent("WordRecognized", "SpeechDetector", "onSpeechDetected")
开发者ID:pieterwolfert,项目名称:HRI,代码行数:12,代码来源:speechDetectModule.py

示例14: __init__

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
    def __init__(self, name):
        ALModule.__init__(self, name)

        # Create proxies for the instance.
        self.motion = ALProxy("ALMotion")
        
        # Run behaviour when a tactile touched.
        global memory
        memory = ALProxy("ALMemory")
        memory.subscribeToEvent("TouchChanged", self.getName(), "emotive_motion")
开发者ID:mikemcfarlane,项目名称:nao-emotional-framework,代码行数:12,代码来源:emotional_motion_PAD_prototype.py

示例15: ConversationModule

# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import subscribeToEvent [as 别名]
class ConversationModule(ALModule):
    def __init__(self, name):
        ALModule.__init__(self, name)

        self.tts = ALProxy("ALTextToSpeech")
        self.ears = ALProxy("ALSpeechRecognition")
        self.memory = ALProxy("ALMemory")
        self.log = ALProxy("ALLogger")

        self.ears.subscribe("Conversation")
        self.memory.subscribeToEvent("WordRecognized", "Conversation", "onWordRecognized")

    def onWordRecognized(self, key, value, message):
        """
        Subscribe to change in mood
        :param key: memory key
        :param value: memory value
        :param message: message of the event
        :return:
        """

        self.ears.unsubscribe("Conversation")

        self.tts.say("I recognized %s" % value)

        self.ears.subscribe("Conversation")

        pass

    def setMood(self, value):
        """
        Sets the current mood felt by the robot
        :param value: Mood value 1=good, 0=neutral, -1=bad
        :return:
        """
        self.__previousMood = self.__mood
        self.__mood = Mood(value)

        self.memory.raiseEvent("Brain/Mood/Text", self.__mood.text)
        self.memory.raiseEvent("Brain/Mood/Value", self.__mood.value)
        pass

    def getMood(self):
        """
        Gets the current mood
        :return:
        """
        return self.__mood

    def getPreviousMood(self):
        """
        Gets the previous mood
        :return:
        """
        return self.__previousMood
开发者ID:kevywilly,项目名称:nao,代码行数:57,代码来源:conversation.py


注:本文中的naoqi.ALProxy.subscribeToEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。