我在 Windows 上使用 Choregraphe 为我的 NAO 机器人使用 Python 实现程序。我有两个我自己无法解决的问题:
- 我想在 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. 我想将日志字段下载到计算机。
我在“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")