Using G-Code with an EtherCAT based EtherCAT Master for Industrial applications

November 7, 2022

Nikolas Gamarra

G-Code History

G-Code (Geometric Code) is the most commonly used programming language for commanding the tool path for CNC machines (computer numerical control) from traditional mills, lathes, and routers to water jets, plasma cutters, and 3D. Since its conception in the 1950s at MIT, it has provided a more standardized way of providing a machine with motion commands across the manufacturing industry. It was quickly adopted by the manufacturing industry as its simplicity and customizability made it ideal for various manufacturing methods. Standardizing on one language has the advantage of allowing a G-Code program prepared for one machine to be used on another with minimal to no adjustments. Due to its simplicity, versatility, prolific adoption across the manufacturing industry, and use in modern additive manufacturing techniques like 3D printing, G-Code will likely be with us for ages to come. 

Related Software Tools

For complex parts, it is common practice to have CAM (Computer Aided Manufacturing) software generate your G-Code file for you. CAM software can handle complex calculations such as following a spline using many small line segments, which would be too tedious to program by typing the G-Code. Using CAM (or a slicer for 3D printing), you can import a 3D model file exported by your CAD (Computer Aided Design) software and semi-automatically generate the complex G-Code files needed to make the part. 

Common Commands

Simple motion paths can be programmed in manually using lines(G1) and arcs(G2/3) in either a relative(G91) or absolute(G90) positioning mode. Values for X, Y, and Z can then be provided; excluded arguments will be assumed to be the current absolute location. The optional F command will update the current move's targeted feed rate (3D velocity vector). It will accelerate/decelerate at the rate you configure to this velocity.

G01 - Linear Interpolation

Move in a straight line in 3D space.

G02 & G03 - Circular Interpolation

Move clockwise (G2) or counterclockwise (G3) in an arc around a center point to the endpoint.

F - Feed rate

The feed rate command can be added on the same line as a motion command or a line of its own. It will set the targeted max vector velocity in 3D space in your program's units per minute.

G90 & G91 -  Absolute and Incremental

G90(absolute) and 91(relative) change how all specified coordinates should be interpreted. They will be relative to the endpoint of the last command in relative mode. They will always be relative to the machine origin (0,0,0) in absolute mode. 

G20 & G21 - Units

G20(inches) and G21(millimeters) change how all specified coordinates and feed rates should be interpreted. These commands only matter if you want to configure the User Units of your machine differently than those used by G-Code. 

G-Code and RMP

Our G-Code interpreter will handle the parsing of G-Code syntax for you and build up a cartesian motion path using our path motion API. Building our G-Code feature off our path motion API has allowed us to support controlling various machine types with arbitrary kinematic models, including articulated robots with G-Code. Our G-Code API also saves end users from directly managing complex real-time motion streaming.

Our Rapid Setup tool provides a basic G-Code UI with a 3D render of the planned path so that you can test our API can read your G-Code file without having to write any code. 

On this page

start developing today!

1000+ customers have already automated with help of our products and team