LinuxCNC:如何在 Python 中读取当前位置并记录到 CSV
另请参阅我们关于如何仅读取位置的文章,特别是如果你不关心 CSV 记录:LinuxCNC:如何使用 Python 查找当前位置
此脚本将大约每毫秒将位置记录到 CSV。位置将以机器坐标系记录。
log_position_to_csv.py
#!/usr/bin/env python2.7
import linuxcnc
import datetime
import time
stat = linuxcnc.stat()
with open("position-log.csv", "w") as outfile:
while True:
dt = datetime.datetime.now()
stat.poll()
x,y,z,a,b,c,u,v,w = stat.actual_position
outfile.write("{},{:.4f},{:.4f},{:.4f}\n".format(dt.isoformat(), x, y, z))
time.sleep(0.001)If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow