Search code examples
python-2.7nao-robot

Defining NAOqi ALProxy Proxies


I have written a python script for the NAO Robot so that it can take a photo. I have written the import from naoqi import ALProxy and wrote out the a try statement as follows:

try:
    postureProxy = ALProxy("ALRobotPosture", ip, port)
    motionProxy = ALProxy("ALMotion", ip, port)
    speechProxy = ALProxy("ALTextToSpeech", ip, port)
    anspeechProxy = ALProxy("ALAnimatedSpeech", ip, port)
    sprecogProxy = ALProxy("ALSpeechRecognition", ip, port)
    memoryProxy = ALProxy("ALMemory", ip, port)
    photoCaptureProxy = ALProxy("ALPhotoCapture", ip, port)

Later in my script, I have the following:

sprecogProxy.setLanguage("English")

I get an error saying:

NameError: name 'sprecogProxy' is not defined Also, later in my code I refer to the speech Proxy as I say :

speechProxy.say("Place the object in the view")

I get the same error. Earlier my program was working correctly and all of a sudden I am getting this error. Is there anything that can be done to mitigate this program so that this script can run consistently? Please let me know if there is a need for more information.


Solution

  • This looks like an error in your Python, like you're trying to use a variable that was never created (for example one of your ALProxy objects raised an exception at creation, so it never reached the part where it creates sprecogProxy).