G Codes first created 03/02/12 - last modified 03/02/12 Page Author: Ty Harness
G-Codes are a kind of standard language adopted by Numerical Control (NC) Machine Tool (M/T) manufacturers to control the M/T via a series of commands. Originally the G-Codes were fed into the M/T via punched card or paper tape and then when computers became readily available the Gcodes could be transferred to the M/T via floppy discs or a direct serial link.

It's rare these days for M/T programmer to have to handle G Codes directly as all new M/Ts will come with some sophisticated graphical input software which will control all of the M/T parameters. Or you can buy additional Computer Aided Manufacture (CAM) software to suit your needs such as JetCAM[2]. It would be unusual for the software not to except a DXF file, but by no means is DXF the de facto standard. DXF is an AutoDesk file format for storing graphical information like lines and circles and offers no instructions on how to control a M/T. So any CAM software interprets the line, circles to G code.

For historical fun I have included a function that will export some simple G-Code which might be a useful starting point if you have NC laser cutting M/T or milling/routing. TyGraphs has no real ability to program a CNC Lathe. For a water jet/laser cutting machine you typically only have 2 axes to control X and Y. For milling or routing you need to control the z height of the tool so you can set a plunge depth and a Datum Z height so the tool will clear any obstacles while rapid traversing. As a programmer you should also read and trace through every line of the Gcode because you can so easily damage the M/T.

text here text here
Figure 1a - Generating G-Code. 1b)Simulate the cutting path.


Using the TyGraphs Software:

Import/Draw a polyline which represents the tool path. Figure 1 shows a simple triangle.

Go to Plate and choose the size of your work piece or M/T bed which just gives you a spatial sense of what's happening.

Go to Gcodes on the menu bar.

--> Set Datum

--> Set the plunge depth if you are milling or routing. Note this value is incremental from the home position Z value. Don't forget to compensate for tool length. If it's just 2 axes leave Z = 0.

--> User defined burn sequence allows you to cut a defined sequence of objects rather than just the order they were created by the software.

-->Simulate Cutting will show you the order the Gcodes will be created. The yellow path shows G00 rapid traverse although M/T manufactures do not guarantee G00 will go direct from A to B which can be dangerous for hitting clamps or holding down studs/fixtures. The Red Path simulates the G1 command. You should edit the G code file and insert the correct speed and feed rates for your materials and tooling. You can also see the tool has not been compensated for. So you can the finished triangle would too small. The kerf width of a laser M/T can probably be neglected but you'll need to offset the polyline to compensate for the radius of milling cutter or router bit. Also if your making many parts you'll be measuring the finished items regularly and you'll need to compensate for tool wear.

-->Press Generate Gcode.

Figure 1 shows the simplest Gcode file.

{G-Code Generated from the TyGraphs23 software}
G91 {Incremental Programming}
G00 {rapid traverse}
X50.000 Y50.000
M03 {Laser On}
G1
X400.000 Y0.000
G1
X-400.000 Y300.000
G1
X0.000 Y-300.000
M05 {Laser OFF}
M30 {End of Program return to top}


When there's multiple polylines the software rapid traverses between polylines. Figure 2 shows the G00 path is not intelligent therefore from a laser cutting sense the laser must be turned off for rapid traversing.

{G-Code Generated from the TyGraphs software}
{Important: Check this program very carefully }
{Important: You may need to add speed and feed}
G71 {Metric Programming}
G91 {Incremental Postioning}
G00 {rapid traverse}
X89.317 Y39.930
M03 {Laser On}
G01 X200.000 Y0.000
G01 X0.000 Y100.000
G01 X-200.000 Y0.000
G01 X0.000 Y-100.000
M05 {Laser OFF}
G00 {rapid traverse}
X216.903 Y151.936
M03 {Laser On}
G01 X200.000 Y0.000
G01 X0.000 Y100.000
G01 X-200.000 Y0.000
G01 X0.000 Y-100.000
M05 {Laser OFF}
M30 {End of Program return to top}


text here
Figure 2 - Simulated cutting of multiple objects


For a milling point of view the spindle can remain turned on but the cutter must be rasied out of the work peice before lateral traversing.

{G-Code Generated from the TyGraphs software}
{Important: Check this program very carefully }
{Important: You may need to add speed and feed}
G71 {Metric Programming}
G91 {Incremental Postioning}
M03 {Spindle On}
G00 {rapid traverse}
X89.317 Y39.930
G01 Z-25.000
{Feeding into workpeice you will need to add a feed comand} G01 X200.000 Y0.000
G01 X0.000 Y100.000
G01 X-200.000 Y0.000
G01 X0.000 Y-100.000
G00 Z25.000
{Rapid feed out of workpeice} G00 {rapid traverse}
X216.903 Y151.936
G01 Z-25.000
G01 X200.000 Y0.000
G01 X0.000 Y100.000
G01 X-200.000 Y0.000
G01 X0.000 Y-100.000
G00 Z25.000
M05 {Spindle OFF}
M30 {End of Program return to top}


Of course the above examples are trivial and can easily be typed in by hand but the sheet metal patterns developed by the applications with possibly 100 or more line segments would be very tedious.

text here
Figure 3 - Nested Segmental Bend Patterns


Nested Seg B G code.

The TyGraphs software is not the 'be all and end all' of CADCAM software it's limited to just polylines consisting of just line segments because that's what my sheet metal applications produce. I would like to add arc/circle G2 at some stage. Unfortunately there is no tool cutter compensation other than you can scale the polyline larger or smaller to compensate for the tool diameter. Also I would like to add multiple tooling selection.

Often traditional machinists who understand how to operate a lathe and milling machine make the best CNC programmers because G Codes are trivial in comparison to learning how to use a machine, material handling, safe operation, etc. Don't be fooled into thinking CADCAM software is going to solve all your machining needs.
[Home] [TyGraphs]
References

[1] wikipedia
[2] JetCam Website