Well, thanks to SoD and Dave S I have written a little Python wizard to generate g-code for knurling for any length. The first try for simplicity as shown above I just cut a full lead length, which for a diamond knurl is pi x diameter of stock. Even for 12.7mm this is nearly 40mm long which is much too long for practical purposes – larger diameter knurls would be very wasteful. I realised though that if one made a knurl with an integer number of diamonds in the axial direction you can cut each "tooth" with just a zig-zag motion where the work rotates for say N teeth axially while it moves N diamonds axially, then continues to rotate for another N teeth while it moves back N diamonds. What one would then like to do is just cut another zig-zag an carry on until one has gone right round the blank, without having to make a pure rotational move to index to the next tooth. With a bit of playing around for this to happen the number of teeth and number of diamonds have to be "relatively prime", that is have no common factor other than 1. Or, one can just make the number of teeth "M" prime, in which case any number of axial diamonds up to (M-1) can be cut just with repeated zig-zag moves. I think this is the easiest approach since there isn't a particular reason to have any specific number as long as the knurl looks and feels right.
For my previous example M=37 is a nearby prime to 42 – I wanted something rather smaller than 42 to get a coarser pattern, 37 gives about a 1.08mm pitch. Here's the Python code.
import math
# Python program to generate G Code for a diamond knurl using a rotary axis on the mill.
# Parameters required:
# Initial stock diameter
# Number of circumferential "teeth" – this should be PRIME
# Length of knurl defined as the number of longitudinal teeth
# Feedrate
# Horizontal axis height above machine zero.
diameter = float(input("Stock diameter: ")
teeth = int(input("# teeth (prime): ")
length = int(input("# axial diamonds: ")
feed = float(input("feedrate: " ))
Z_feedrate = float(input("Downfeed rate; ")
height = float(input("axis height: ")
name = input("Output filename: " #include .txt or other extension
# Now do geometry calcs
pi = 4*math.atan(1)
lead = pi * diameter
tooth_angle = 360 / teeth
L_pitch = lead / teeth
X_feed = round(length*L_pitch,3)
A_feed = round(length*tooth_angle,3)
Z_feed = round((diameter / (2*math.sqrt(2)))*(1 – math.sqrt(2)*math.sin(pi*(.25-1/teeth))),3)
Z_safe = height + diameter/2 + 1
# print(lead, tooth_angle, L_pitch, X_feed, A_feed, Z_feed, Z_safe)
myFile = open(name, 'a'
# Now start generating g-code
print(f"G0 G49 G40 G17 G80 G50 G90", file = myFile)
print(f"G00 Z", Z_safe, file = myFile)
print(f"G00 X0 Y0", file = myFile)
print(f"G91", file = myFile)
print(f"G00 A",5, file = myFile)
print(f"G01 Z", -1-Z_feed, " F", Z_feedrate, file = myFile)
count = 0
print(f"F", feed, file = myFile)
while count < teeth:
print(f"G01 X",X_feed," A", A_feed, " (", count, "", file = myFile)
print(f"G01 X", -X_feed," A", A_feed, file = myFile)
count += 1
print(f"G90", file = myFile)
print(f"G00 Z", Z_safe, file = myFile)
print(f"M5 M30", file = myFile)
myFile.close()
******ing Smileys! They should be closing brackets.
Thonny is free and comes as the built-in tool on the R-Pi, but I also use it on my PC. When you run it it asks for various parameters of the cut as listed, and the name of the file you want to put the results in (which will be in the same folder as the code). To get a text file include .txt on the end of the name. Note that the machine should be referenced so that X=0 is at the start or the knurl and Y=0 is on the A-axis. Z=0 for the tool tip is the machine table.
Edited By John Haine on 12/09/2021 09:50:51
Edited By John Haine on 12/09/2021 09:57:17
Edited By John Haine on 12/09/2021 09:58:32