Skip to content
g-code.rst 79.6 KiB
Newer Older
Fabrice Salvaire's avatar
Fabrice Salvaire committed
G Codes
=======

Conventions
-----------

Conventions used in this section

Fabrice Salvaire's avatar
Fabrice Salvaire committed
In the G code prototypes the hyphen (``-``) stands for a real value and (``<>``) denotes an optional
Fabrice Salvaire's avatar
Fabrice Salvaire committed
item.

Fabrice Salvaire's avatar
Fabrice Salvaire committed
If ``L-`` is written in a prototype the ``-`` will often be referred to as the ``L number``, and so on for
Fabrice Salvaire's avatar
Fabrice Salvaire committed
any other letter.

Fabrice Salvaire's avatar
Fabrice Salvaire committed
In the G code prototypes the word ``axes`` stands for any axis as defined in your configuration.
Fabrice Salvaire's avatar
Fabrice Salvaire committed
An optional value will be written like this ``<L→``.
Fabrice Salvaire's avatar
Fabrice Salvaire committed

A real value may be:

Fabrice Salvaire's avatar
Fabrice Salvaire committed
* An explicit number, ``4``
* An expression, ``[2+2]``
* A parameter value, ``#88``
* A unary function value, ``acos[0]``
Fabrice Salvaire's avatar
Fabrice Salvaire committed
In most cases, if ``axis`` words are given (any or all of ``X Y Z A B C U V W``), they specify a
Fabrice Salvaire's avatar
Fabrice Salvaire committed
destination point.

Axis numbers are in the currently active coordinate system, unless explicitly described as being in
the absolute coordinate system.

Where axis words are optional, any omitted axes will retain their original value.

Any items in the G code prototypes not explicitly described as optional are required.

The values following letters are often given as explicit numbers. Unless stated otherwise, the
Fabrice Salvaire's avatar
Fabrice Salvaire committed
explicit numbers can be real values. For example, ``G10 L2`` could equally well be written ``G[2*5]
L[1+1]``. If the value of parameter 100 were 2, ``G10 L#100`` would also mean the same.
Fabrice Salvaire's avatar
Fabrice Salvaire committed
If ``L-`` is written in a prototype the ``-`` will often be referred to as the ``L number``, and so on for
Fabrice Salvaire's avatar
Fabrice Salvaire committed
any other letter.

G Code Quick Reference Table
----------------------------

