到NAO Rob的Python脚本连接

2024-09-29 19:19:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我的项目的目标是用神经网络编程NAO机器人来检测和识别机器人。我使用MatLab中的神经网络对对象进行分类,并编写脚本通过Python中的NAO机器人捕捉图像。我有所有必要的导入(naoqi的ALProxy、PIL中的Image、random、time、os、sys、cv2和vision_定义),并在python代码中为每个代理(postureProxy、motionProxy、speechProxy、anspeechProxy、sprecogProxy、memoryProxy和photoCaptureProxy)配置了ip和端口。在

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

如果连接有问题,我就打印出错误。我收到一个错误通知,内容如下:

^{pr2}$

我知道由于涉及到TCP,计算机和NAO机器人之间的有线连接出了问题。这个问题有什么解决办法吗?在

下面是一段较大的代码:

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

Tags: 代码ipport机器人神经网络errorvisionnao
1条回答
网友
1楼 · 发布于 2024-09-29 19:19:33

看起来ip变量的值是“ip”,而不是机器人的实际ip地址;端口也是一样。端口变量应该是9559(除非您使用的是虚拟机器人)。在

如果没有,您可能需要显示一个更大的代码段。在

(编辑,现在有一个更大的片段)

当我尝试这个代码的时候

Cannot connect to tcp://192.168.208.254:9559

因此,您显示的错误消息似乎与代码不匹配(或者发生了一些奇怪的事情—可能您有一个旧版本的pythonsdk,它以不同的方式显示错误消息)。在

有可能你的电脑和机器人不在同一个网络上——只需在命令行中ping该IP地址,或者用web浏览器打开它。在

相关问题 更多 >

    热门问题