Looking good fenrus! I’ll review your code for comments in a minute.
I have my first draft typed up here:
It’s in python, and also about an hour old
I have a plan for automatic tests, but have ran into an issue: In the original version of the routine, Fusion performed G0 plunges beneath the feed height. I don’t know how to detect that this is OK (I think that fusion is able to do so because they know that they already milled out that material).
Unfortunately, unless we can nail down how to replicate this behavior, we’ll have to manually validate everything.
I’ve manually inspected a diff of my result with the “good” source and found that it matches perfectly (minus a few comments Fusion adds, etc, as well as the plunge issue above and a minor bug which results in a few seconds of G1 at the start of each toolpath, so a tiny bit slower but nbd)
For my code, the relevant logic can be almost completely described by this snippet of code, which should be almost self-evident:
conditionMovingDownPastClearance = zAtEndOfLine[i] < feedHeightCurrent and zAtEndOfLine[i] < zAtStartOfLine[i]
conditionMovingLaterallyBelowClearance = (zAtEndOfLine[i] < clearanceHeightCurrent or zAtEndOfLine[i] < zAtEndOfLine[i]) and (xAtStartOfLine[i]!=xAtEndOfLine[i] or yAtStartOfLine[i] != yAtEndOfLine[i] )
bInsertG0BecauseVerticalUp=xAtStartOfLine[i]==xAtEndOfLine[i] and yAtStartOfLine[i]==yAtEndOfLine[i] and zAtEndOfLine[i]>=clearanceHeightCurrent and newGmode != 'G0' and lineGmodes[i]=='G1'
bInsertG0BecauseLateralAbove=xAtStartOfLine[i]!=xAtEndOfLine[i] and yAtStartOfLine[i]!=yAtEndOfLine[i] and zAtEndOfLine[i]>=clearanceHeightCurrent and zAtStartOfLine[i]>=clearanceHeightCurrent and newGmode != 'G0' and lineGmodes[i]=='G1'
bSwitchToG1=(conditionMovingDownPastClearance or conditionMovingLaterallyBelowClearance) and newGmode == 'G0' and lineGmodes[i] == 'G1'
# if the current line does not move X or Y, and ends above the clearance height and is a G1 op, switch to G0
# if the current line does move X and/or Y, but starts and ends above the clearance height, switch to G0
if bInsertG0BecauseVerticalUp or bInsertG0BecauseLateralAbove:
[newGmode, tokensLine] = addStartOfG0(tokensLine)
# if the reassigned gMode (at the end of the upcoming line) is different from G1,
# .... and the gMode at the start of the line was a G0
# .... and the Z at the end of the line is less than the clearance height
# .... set it to a G1
[newGmode, tokensLine] = addStartOfG1(tokensLine, fAtEndOfLine[i])
alreadyChangedModes = True
@fenrus thoughts on the plunge issue? It would be really nice to have an automated path to testing this in the event of future updates.
Want me to post the other 6 test projects (about 12 *.nc files)