==================================== ===========================================
Code                                 Description
==================================== ===========================================
Fabrice Salvaire's avatar
Fabrice Salvaire committed
`G0 <gcode_g0>`_                     Coordinated Motion at Rapid Rate
Fabrice Salvaire's avatar
Fabrice Salvaire committed
`G1 <#gcode:g1>`__                   Coordinated Motion at Feed Rate
`G2 G3 <#gcode:g2-g3>`__             Coordinated Helical Motion at Feed Rate
`G4 <#gcode:g4>`__                   Dwell
`G5 <#gcode:g5>`__                   Cubic Spline
`G5.1 <#gcode:g5.1>`__               Quadratic B-Spline
`G5.2,G5.3 <#gcode:g5.2-g5.3>`__     NURBS, add control point
`G7 <#gcode:g7>`__                   Diameter Mode (lathe)
`G8 <#gcode:g8>`__                   Radius Mode (lathe)
`G10 L1 <#gcode:g10-l1>`__           Set Tool Table Entry
`G10 L10 <#gcode:g10-l10>`__         Set Tool Table, Calculated, Workpiece
`G10 L11 <#gcode:g10-l11>`__         Set Tool Table, Calculated, Fixture
`G10 L2 <#gcode:g10-l2>`__           Coordinate System Origin Setting
`G10 L20 <#gcode:g10-l20>`__         Coordinate System Origin Setting Calculated
`G17 - G19.1 <#gcode:g17-g19.1>`__   Plane Select
`G20 G21 <#gcode:g20-g21>`__         Set Units of Measure
`G28 - G28.1 <#gcode:g28-g28.1>`__   Go to Predefined Position
`G30 - G30.1 <#gcode:g30-g30.1>`__   Go to Predefined Position
`G33 <#gcode:g33>`__                 Spindle Synchronized Motion
`G33.1 <#gcode:g33.1>`__             Rigid Tapping
`G38.2 - G38.5 <#gcode:g38>`__       Probing
`G40 <#gcode:g40>`__                 Cancel Cutter Compensation
`G41 G42 <#gcode:g41-g42>`__         Cutter Compensation
`G41.1 G42.1 <#gcode:g41.1-g42.1>`__ Dynamic Cutter Compensation
`G43 <#gcode:g43>`__                 Use Tool Length Offset from Tool Table
`G43.1 <#gcode:g43.1>`__             Dynamic Tool Length Offset
`G43.2 <#gcode:g43.2>`__             Apply additional Tool Length Offset
`G49 <#gcode:g49>`__                 Cancel Tool Length Offset
`G53 <#gcode:g53>`__                 Move in Machine Coordinates
`G54-G59.3 <#gcode:g54-g59.3>`__     Select Coordinate System (1 - 9)
`G61 G61.1 <#gcode:g61-g61.1>`__     Path Control Mode
`G64 <#gcode:g64>`__                 Path Control Mode with Optional Tolerance
`G73 <#gcode:g73>`__                 Drilling Cycle with Chip Breaking
`G74 <#gcode:g74>`__                 Left-hand Tapping Cycle with Dwell
`G76 <#gcode:g76>`__                 Multi-pass Threading Cycle (Lathe)
`G80 <#gcode:g80>`__                 Cancel Motion Modes
`G81 <#gcode:g81>`__                 Drilling Cycle
`G82 <#gcode:g82>`__                 Drilling Cycle with Dwell
`G83 <#gcode:g83>`__                 Drilling Cycle with Peck
`G84 <#gcode:g84>`__                 Right-hand Tapping Cycle with Dwell
`G85 <#gcode:g85>`__                 Boring Cycle, No Dwell, Feed Out
`G86 <#gcode:g86>`__                 Boring Cycle, Stop, Rapid Out
`G89 <#gcode:g89>`__                 Boring Cycle, Dwell, Feed Out
`G90 G91 <#gcode:g90-g91>`__         Distance Mode
`G90.1 G91.1 <#gcode:g90.1-g91.1>`__ Arc Distance Mode
`G92 <#gcode:g92>`__                 Coordinate System Offset
`G92.1 G92.2 <#gcode:g92.1-g92.2>`__ Cancel G92 Offsets
`G92.3 <#gcode:g92.3>`__             Restore G92 Offsets
`G93 G94 G95 <#gcode:g93-g94-g95>`__ Feed Modes
`G96 <#gcode:g96-g97>`__             Spindle Control Mode
`G98 G99 <#gcode:g98-g99>`__         Canned Cycle Z Retract Mode
==================================== ===========================================

G0 Rapid Move
-------------

Fabrice Salvaire's avatar
Fabrice Salvaire committed
.. code:: text
Fabrice Salvaire's avatar
Fabrice Salvaire committed
For rapid motion, program ``G0 axes``, where all the axis words are optional. The ``G0`` is optional if
the current motion mode is ``G0``. This will produce coordinated motion to the destination point at
the maximum rapid rate (or slower). ``G0`` is typically used as a positioning move.
Fabrice Salvaire's avatar
Fabrice Salvaire committed

Rapid Velocity Rate
~~~~~~~~~~~~~~~~~~~

The MAX_VELOCITY setting in the ini file [TRAJ] section defines the maximum rapid traverse rate. The
maximum rapid traverse rate can be higher than the individual axes MAX_VELOCITY setting during a
coordinated move. The maximum rapid traverse rate can be slower than the MAX_VELOCITY setting in the
[TRAJ] section if an axis MAX_VELOCITY or trajectory constraints limit it.

G0 Example

Fabrice Salvaire's avatar
Fabrice Salvaire committed
.. code:: text
Fabrice Salvaire's avatar
Fabrice Salvaire committed

   G90 (set absolute distance mode)
   G0 X1 Y-2.3 (Rapid linear move from current location to X1 Y-2.3)
   M2 (end program)

* See `G90 <#gcode:g90-g91>`__ & `M2 <#mcode:m2-m30>`__ sections for more information.

If cutter compensation is active, the motion will differ from the above; see the `Cutter
Compensation <#sec:cutter-compensation>`__ Section.

