gpt4 book ai didi

Python 脚本连接到 NAO 机器人

转载 作者:行者123 更新时间:2023-11-28 18:09:37 25 4
gpt4 key购买 nike

我项目的目标是对 NAO 机器人进行编程,以使用神经网络检测和识别机器人。我在 MatLab 中使用神经网络对对象进行分类,我正在编写脚本以通过 Python 中的 NAO 机器人捕获图像。我拥有所有必要的导入(来自 naoqi 的 ALProxy、来自 PIL 的图像、随机、时间、操作系统、系统、cv2 和 vision_definitions),并在 python 代码中为每个代理(postureProxy、motionProxy、speechProxy)配置了 ip 和端口、anspeechProxy、sprecogProxy、memoryProxy 和 photoCaptureProxy)。

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

如果我遇到任何连接问题,我会打印出错误,我确实做到了。我收到了如下错误通知:

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

我知道因为涉及到 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

最佳答案

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

如果没有,您可能想要显示更大的代码片段。

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

当我尝试该代码时,我得到了一些东西

Cannot connect to tcp://192.168.208.254:9559

所以您显示的错误消息似乎与代码不匹配(或者发生了一些奇怪的事情 - 也许您使用的是旧版本的 python SDK,它以不同的方式显示错误消息)。

您的计算机可能与机器人不在同一个网络上 - 只需在命令行中 ping 该 IP 地址,或使用网络浏览器打开它即可。

关于Python 脚本连接到 NAO 机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51502607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com