本文整理汇总了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)
示例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)
示例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)
示例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)
示例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")
示例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")
示例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")
示例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")
示例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 !
示例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")
示例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()
示例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"
示例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")
示例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")
示例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