Can someone help me create a Python script to record positions in the event of a power loss or LinuxCNC error?
I plan to create an external real-time position logger with an update interval of 0.001 seconds. I use this feature for a wirecut machine. I'm using a Python script and have tried activating log_position_to_txt.py with the M-code command, but the position logging process results in a code overflow, causing the .txt file to grow uncontrollably.
Here's the code for log_position_to_txt.py:
##############################
#!/usr/bin/env python2.7
import linuxcnc
import time
stat = linuxcnc.stat()
with open("position-log.txt", "w") as outfile:
while True:
stat.poll()
x,y,z,a,b,c,u,v,w = stat.actual_position
outfile.write("X ")
outfile.write("{:.4f}\n".format(x))
outfile.write("Y ")
outfile.write("{:.4f}\n".format(y))
time.sleep(0.001)
####################################
Can someone help me fix my Python script so that... position recording does not result in code accumulation?