本文整理汇总了Python中naoqi.ALProxy.unsubscribeToEvent方法的典型用法代码示例。如果您正苦于以下问题:Python ALProxy.unsubscribeToEvent方法的具体用法?Python ALProxy.unsubscribeToEvent怎么用?Python ALProxy.unsubscribeToEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类naoqi.ALProxy
的用法示例。
在下文中一共展示了ALProxy.unsubscribeToEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SpeechRecoModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class SpeechRecoModule(ALModule):
#""" A module to use speech recognition """
def __init__(self, name):
ALModule.__init__(self, name)
try:
self.asr = ALProxy("ALSpeechRecognition")
except Exception as e:
self.asr = None
self.memory = ALProxy("ALMemory")
def onLoad(self):
from threading import Lock
self.bIsRunning = False
self.mutex = Lock()
self.hasPushed = False
self.hasSubscribed = False
self.BIND_PYTHON("SpeechReco", "onWordRecognized")
def onUnload(self):
from threading import Lock
self.mutex.acquire()
try:
if (self.bIsRunning):
if (self.hasSubscribed):
self.memory.unsubscribeToEvent("WordRecognized", "SpeechReco")
if (self.hasPushed and self.asr):
self.asr.popContexts()
except RuntimeError, e:
self.mutex.release()
raise e
self.bIsRunning = False;
self.mutex.release()
示例2: ReactionModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class ReactionModule(ALModule):
""" A basic module to test events """
def __init__(self, name):
ALModule.__init__(self, name)
self.name = name
self.tts = ALProxy("ALTextToSpeech")
self.posture = ALProxy("ALRobotPosture")
self.memory = ALProxy("ALMemory")
self.memory.subscribeToEvent("HandDetectedEvent", name, "handleDetection")
def handleDetection(self, key, value, message):
""" A method that handles detection of the ball. """
self.memory.unsubscribeToEvent("HandDetectedEvent", self.name)
if value == 0 and self.posture.getPostureFamily() != "Sitting":
self.posture.goToPosture("Sit", 1.0)
elif value == 1 and self.posture.getPostureFamily() != "Standing":
self.posture.goToPosture("Stand", 1.0)
self.memory.subscribeToEvent("HandDetectedEvent", self.name, "handleDetection")
def disconnect(self):
try:
self.memory.unsubscribeToEvent("HandDetectedEvent", self.getName())
except BaseException, err:
print "Error while disconnecting from gesture reaction module: " + str(err)
示例3: NAOVoiceRec
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [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: RedBallDetectionModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [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")
示例5: SpeechDetectionModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [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)
示例6: _SubscriberModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [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)
示例7: __init__
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [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 !
示例8: Golf
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class Golf(ALModule):
def __init__(self, name, robotIP, port):
ALModule.__init__(self, name)
self.robotIP = robotIP
self.port = port
self.memory = ALProxy("ALMemory")
self.motion = ALProxy("ALMotion")
self.posture = ALProxy("ALRobotPosture")
self.memory.subscribeToEvent("ALChestButton/TripleClickOccurred", "myGolf", "chestButtonPressed")
self.memory.subscribeToEvent("FrontTactilTouched", "myGolf", "frontTactilTouched")
self.memory.subscribeToEvent("MiddleTactilTouched", "myGolf", "middleTactilTouched")
self.memory.subscribeToEvent("RearTactilTouched", "myGolf", "rearTactilTouched")
self.memory.subscribeToEvent("robotHasFallen", "myGolf", "fallDownDetected")
def frontTactilTouched(self):
print "frontTactilTouched!!!!!!!!!!!!!"
self.memory.unsubscribeToEvent("FrontTactilTouched", "myGolf")
global holeFlag
holeFlag = 1
self.memory.subscribeToEvent("FrontTactilTouched", "myGolf", "frontTactilTouched")
def middleTactilTouched(self):
print "middleTactilTouched!!!!!!!!!!!!!!!!!!"
self.memory.unsubscribeToEvent("MiddleTactilTouched", "myGolf")
global holeFlag
holeFlag = 2
self.memory.subscribeToEvent("MiddleTactilTouched", "myGolf", "middleTactilTouched")
def rearTactilTouched(self):
print "rearTactilTouched!!!!!!!!!!!!!!!!!!"
self.memory.unsubscribeToEvent("RearTactilTouched", "myGolf")
global holeFlag
holeFlag = 3
self.memory.subscribeToEvent("RearTactilTouched", "myGolf", "rearTactilTouched")
def chestButtonPressed(self):
print "chestButtonPressed!!!!!!!!!!!!!!!!"
self.memory.unsubscribeToEvent("ALChestButton/TripleClickOccurred", "myGolf")
global holeFlag
holeFlag = 0
self.motion.angleInterpolationWithSpeed("LHand", 0.8, 1)
time.sleep(2)
self.motion.angleInterpolationWithSpeed("LHand", 0.2, 1)
self.motion.rest()
self.memory.subscribeToEvent("ALChestButton/TripleClickOccurred", "myGolf", "chestButtonPressed")
def fallDownDetected(self):
print "fallDownDetected!!!!!!!!!!!!!!!!"
self.memory.unsubscribeToEvent("robotHasFallen", "myGolf")
global robotHasFallenFlag
robotHasFallenFlag = 1
self.posture.goToPosture("StandInit", 0.5)
releaseStick(self.robotIP, self.port)
time.sleep(15)
catchStick(self.robotIP, self.port)
standWithStick(0.1, self.robotIP, self.port)
self.memory.subscribeToEvent("robotHasFallen", "myGolf", "fallDownDetected")
示例9: Reward
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [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()
示例10: main
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
def main(robotIp,robotPort):
sensor = ALProxy("ALSensors",robotIp,robotPort)
memory = ALProxy("ALMemory",robotIp,robotPort)
sensor.subscribe("myApplication")
memory.subscribeToEvent("Evento","FrontTactilTouched","FrontTactilTouched")
while 1:
ftt=memory.getData("FrontTactilTouched")
if ftt==1.0:
print "ftt"
talker("ftt")
time.sleep(3)
memory.unsubscribeToEvent("Evento","FrontTactilTouched")
sensor.unsubscribe("myApplication")
示例11: ReactToTouchModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class ReactToTouchModule(ALModule):
""" A simple module able to react to sensor events.
Leave this doc string else this module will not be bound!
"""
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
self.memory = ALProxy("ALMemory")
# Unsubscribe to event if still subscribed.
try:
self.memory.unsubscribeToEvent("TouchChanged", "ReactToTouch")
except Exception, e:
pass
self.memory.subscribeToEvent("TouchChanged", "ReactToTouch", "onTouched")
self.touched = ""
示例12: NaoModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class NaoModule(ALModule):
mySubscriptions = []
def __init__(self, name):
ALModule.__init__(self, name)
self.memory = ALProxy("ALMemory")
def getProxy(self, name):
""" get proxy """
try:
return ALProxy(name)
except:
print("could not subscribe to proxy: " + name)
def getTTS(self):
return ALProxy("ALTextToSpeech")
def getBasicAwareness(self):
return ALProxy("ALBasicAwareness")
def getAutonomousMoves(self):
return ALProxy("ALAutonomousMoves")
def exit(self):
""" exit module """
for key in self.mySubscriptions:
self.stopListeningTo(key)
ALModule.exit(self)
def listenTo(self, key, method):
""" listen to memory event """
self.memory.subscribeToEvent(key, self.getName(), method)
self.mySubscriptions.append(key)
pass
def stopListeningTo(self, key):
""" stop listening to memory event """
try:
self.memory.unsubscribeToEvent(key, self.getName())
except:
print("not subscribed to " + key)
pass
示例13: SetVolumeModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class SetVolumeModule(ALModule):
""" A simple module able to react to sensor events.
Leave this doc string else this module will not be bound!
"""
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
self.memory = ALProxy("ALMemory")
# Unsubscribe to event if still subscribed.
try:
self.memory.unsubscribeToEvent("FrontTactilTouched", "SetVolume")
self.memory.unsubscribeToEvent("RearTactilTouched", "SetVolume")
except Exception, e:
pass
self.memory.subscribeToEvent("FrontTactilTouched", "SetVolume", "onFrontTouched")
self.memory.subscribeToEvent("RearTactilTouched", "SetVolume", "onRearTouched")
self.audiodevice = ALProxy("ALAudioDevice")
self.tts = ALProxy("ALTextToSpeech")
示例14: speechRecognitionNaoModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class speechRecognitionNaoModule(ALModule):
""" A simple module able to react to speech events.
Leave this doc string else this module will not be bound!
"""
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
self.memory = ALProxy("ALMemory")
# Unsubscribe to event if still subscribed to stop ASR engine.
try:
self.memory.unsubscribeToEvent("WordRecognized", "SpeechRecognizer")
except Exception, e:
pass
self.asr = ALProxy("ALSpeechRecognition")
vocabulary = ["rene", "james"]
self.asr.setVocabulary(vocabulary, False )
self.asr.setVisualExpression(True)
self.word = ""
示例15: FaceRecognitionModule
# 需要导入模块: from naoqi import ALProxy [as 别名]
# 或者: from naoqi.ALProxy import unsubscribeToEvent [as 别名]
class FaceRecognitionModule(ALModule):
""" A simple module able to react to facedetection events.
Leave this doc string else this module will not be bound!
"""
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
self.memory = ALProxy("ALMemory")
# Unsubscribe to event if still subscribed.
try:
self.memory.unsubscribeToEvent("FaceDetected", "FaceRecognizer")
except Exception, e:
pass
self.tracking = ALProxy("ALTracker")
self.timeFaceDetectionStartedInSeconds = 0
self.timeFirstRecognitionInSeconds = 0
self.previousTimeInSeconds = 0
self.timeInSeconds = 0
self.face = ""
self.tracker = ALProxy("ALTracker")
self.motion = ALProxy("ALMotion")
self.leds = ALProxy("ALLeds")