Search code examples
pythonevent-handlingdelaylednao-robot

Naoqi eventhandling 10 Secounds delay


I am working with a NAO-robot on a Windows-XP machine and Python 2.7.

I want to detect markers in speech. The whole thing worked, but unfortunately I have to face now a 10 Secounds delay and my events aren't detected (the callback function isnt invoked).

First, my main-function:

from naoqi import ALProxy, ALBroker
from speechEventModule import SpeechEventModule
myString = "Put that \\mrk=1\\ there."
NAO_IP = "192.168.0.105" 
NAO_PORT = 9559
memory = ALProxy("ALMemory", NAO_IP, NAO_PORT)
tts = ALProxy("ALTextToSpeech", NAO_IP, NAO_PORT)
tts.enableNotifications()

myBroker = ALBroker("myBroker",
   "0.0.0.0",   # listen to anyone
   0,           # find a free port and use it
   NAO_IP,         # parent broker IP
   NAO_PORT)       # parent broker port

global SpeechEventListener
SpeechEventListener = SpeechEventModule("SpeechEventListener", memory)
memory.subscribeToEvent("ALTextToSpeech/CurrentBookMark", "SpeechEventListener", "onBookmarkDetected")
tts.say(initialString)

And here my speechEventModule:

from naoqi import ALModule
from naoqi import ALProxy

NAO_IP = "192.168.0.105" 
NAO_PORT = 9559

SpeechEventListener = None
leds = None
memory = None

class SpeechEventModule(ALModule):
    def __init__(self, name, ext_memory):
        ALModule.__init__(self, name)
        global memory
        memory = ext_memory
        global leds 
        leds = ALProxy("ALLeds",NAO_IP, NAO_PORT)        

    def onBookmarkDetected(self, key, value, message):
        print "Event detected!"
        print "Key: ", key
        print "Value: " , value
        print "Message: " , message

        if(value == 1):
            global leds
            leds.fadeRGB("FaceLeds", 0x00FF0000, 0.2)
        if(value == 2):
            global leds
            leds.fadeRGB("FaceLeds", 0x000000FF, 0.2)

Please, do anybody have the same problem? Can anybody give me an advice?

Thanks in advance!


Solution

  • You are subscribing to the event outside your module. if I am not wrong you have to do it into the __init__ method.

    class SpeechEventModule(ALModule):
    
        def __init__(self, name, ext_memory):
            ALModule.__init__(self, name)
            memory = ALProxy("ALMemory")
            leds = ALProxy("ALLeds")
    

    Anyway, check that your main function keeps running forever (better if you catch a keyboard interruption) or you program will end before he can catch any keyword.

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print
        print "Interrupted by user, shutting down"
        myBroker.shutdown()
        sys.exit(0)
    

    Take a look to this tutorial, it could be helpful.