Hi Terry,
Took a look at the code. Since the X axis has to change speed as the A rotates (since tangential speed changes as you change distance from centre) I broke the X axis moves into fractions and used a sub to repeat it. Please see attached screenshot, I hope it will clarify what I meant. In the picture, a, is my X variable and it changes with the angle. I call in the code the ABsegment as single segment and this is then broken into smaller segments depending on the resolution.
I have also made a couple of changes to the code so it will match the sketch and be more readable. Here is the revised one:
%
G0 G49 G40 G17 G80 G50 G90
(A axis is in revolution mode)
(Program in Diameter mode)
#1 = 6 (number of sides)
#2 = 10 (distance across flats)
#3 = 120 (feed: mm/min)
#4 = 0.1 (Z feed per revolution)
#9 = 10 (length along Z)
#17 = 10 (resolution - number of segments in half flat size)
#5 = [360/#1] (root angle)
#6 = [2*[0.5*#2]/cos[0.5*#5]] (distance across corners)
; Not used #7 = [[0.5*#2]*tan[0.5*#5]] (half side length)
#10 = [0.5*#5] (single segment revolution angle of A axis)
#11 = [#10/#17] (single rotation fraction angle of A)
#16 = #11
#12 = [[-1*[#4/[#1*2]]]/#17] (Z advance per segment)
#13 = #12
G0 X[#2+1] A0
G0 Z1
G1 X#2 Z.1 F#3
#14 = [-1*[#4/#1]] (Z advance per main subroutine execution)
#15 = FIX[#9/#14] (Number of subroutine executions required - 'L')
M98 P100 L#15
M30
O100
M98 P101 L#17
#16 = #11
M98 P102 L#17
M99
O101
G1 X[2*[0.5*#2]/cos[#16]] A#16/360 Z#13 (A converted fromdegrees to revolutions)
#16 = [#16 + #11]
#13 = [#13 + #12]
M99
O102
G1 X[2*[0.5*#2]/cos[0.5*#5-#16]] A#16/360 Z#13 (A converted fromdegrees to revolutions)
#16 = [#16 + #11]
#13 = [#13 + #12]
M99
%