pythonnao-robot

Python Script connection to NAO Robot


The goal of my project is to program the NAO robot to detect and recognize robots using a neural network. I am using a neural network in MatLab to classify the objects and I am writing scripts for capturing an image through the NAO Robot in Python. I have all of the necessary imports (ALProxy from naoqi, Image from PIL, random, time, os, sys, cv2, and vision_definitions) and have configured the ip and the port in the python code for each proxy (postureProxy, motionProxy, speechProxy, anspeechProxy, sprecogProxy, memoryProxy, and photoCaptureProxy).

try:
    photoCaptureProxy = ALProxy("ALPhotoCapture", ip, port)
    #this was done for each proxy listed above
except Exception, error:
    print("Connection error: ", error)

I printed out the error if I had any problems with connection and I did. I got a received notice of an error as follows:

RuntimeERror('\tALBroker::createBroker\n\tCannot connect to tcp://ip:port',))

I know since TCP is involved it, something is going wrong with the wired connection between the computer and the NAO Robot. Are there any fixes for this problem?

Here is a larger segment of code below:

ip = "192.168.208.254"
port = 9559

#ALProxy setups
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)
except Exception, error:
   print("Connection error: ", error)

resolution = vision_definitions.kVGA
colorSpace = vision_definitions.kYUVColorSpace
fps = 30

Solution

  • It looks like your ip variable's value is "ip" and not the actual IP address of your robot; same for the port. The port variable should be 9559 (unless you're working with virtual robots).

    If not, you may want to show a larger code snippet.

    (edit, now that there is a larger snippet)

    When I try that code I get something with

    Cannot connect to tcp://192.168.208.254:9559
    

    So the error message you show doesn't seem to be match the code (or something strange is going on - maybe you have an older version of the python SDK that displays error messages differently).

    It is possible that your computer is just not on the same network as the robot - just ping that IP address in command line, or open it with a web browser, to be sure.