Fabrice Salvaire's avatar
Fabrice Salvaire committed
If ``G53`` is programmed on the same line, the motion will also differ; see the `G53 <#gcode:g53>`__
Fabrice Salvaire's avatar
Fabrice Salvaire committed
Section for more information.

The path of a G0 rapid motion can be rounded at direction changes and depends on the `trajectory
control <#sec:trajectory-control>`__ settings and maximum acceleration of the axes.

Fabrice Salvaire's avatar
Fabrice Salvaire committed
**It is an error if:**
Fabrice Salvaire's avatar
Fabrice Salvaire committed

* An axis letter is without a real value.
* An axis letter is used that is not configured

G1 Linear Move
--------------

Fabrice Salvaire's avatar
Fabrice Salvaire committed
.. code:: text
Fabrice Salvaire's avatar
Fabrice Salvaire committed

   G1 axes

For linear (straight line) motion at programed `feed rate <#sec:set-feed-rate>`__ (for cutting or
Fabrice Salvaire's avatar
Fabrice Salvaire committed
not), program ``G1 ``axes````, where all the axis words are optional. The ``G1`` is optional if the
current motion mode is ``G1``. This will produce coordinated motion to the destination point at the
Fabrice Salvaire's avatar
Fabrice Salvaire committed
current feed rate (or slower).

G1 Example

Fabrice Salvaire's avatar
Fabrice Salvaire committed
.. code:: text
Fabrice Salvaire's avatar
Fabrice Salvaire committed

   G90 (set absolute distance mode)
   G1 X1.2 Y-3 F10 (linear move at a feed rate of 10 from current position to X1.2 Y-3)
   Z-2.3 (linear move at same feed rate from current position to Z-2.3)
   Z1 F25 (linear move at a feed rate of 25 from current position to Z1)
   M2 (end program)

Fabrice Salvaire's avatar
Fabrice Salvaire committed
* See `G90 <#gcode:g90-g91>`__ & `F <#sec:set-feed-rate>`__ & `M2 <#mcode:m2-m30>`__ sections for
  more information.
Fabrice Salvaire's avatar
Fabrice Salvaire committed

If cutter compensation is active, the motion will differ from the above; see the `Cutter
Compensation <#sec:cutter-compensation>`__ Section.

Fabrice Salvaire's avatar
Fabrice Salvaire committed
If ``G53`` is programmed on the same line, the motion will also differ; see the `G53 <#gcode:g53>`__
Fabrice Salvaire's avatar
Fabrice Salvaire committed
Section for more information.

Fabrice Salvaire's avatar
Fabrice Salvaire committed
**It is an error if:**
Fabrice Salvaire's avatar
Fabrice Salvaire committed

* No feed rate has been set.
* An axis letter is without a real value.
* An axis letter is used that is not configured

G2, G3 Arc Move
---------------

Fabrice Salvaire's avatar
Fabrice Salvaire committed
.. code:: text
Fabrice Salvaire's avatar
Fabrice Salvaire committed

   G2 or G3 axes offsets (center format)
   G2 or G3 axes R- (radius format)
   G2 or G3 offsets|R- <P-> (full circles)

Fabrice Salvaire's avatar
Fabrice Salvaire committed
A circular or helical arc is specified using either ``G2`` (clockwise arc) or ``G3`` (counterclockwise
Fabrice Salvaire's avatar
Fabrice Salvaire committed
arc) at the current `feed rate <#sec:set-feed-rate>`__. The direction (CW, CCW) is as viewed from
the positive end of the axis about which the circular motion occurs.

The axis of the circle or helix must be parallel to the X, Y, or Z axis of the machine coordinate
Fabrice Salvaire's avatar
Fabrice Salvaire committed
system. The axis (or, equivalently, the plane perpendicular to the axis) is selected with ``G17``
(Z-axis, XY-plane), ``G18`` (Y-axis, XZ-plane), or ``G19`` (X-axis, YZ-plane). Planes ``17.1``, ``18.1``,
and ``19.1`` are not currently supported. If the arc is circular, it lies in a plane parallel to the
Fabrice Salvaire's avatar
Fabrice Salvaire committed
selected plane.

Loading full blame...