Python NAO 机器人的脚本连接
Python Script connection to NAO Robot
我项目的目标是对 NAO 机器人进行编程,以使用神经网络检测和识别机器人。我在 MatLab 中使用神经网络对对象进行分类,我正在编写脚本以通过 Python 中的 NAO 机器人捕获图像。我有所有必要的导入(来自 naoqi 的 ALProxy、来自 PIL 的图像、随机、时间、os、sys、cv2 和 vision_definitions)并在 [=24] 中配置了 ip 和端口=] 每个代理的代码(postureProxy、motionProxy、speechProxy、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 地址,或使用网络浏览器打开它即可。
我项目的目标是对 NAO 机器人进行编程,以使用神经网络检测和识别机器人。我在 MatLab 中使用神经网络对对象进行分类,我正在编写脚本以通过 Python 中的 NAO 机器人捕获图像。我有所有必要的导入(来自 naoqi 的 ALProxy、来自 PIL 的图像、随机、时间、os、sys、cv2 和 vision_definitions)并在 [=24] 中配置了 ip 和端口=] 每个代理的代码(postureProxy、motionProxy、speechProxy、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 地址,或使用网络浏览器打开它即可。