LinuxCNC G-code practice
What carries over from any control
A program that only uses the core codes runs the same on LinuxCNC and on a Fanuc-style control: G21 G17 G90, G54, G43 H1, G81 and M3 S1200 all mean the same. That makes LinuxCNC, which is free and has a simulator, a good place to learn the common G-codes before working on industrial machines.
Codes and words that are LinuxCNC's own
These are documented in the LinuxCNC G-code reference. Fanuc does the same jobs with different codes, or in parameters.
| Code or word | What it does |
|---|---|
O100 sub … endsub | A named subroutine, called with O100 call [arguments]. Also O-word if/else, while and repeat loops. |
#<depth> | Named parameters, readable in place of numbered # variables. |
G64 P0.01 | Path blending with a tolerance: corners may be rounded by up to P to keep speed up. G61 is exact path. |
G33.1 | Rigid tapping, synchronised with the spindle. Fanuc uses M29 with G84 for the same job. |
G7 / G8 | Lathe diameter mode or radius mode for X. |
G90.1 / G91.1 | Arc centres I, J, K as absolute positions or as distances from the start point (the usual default). |
M62 to M66 | Switch digital outputs (synchronised with motion or immediately) and wait on inputs. |
M100 to M199 | User-defined M-codes: each runs a script you write, for example to drive a fixture. |
Where Fanuc habits trip you up
- M98 / M99 are not the usual subprogram call. Older LinuxCNC versions do not read Fanuc-style M98/M99 at all; recent ones accept a limited form. O-word call is the native way.
- Macro B does not run. Fanuc # variable logic with IF … GOTO is written as O-word if/while on LinuxCNC.
- Strict about errors. LinuxCNC stops on things some controls let through, such as an arc whose end point does not match its radius within tolerance.
Habits that help
- Use the preview before you run. The toolpath plot in AXIS or Gmoccapy shows a wrong offset or a sign error before the tool moves.
- Keep the tool table and G43 together. G43 without an H uses the loaded tool's entry; know which entry that is.
- Write subroutines with names. O<pocket> call reads better a year later than O100 call.
Quiz: the core codes, as LinuxCNC reads them
Mill and lathe: what does this code do?
G03
Codes and options vary by control version and machine builder. Check the manual for your machine before running a program.
Frequently asked questions
- Can LinuxCNC run Fanuc G-code programs?
- Programs that use the core codes, yes. Programs with Macro B logic, Fanuc-specific cycle parameters or machine-builder M-codes need porting: logic becomes O-words, and M-codes are set up in your configuration.
- What G-codes are unique to LinuxCNC?
- The best known are the O-word subroutines and loops, named parameters, G33.1 rigid tapping, G64 with a P tolerance, G7/G8 diameter and radius mode on lathes, G90.1/G91.1 for arc centres, M62 to M66 for I/O, and M100 to M199 user M-codes.
- Is LinuxCNC good for learning G-code for a job?
- Yes. It is free, runs a simulator on an ordinary PC, and its documentation is public. The core codes transfer directly to Fanuc, Haas and similar machines.
G-Code Sprint is an educational practice tool only. It is not a CNC simulator, machine controller, safety manual, or replacement for instruction. Always follow your instructor, employer, machine manual, and shop procedures.