NAO robot: places where output functions of boxes are defined

416 views Asked by At

I am wondering where are output functions of NAO behavior boxes usually defined.

I simply failed to find any related documentation in API. There are some you can find indeed, but not for output functions.

Take Speech Reco box for example, I can find definition of function "WordRecognized" on online API, but not the "wordRecognized" (case sensitive) and the "onNothing". Intuition is that they define them as helpers in the script of the box (which you can get by double-clicking on the box), but I just failed to find any relevant implementation of those either in the script.

Anyone had this before and know the solution? I really appreciate any feedback since I want to inspect how they are defined.

Code for Speech Reco is as below, and this situation happens for some other boxes too:

class MyClass(GeneratedClass):

def __init__(self):
    GeneratedClass.__init__(self, False)
    try:
        self.asr = ALProxy("ALSpeechRecognition")
    except Exception as e:
        self.asr = None
        self.logger.error(e)
    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(self.getName(), "onWordRecognized")

def onUnload(self):
    from threading import Lock
    self.mutex.acquire()
    try:
        if (self.bIsRunning):
            if (self.hasSubscribed):
                self.memory.unsubscribeToEvent("WordRecognized", self.getName())
            if (self.hasPushed and self.asr):
                self.asr.popContexts()
    except RuntimeError, e:
        self.mutex.release()
        raise e
    self.bIsRunning = False;
    self.mutex.release()

def onInput_onStart(self):
    from threading import Lock
    self.mutex.acquire()
    if(self.bIsRunning):
        self.mutex.release()
        return
    self.bIsRunning = True
    try:
        if self.asr:
            self.asr.setVisualExpression(self.getParameter("Visual expression"))
            self.asr.pushContexts()
        self.hasPushed = True
        if self.asr:
            self.asr.setVocabulary( self.getParameter("Word list").split(';'), self.getParameter("Enable word spotting") )
        self.memory.subscribeToEvent("WordRecognized", self.getName(), "onWordRecognized")
        self.hasSubscribed = True
    except RuntimeError, e:
        self.mutex.release()
        self.onUnload()
        raise e
    self.mutex.release()

def onInput_onStop(self):
    if( self.bIsRunning ):
        self.onUnload()
        self.onStopped()

def onWordRecognized(self, key, value, message):
    if(len(value) > 1 and value[1] >= self.getParameter("Confidence threshold (%)")/100.):
        self.wordRecognized(value[0]) #~ activate output of the box
    else:
        self.onNothing()
1

There are 1 answers

0
Alexandre Mazel On

Those methods are defined when you create or edit a box input or output. See this piece of documentation.

If you give the input the name "onMyTruc", then the method onInput_onMyTruc(self) will be called when the input is triggered.

If you give the name "output_value" to some output, it will create a callable method name: self.output_value()

In your example, wordRecognized and onNothing are the name of the output of the SpeechReco box.