0

我在 Windows 上使用 Choregraphe 为我的 NAO 机器人使用 Python 实现程序。我有两个我自己无法解决的问题:

  1. 我想在 NAO 机器人上创建一个文本文件并在其中写入信息。后来我想把它存储到我的电脑上。导致这篇文章 -阅读文本文件

我在 Python Box 中使用了以下代码:

import logging
 filepath = os.path.join(os.path.dirname(ALFrameManager.getBehaviorPath(self.behaviorId)), "fileName.txt")
maybeContains = None
try:
    with open(filepath, "r") as textfile:
        maybeContains = textfile.readlines()
except:
    pass
with open(filepath, "a") as textfile:
    if maybeContains == "":
        agenda = "type1;type2;\n"
        textfile.write(agenda)
        textfile.write(storedData)
    else:
        textfile.write(storedData)
self.onStopped()

当我尝试通过“连接”>“高级”>“文件传输”下载文件“fileName.txt”时,列出的订单之一中没有该文件。

  1. 我还想在机器人上创建一个文本文件来记录编码中的信息,这样我就可以检查机器人的动作。如 1. 我想将日志字段下载到计算机。

我在“Say Text”框的 onLoad() 方法中添加了以下代码:

     def onLoad(self):
    self.logging.basicConfig(filename="20180712.log", format='%(asctime)s %(levelname)s-8s [%(filename)s:%(lineno)d]%(message)s', level=logging.DEBUG)
self.logger = self.logging.getLogger("Behavior - Box") `

    Before a command, which should be logged I call
    `    self.logger("what happened here")
4

1 回答 1

1

“连接 > 高级 > 文件传输”在特定位置打开文件。取决于您的机器人的版本。几年前它是 "/var/www" 或 "~/ftp/" ...

在我当前的 NAO (2.1) 中,它位于“/home/nao”中。

所以在我的例子中,好的方法是在这个地方创建文件:

filepath = "/home/nao/myfile.txt"

话虽这么说,有更好的方法从你的机器人获取文件,在 windows 上,你可以使用 winscp (gui) 或 pscp (cli),它比 Choregraphe 方便得多......

祝你好运。

于 2018-07-16T10:44:34.027 回答