I have run out of time tonight, but this is close.
In the INI file add this to the [FILTER] section
Code:
PROGRAM_EXTENSION = .foam foam
foam = /home/{YOUR USERNAME}/linuxcnc/filter.py
Now save this at that path as filter.py
Code:
#! /usr/bin/python
import re
import sys
import math
infile = sys.argv[1]
f = open(infile, 'r')
feedrate = 1
X = 0.0
Y = 0.0
U = 0.0
V = 0.0
oldX = X
oldY = Y
oldU = U
oldV = V
for line in f:
Ff = re.match(r".*F\s*([\d\.,]+)", line)
Xf = re.match(r".*X\s*([\d\.,]+)", line)
Yf = re.match(r".*Y\s*([\d\.,]+)", line)
Uf = re.match(r".*U\s*([\d\.,]+)", line)
Vf = re.match(r".*V\s*([\d\.,]+)", line)
G1f = re.match(r".*G\s*0*1\D", line)
if Xf:
X = float(Xf.group(1))
if Yf:
Y = float(Yf.group(1))
if Uf:
U = float(Uf.group(1))
if Vf:
V = float(Vf.group(1))
hXY = math.sqrt((oldX-X)**2 + (oldY-Y)**2)
hUV = math.sqrt((oldU-U)**2 + (oldV-V)**2)
if hXY > hUV and hXY != 0:
F93 = float(feedrate / hXY)
elif hUV != 0:
F93 = float(feedrate / hUV)
if Ff:
feedrate = float(Ff.group(1))
print "( feedrate = %f)" % feedrate
print "G93"
elif G1f:
print "%s F%f" % (line.rstrip(), F93)
else:
print line.rstrip()
oldX = X
oldY = Y
oldU = U
oldV = V
print "M2"
Now any gcode file with a .foam extension will run through that filter, example output:
It probably needs work, I am not sure that my G93 feedrate calculation is correct, but the structure is there.