G-code best practices – Smithy CNC Mills User Manual
Page 70

SmithyCNC Programmer’s Reference Manual: G-Code Best Practices
SmithyCNC Programmer’s Reference Manual: G-Code Best Practices
7-2
G-CODE BEST PRACTICES
7.1 Use an appropriate decimal precision
Use at least 3 digits after the decimal when milling in millimeters, and at least 4
digits after the decimal when milling in inches. In particular, arc tolerance
checks are made to .001 and .0001 depending on the active units.
7.2 Use consistent white space
G-code is most legible when at least one space appears before words. While it is
permitted to insert whitespace in the middle of numbers, there is no reason
to do so.
7.3 Prefer "Center-format" arcs
Center-format arcs (which use I- J- K- instead of R-) behave more consistently
than R-format arcs, particularly for included angles near 180 or 360 degrees.
7.4 Put important modal settings at the top of the file
When correct execution of your program depends on modal settings, be sure to
set them at the beginning of the part program. Modes can carry over from pre-
vious programs and from the MDI commands.
As a good preventative measure, put a line similar to the following at the top of
all your programs:
G17 G20 G40 G49 G54 G80 G90 G94
(XY plane, inch mode, cancel diameter compensation, cancel length offset, coor-
dinate system 1, cancel motion, non-incremental motion, feed/minute mode)
Perhaps the most critical modal setting is the distance units--If you do not
include G20 or G21, then different machines will mill the program at different
scales. Other settings, such as the return mode in canned cycles may also be
important.
7.5 Don't put too many things on one line
Ignore everything in Section [sec:Order-of-Execution], and instead write no line
of code that is the slightest bit ambiguous. Similarly, don't use and set a param-
eter on the same line, even though the semantics are well defined. (Exception: