Skip to content
......@@ -21,6 +21,9 @@
.. |LinuxCNC| replace:: Linux CNC
.. _LinuxCNC: http://linuxcnc.org/docs/2.7/html/gcode/overview.html
.. |NIST| replace:: NIST
.. _NIST: https://www.nist.gov
.. |Machinekit| replace:: Machinekit
.. _Machinekit: http://www.machinekit.io
......
......@@ -2,7 +2,7 @@
####################################################################################################
#
# PythonicGcodeMachine - @licence_header_description@
# PythonicGcodeMachine - A Python G-code Toolkit
# Copyright (C) 2018 Fabrice Salvaire
#
####################################################################################################
......@@ -313,4 +313,4 @@ intersphinx_mapping = {'http://docs.python.org/': None}
# https://github.com/jdillard/sphinx-sitemap
#
site_url = '@project_url@' # could use setup_dict
site_url = 'https://github.com/FabriceSalvaire/pythonic-gcode-machine' # could use setup_dict
......@@ -7,7 +7,7 @@
==============
G-Code Parser
-------------
=============
The RS-274 parser is generated automatically from the grammar defined in the paper |NIST-RS-274|_
(Appendix E) using the generator `PLY <https://www.dabeaz.com/ply/ply.html>`_ which implement a
......@@ -19,6 +19,92 @@ The parser construct an `abstract syntax tree (AST)
User can subclass this parser to support a derived G-code flavour.
G-code flavours
---------------
===============
The different flavours are partly handled in |YAML|_ files.
G-code Generation and Simulation
================================
Computational Geometry Engine
=============================
The computational geometry engine requires these features :
* import standard 2D object file, e.g. SVG and DXF
* import standard 3D object file, e.g. STL
* 2D path erosion and dilation, e.g. to compute cutter radius compensation
* 2D/3D Minkowski sum along a path
* 3D extrusion
* 3D Boolean operation : object - tool path
List of the Main Open Source Computational Geometry Algorithms Libraries
------------------------------------------------------------------------
The Computational Geometry Algorithms Library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
`CGAL <https://www.cgal.org>`_ is a software project that provides easy access to efficient and
reliable geometric algorithms in the form of a C++ library. CGAL is used in various areas needing
geometric computation, such as geographic information systems, computer aided design, molecular
biology, medical imaging, computer graphics, and robotics.
CGAL is used in:
* many academic projects
* `OpenSCAD <http://www.openscad.org>`_
Git repository and Python binding:
* https://github.com/CGAL/cgal
* https://github.com/CGAL/cgal-swig-bindings
* https://github.com/sciencectn/cgal-bindings
STL (STereoLithography) format support:
* https://en.wikipedia.org/wiki/STL_(file_format)
* https://doc.cgal.org/latest/Polyhedron/classCGAL_1_1Polyhedron__incremental__builder__3.html
* include/CGAL/IO/Polyhedron_builder_from_STL.h
* https://github.com/CGAL/cgal/blob/master/Polyhedron/demo/Polyhedron/Plugins/IO/STL_io_plugin.cpp
* demo/Polyhedron/Plugins/IO/STL_io_plugin.cpp
* https://github.com/CGAL/cgal/blob/master/Polyhedron_IO/include/CGAL/IO/STL_reader.h
* include/CGAL/IO/STL_reader.h
* include/CGAL/IO/STL_writer.h
Open CASCADE
~~~~~~~~~~~~
* https://www.opencascade.com
* `Open CASCADE Community Edition <https://github.com/tpaviot/oce>`_
* https://github.com/tpaviot/pythonocc-core — python wrapper
Open CASCADE is used in:
* `Salome <http://www.salome-platform.org>`_
* `FreeCAD <https://freecadweb.org>`_
.. `code_aster <https://www.code-aster.org>`_
G-code Visualisation
====================
The open source `Qt <https://www.qt.io>`_ framework provide a multi-platform User Interface framework with 3D support.
* `Qt 3D <https://doc.qt.io/qt-5/qt3d-index.html>`_
Qt 3D provides functionality for near-realtime simulation systems with support for 2D and 3D rendering in both Qt C++ and Qt Quick applications.
* `QMesh Class <https://doc.qt.io/qt-5/qt3drender-qmesh.html>`_
QMesh supports the following formats:
* Wavefront OBJ
* Stanford Triangle Format PLY
* STL (STereoLithography)
* Autodesk FBX if the SDK is installed
.. -*- mode: rst -*-
PythonicGcodeMachine features:
* a compliant RS-274 / ISO G-code parser which is automatically generated from grammar and easy to
derivate to support other flavours,
* an abstract syntax tree (AST) API,
* some G-code flavour aspects are handled by YAML files for maximum flexibility,
* tools to manipulate and validate G-code,
* and more ..
PythonicGcodeMachine supports these G-code flavours:
* RS-274 **(full support)**
* Fanuc *(partially)*
* Heidenhain *(partially)*
* LinuxCNC *(partially)*
.. include:: ../abbreviation.txt
.. _gcode-reference-page:
==================
G-code Reference
==================
.. toctree::
rs-274/index.rst
linuxcnc/index.rst
= Coordinate Systems
[[cha:coordinate-system]]
== Introduction
This chapter introduces you to offsets as they are used by the LinuxCNC.
These include:
* Machine Coordinates (G53)
* Nine Coordinate System Offsets (G54-G59.3)
* Global Offsets (G92) and Local Offsets (G52)
[[sec.machine-corrdinate-system]]
== Machine Coordinate System
When LinuxCNC is started the postions of each axis is the machine origin. Once
an axis homed the the machine orgin for that axis is set to the homed position.
The machine origin is the machine coordinate system which all other coordinate
systems are based. The <<gcode:g53,G53>> G code can be used to move in the
machine coordinate system.
== Coordinate Systems
.Example of Coordinate Systems
image::images/offsets.png[align="center", alt="Example of Coordinate Systems"]
.Coordinate System Offsets
* G54 - use coordinate system 1
* G55 - use coordinate system 2
* G56 - use coordinate system 3
* G57 - use coordinate system 4
* G58 - use coordinate system 5
* G59 - use coordinate system 6
* G59.1 - use coordinate system 7
* G59.2 - use coordinate system 8
* G59.3 - use coordinate system 9
Coordinate system offsets are used to shift the coordinate system from the
machine coordinate system. This allows the G code to be programmed for the
part without regard to the part location on the machine. Using coordinate
system offsets would allow you to machine parts in multiple locations with the
same G code.
The values for offsets are stored in the VAR file that is requested by the INI
file during the startup of an LinuxCNC.
In the VAR file scheme, the first variable number stores the X offset,
the second the Y offset and so on for all nine axes. There are numbered
sets like this for each of the coordinate system offsets.
Each of the graphical interfaces has a way to set values for these
offsets. You can also set these values by editing the VAR file itself
and then restart LinuxCNC so that the LinuxCNC reads the new values
however this is not the recommended way. Using G10, G52, G92, G28.1,
etc are better ways to set the variables.
.Example of G55 parameters
[width="40%",cols="^,^,^",options="header"]
|====
|Axis | Variable | Value
| X |5241 |2.000000
| Y |5242 |1.000000
| Z |5243 |-2.000000
| A |5244 |0.000000
| B |5245 |0.000000
| C |5246 |0.000000
| U |5247 |0.000000
| V |5248 |0.000000
| W |5249 |0.000000
|====
You should read this as moving the zero positions of G55 to X = 2
units, Y= 1 unit, and Z = -2 units away from the absolute zero position.
Once there are values assigned, a call to G55 in a program block would
shift the zero reference by the values stored. The following line would
then move each axis to the new zero position. Unlike G53, G54 through
G59.3 are modal commands. They will act on all blocks of code after one
of them has been set. The program that might be run using
fixture offsets would require only a single coordinate
reference for each of the locations and all of the work to be done
there. The following code is offered as an example of making a square
using the G55 offsets that we set above.
----
G55 ; use coordinate system 2
G0 X0 Y0 Z0
G1 F2 Z-0.2000
X1
Y1
X0
Y0
G0 Z0
G54 ; use coordinate system 1
G0 X0 Y0 Z0
M2
----
In this example the G54 near the end leaves the G54 coordinate system with all
zero offsets so that there is a modal code for the absolute machine based axis
positions. This program assumes that we have done that and use the ending
command as a command to machine zero. It would have been possible to use G53
and arrive at the same place but that command would not have been modal and
any commands issued after it would have returned to using the G55 offsets
because that coordinate system would still be in effect.
=== Default Coordinate System
One other variable in the VAR file becomes important when we think
about offset systems. This variable is named 5220. In the default files
its value is set to 1.00000. This means that when the LinuxCNC starts up it
should use the first coordinate system as its default. If you set this
to 9.00000 it would use the ninth offset system as its default for
start up and reset. Any value other than an integer (decimal really)
between 1 and 9, or a missing 5220 variable will cause the LinuxCNC to
revert to the default value of 1.00000 on start up.
=== Setting Coordinate System Offsets
The G10 L2x command can be used to set coordinate system offsets:
* 'G10 L2 P(1-9)' - Set offset(s) to a value. Current position irrelevant.
(see <<gcode:g10-l2,G10 L2>> for details)
* 'G10 L20 P(1-9)' - Set offset(s) so current position becomes a value.
(see <<gcode:g10-l20,G10 L20>> for details)
== Local and Global Offsets[[sec:g52-and-g92-offsets]]
=== The G52 command[[sec:g52]]
'G52' is used in a part program as a temporary "local coordinate
system offset" within the workpiece coordinate system. An example use
case is when machining several identical features at different
locations on a part. For each feature, 'G52' programs a local
reference point within workpiece coordinates, and a subprogram is
called to machine the feature relative to that point.
'G52' axis offsets are programmed relative to workpiece coordinate
offsets 'G54' through 'G59.3'. As a local offset, 'G52' is applied
after the workpiece offset, including rotation. Thus, a part feature
will be machined identically on each part regardless of the part's
orientation on the pallet.
[CAUTION]
As a temporary offset, set and unset within the localized scope of a
part program, in other g-code interpreters 'G52' does not persist
after machine reset, 'M02' or 'M30'. In LinuxCNC, 'G52' shares
parameters with 'G92', which, for historical reasons, *does* persist
these parameters. See <<sec:g92-persistence-cautions,G92 Persistence
Cautions>> below.
[CAUTION]
'G52' and 'G92' share the same offset registers. Therefore, setting
'G52' will override any earlier 'G92' setting, and 'G52' will persist
across machine reset when 'G92' persistence is enabled. These
interactions may result in unexpected offsets. See
<<sec:g92-g52-interaction-cautions,G92 and G52 Interaction Cautions>>
below.
Programming 'G52 X1 Y2' offsets the current workpiece coordinate
system X axis by 1 and Y axis by 2. Accordingly, on the DRO, the
current tool position's X and Y coordinates will be reduced by 1 and
2, respectively. Axes unset in the command, such as Z in the previous
example, will be unaffected: any previous 'G52' Z offset will remain
in effect, and otherwise the Z offset will be zero.
The temporary local offset may be canceled with 'G52 X0 Y0'. Any axes
not explicitly zeroed will retain the previous offset.
'G52' shares the same offset registers as 'G92', and thus
'G52' is visible on the DRO and preview labeled with 'G92'.
=== The G92 commands[[sec:g92-commands]]
'G92' is typically used in two conceptually different ways: as a
"global coordinate system offset" or as a "local coordinate system
offset". The 'G92' set of commands includes:
* 'G92' - This command, when used with axis names, sets values to offset
variables.
* 'G92.1' - This command sets zero values to the G92 variables.
* 'G92.2' - This command suspends but does not zero out the G92
variables.
* 'G92.3' - This command applies offset values that have been suspended.
As a global offset, 'G92' is used to shift all workpiece coordinate
systems 'G54' through 'G59.3'. An example use case is when machining
several identical parts in fixtures with known locations on a pallet,
but the pallet location may change between runs or between machines.
Each fixture location offset, relative to a reference point on the
pallet, is preset in one of the workpiece coordinate systems, 'G54'
through 'G59.3', and 'G92' is used to "touch off" on the pallet
reference point. Then, for each part, the corresponding workpiece
coordinate system is selected and the part program is executed.
[NOTE]
'G10 R-' workpiece coordinate system rotation is specific to the
'rs274ngc' interpreter, and the 'G92' offset is applied 'after'
rotation. When using 'G92' as a global offset, workpiece coordinate
system rotations may have unexpected results.
As a local coordinate system, 'G92' is used as a temporary offset
within the workpiece coordinate system. An example use case is when
machining a part with several identical features at different
locations. For each feature, 'G92' is used to set a local reference
point, and a subprogram is called to machine the feature starting at
that point.
[NOTE]
The use of 'G92' is discouraged for programming with local coordinate
systems in a part program. Instead, see <<sec:g52,'G52'>>, a local
coordinate system offset more intuitive when desired offset relative
to the workpiece is known but current tool location may not be known.
Programming 'G92 X0 Y0 Z0' sets the current tool location to the
coordinates X0, Y0, and Z0, without motion. G92 *does not* work from
absolute machine coordinates. It works from *current location*.
'G92' also works from current location as modified by any other
offsets that are in effect when the 'G92' command is invoked. While
testing for differences between work offsets and actual offsets it was
found that a 'G54' offset could cancel out a 'G92' and thus give the
appearance that no offsets were in effect. However, the 'G92' was
still in effect for all coordinates and did produce expected work
offsets for the other coordinate systems.
By default, 'G92' offsets are restored after the machine is started.
Programmers that wish for Fanuc behavior, where 'G92' offsets are
cleared at machine start and after a reset or program end, may disable
'G92' persistence by setting 'DISABLE_G92_PERSISTENCE = 1' in the
'[RS274NGC]' section of the '.ini' file.
[NOTE]
It is good practice to clear the 'G92' offsets at the end of their use
with 'G92.1' or 'G92.2'. When starting up LinuxCNC with 'G92'
persistence enabled (the default), any offsets in the 'G92' variables
will be applied when an axis is homed. See
<<sec:g92-persistence-cautions,G92 Persistence Cautions>> below.
=== Setting G92 Values
G92 commands work from current axis location and add and subtract
correctly to give the current axis position the value assigned by the
G92 command. The effects work even though previous offsets are in.
So if the X axis is currently showing 2.0000 as its position a 'G92 X0'
will set an offset of -2.0000 so that the current location of X becomes
zero. A 'G92 X2' will set an offset of 0.0000 and the displayed position
will not change. A 'G92 X5.0000' will set an offset of 3.0000 so that the
current displayed position becomes 5.0000.
=== G92 Persistence Cautions[[sec:g92-persistence-cautions]]
By default, the values of a 'G92' offset will be saved in the VAR file
and be restored after a machine reset or startup.
The G92 parameters are:
* 5210 - Enable/disable flag (1.0/0.0)
* 5211 - X Axis Offset
* 5212 - Y Axis Offset
* 5213 - Z Axis Offset
* 5214 - A Axis Offset
* 5215 - B Axis Offset
* 5216 - C Axis Offset
* 5217 - U Axis Offset
* 5218 - V Axis Offset
* 5219 - W Axis Offset
where 5210 is the 'G92' enable flag (1 for enabled, 0 for disabled)
and 5211 to 5219 are the axis offsets. If you are seeing unexpected
positions as the result of a commanded move, as a result of storing an
offset in a previous program and not clearing them at the end then
issue a G92.1 in the MDI window to clear the stored offsets.
If G92 values exist in the VAR file when LinuxCNC starts up, the G92
values in the var file will be applied to the values of the current
location of each axis. If this is home position and home position is
set as machine zero everything will be correct. Once home has been
established using real machine switches, or by moving each axis to a known
home position and issuing an axis home command, any G92 offsets will be
applied. If you have a G92 X1 in effect when you home the X axis the
DRO will read 'X: 1.000' instead of the expected 'X: 0.000' because the
G92 was applied to the machine origin. If you issue a G92.1 and the DRO
now reads all zeros then you had a G92 offset in effect when you last
ran LinuxCNC.
Unless your intention is to use the same G92 offsets in the next
program, the best practice is to issue a G92.1 at the end of any G
code files where you use G92 offsets.
When a program is aborted during processing that has 'G92' offsets in
effect a startup will cause them to become active again. As a
safeguard, always have your preamble to set the environment as you
expect it. Additionally, 'G92' persistence may be disabled by setting
'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
'.ini' file.
=== G92 and G52 Interaction Cautions[[sec:g92-g52-interaction-cautions]]
'G52' and 'G92' share the same offset registers. Unless 'G92'
persistence is disabled in the '.ini' file (see <<sec:g92-commands,G92
Commands>>), 'G52' offsets will also persist after machine reset,
'M02' or 'M30'. Beware that a 'G52' offset in effect during a program
abort may result in unintended offsets when the next program is run.
See <<sec:g92-persistence-cautions,G92 Persistence Cautions>> above.
== Sample Programs Using Offsets
=== Sample Program Using Workpiece Coordinate Offsets
This sample engraving project mills a set of four .1 radius circles in
roughly a star shape around a center circle. We can setup the
individual circle pattern like this.
---------------------------------------------------------------------
G10 L2 P1 X0 Y0 Z0 (ensure that G54 is set to machine zero)
G0 X-0.1 Y0 Z0
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
M2
---------------------------------------------------------------------
We can issue a set of commands to create offsets for the four other
circles like this.
-----------------------------------------------------------
G10 L2 P2 X0.5 (offsets G55 X value by 0.5 inch)
G10 L2 P3 X-0.5 (offsets G56 X value by -0.5 inch)
G10 L2 P4 Y0.5 (offsets G57 Y value by 0.5 inch)
G10 L2 P5 Y-0.5 (offsets G58 Y value by -0.5 inch)
-----------------------------------------------------------
We put these together in the following program:
---------------------------------------------------------------------
(a program for milling five small circles in a diamond shape)
G10 L2 P1 X0 Y0 Z0 (ensure that G54 is machine zero)
G10 L2 P2 X0.5 (offsets G55 X value by 0.5 inch)
G10 L2 P3 X-0.5 (offsets G56 X value by -0.5 inch)
G10 L2 P4 Y0.5 (offsets G57 Y value by 0.5 inch)
G10 L2 P5 Y-0.5 (offsets G58 Y value by -0.5 inch)
G54 G0 X-0.1 Y0 Z0 (center circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G55 G0 X-0.1 Y0 Z0 (first offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G56 G0 X-0.1 Y0 Z0 (second offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G57 G0 X-0.1 Y0 Z0 (third offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G58 G0 X-0.1 Y0 Z0 (fourth offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G54 G0 X0 Y0 Z0
M2
---------------------------------------------------------------------
Now comes the time when we might apply a set of G92 offsets to this
program. You'll see that it is running in each case at Z0. If the mill
were at the zero position, a G92 Z1.0000 issued at the head of the
program would shift everything an inch. You might also shift the
whole pattern around in the XY plane by adding some X and Y offsets
with G92. If you do this you should add a G92.1 command just before the
M2 that ends the program. If you do not, other programs that you might
run after this one will also use that G92 offset. Furthermore it would
save the G92 values when you shut down the LinuxCNC and they will be
recalled when you start up again.
=== Sample Program Using G52 Offsets
(To be written)
[[cha:g-codes]]
= G Codes
:ini: {basebackend@docbook:'':ini}
:hal: {basebackend@docbook:'':hal}
:ngc: {basebackend@docbook:'':ngc}
== Conventions
Conventions used in this section
In the G code prototypes the hyphen ('-') stands for a real value
and ('<>') denotes an optional item.
If 'L-' is written in a prototype the '-' will often be referred to
as the 'L number', and so on for any other letter.
In the G code prototypes the word 'axes' stands for any axis as defined
in your configuration.
An optional value will be written like this '<L->'.
A real value may be:
* An explicit number, '4'
* An expression, '[2+2]'
* A parameter value, '#88'
* A unary function value, 'acos[0]'
In most cases, if 'axis' words are given
(any or all of 'X Y Z A B C U V W'),
they specify a 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 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.
If 'L-' is written in a prototype the '-' will often be referred to
as the 'L number', and so on for any other letter.
== G Code Quick Reference Table[[gcode:quick-reference-table]]
(((G Code Table)))
[width="75%", options="header", cols="2^,5<"]
|====================================================================
|Code |Description
|<<gcode:g0,G0>> |Coordinated Motion at Rapid Rate
|<<gcode:g1,G1>> |Coordinated Motion at Feed Rate
|<<gcode:g2-g3,G2 G3>> |Coordinated Helical Motion at Feed Rate
|<<gcode:g4,G4>> |Dwell
|<<gcode:g5,G5>> |Cubic Spline
|<<gcode:g5.1,G5.1>> |Quadratic B-Spline
|<<gcode:g5.2-g5.3,G5.2,G5.3>> |NURBS, add control point
|<<gcode:g7,G7>> |Diameter Mode (lathe)
|<<gcode:g8,G8>> |Radius Mode (lathe)
|<<gcode:g10-l1,G10 L1>> |Set Tool Table Entry
|<<gcode:g10-l10,G10 L10>> |Set Tool Table, Calculated, Workpiece
|<<gcode:g10-l11,G10 L11>> |Set Tool Table, Calculated, Fixture
|<<gcode:g10-l2,G10 L2>> |Coordinate System Origin Setting
|<<gcode:g10-l20,G10 L20>> |Coordinate System Origin Setting Calculated
|<<gcode:g17-g19.1,G17 - G19.1>> |Plane Select
|<<gcode:g20-g21,G20 G21>> |Set Units of Measure
|<<gcode:g28-g28.1,G28 - G28.1>> |Go to Predefined Position
|<<gcode:g30-g30.1,G30 - G30.1>> |Go to Predefined Position
|<<gcode:g33,G33>> |Spindle Synchronized Motion
|<<gcode:g33.1,G33.1>> |Rigid Tapping
|<<gcode:g38,G38.2 - G38.5>> |Probing
|<<gcode:g40,G40>> |Cancel Cutter Compensation
|<<gcode:g41-g42,G41 G42>> |Cutter Compensation
|<<gcode:g41.1-g42.1,G41.1 G42.1>> |Dynamic Cutter Compensation
|<<gcode:g43,G43>> |Use Tool Length Offset from Tool Table
|<<gcode:g43.1,G43.1>> |Dynamic Tool Length Offset
|<<gcode:g43.2,G43.2>> |Apply additional Tool Length Offset
|<<gcode:g49,G49>> |Cancel Tool Length Offset
|<<gcode:g53,G53>> |Move in Machine Coordinates
|<<gcode:g54-g59.3,G54-G59.3>> |Select Coordinate System (1 - 9)
|<<gcode:g61-g61.1,G61 G61.1>> |Path Control Mode
|<<gcode:g64,G64>> |Path Control Mode with Optional Tolerance
|<<gcode:g73,G73>> |Drilling Cycle with Chip Breaking
|<<gcode:g74,G74>> |Left-hand Tapping Cycle with Dwell
|<<gcode:g76,G76>> |Multi-pass Threading Cycle (Lathe)
|<<gcode:g80,G80>> |Cancel Motion Modes
|<<gcode:g81,G81>> |Drilling Cycle
|<<gcode:g82,G82>> |Drilling Cycle with Dwell
|<<gcode:g83,G83>> |Drilling Cycle with Peck
|<<gcode:g84,G84>> |Right-hand Tapping Cycle with Dwell
|<<gcode:g85,G85>> |Boring Cycle, No Dwell, Feed Out
|<<gcode:g86,G86>> |Boring Cycle, Stop, Rapid Out
|<<gcode:g89,G89>> |Boring Cycle, Dwell, Feed Out
|<<gcode:g90-g91,G90 G91>> |Distance Mode
|<<gcode:g90.1-g91.1,G90.1 G91.1>> |Arc Distance Mode
|<<gcode:g92,G92>> |Coordinate System Offset
|<<gcode:g92.1-g92.2,G92.1 G92.2>> |Cancel G92 Offsets
|<<gcode:g92.3,G92.3>> |Restore G92 Offsets
|<<gcode:g93-g94-g95,G93 G94 G95>> |Feed Modes
|<<gcode:g96-g97,G96>> |Spindle Control Mode
|<<gcode:g98-g99,G98 G99>> |Canned Cycle Z Retract Mode
|====================================================================
[[gcode:g0]]
== G0 Rapid Move
(((G0 Rapid Move)))
-------------------
G0 axes
-------------------
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.
=== 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
----
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 <<gcode:g90-g91,G90>> & <<mcode:m2-m30,M2>> sections for more information.
If cutter compensation is active, the motion will differ from
the above; see the <<sec:cutter-compensation,Cutter Compensation>> Section.
If 'G53' is programmed on the same line, the motion will also differ;
see the <<gcode:g53,G53>> Section for more information.
The path of a G0 rapid motion can be rounded at direction changes and depends
on the <<sec:trajectory-control,trajectory control>> settings and maximum
acceleration of the axes.
It is an error if:
* An axis letter is without a real value.
* An axis letter is used that is not configured
[[gcode:g1]](((G1 Linear Move)))
== G1 Linear Move
-------------------
G1 axes
-------------------
For linear (straight line) motion at programed <<sec:set-feed-rate,feed rate>>
(for cutting or 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 current feed
rate (or slower).
.G1 Example
----
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)
----
* See <<gcode:g90-g91,G90>> & <<sec:set-feed-rate,F>> & <<mcode:m2-m30,M2>> sections
for more information.
If cutter compensation is active, the motion will differ from
the above; see the <<sec:cutter-compensation,Cutter Compensation>> Section.
If 'G53' is programmed on the same line, the motion will also differ;
see the <<gcode:g53,G53>> Section for more information.
It is an error if:
* No feed rate has been set.
* An axis letter is without a real value.
* An axis letter is used that is not configured
[[gcode:g2-g3]]
== G2, G3 Arc Move
(((G2, G3 Arc Move)))
----
G2 or G3 axes offsets (center format)
G2 or G3 axes R- (radius format)
G2 or G3 offsets|R- <P-> (full circles)
----
A circular or helical arc is specified using either 'G2' (clockwise
arc) or 'G3' (counterclockwise arc) at the current
<<sec:set-feed-rate,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 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 selected plane.
To program a helix, include the axis word perpendicular to the arc
plane: for example, if in the 'G17' plane, include a 'Z' word. This
will cause the 'Z' axis to move to the programmed value during the
circular 'XY' motion.
To program an arc that gives more than one full turn, use the 'P' word
specifying the number of full turns plus the programmed arc. The 'P' word
must be an integer. If 'P' is unspecified, the behavior is as if 'P1' was
given: that is, only one full or partial turn will result. For example, if a
180 degree arc is programmed with a P2, the resulting motion will be 1 1/2
rotations. For each P increment above 1 an extra full circle is added to the
programmed arc. Multi turn helical arcs are supported and give motion useful
for milling holes or threads.
If a line of code makes an arc and includes rotary axis motion,
the rotary axes turn at a constant rate so that the rotary
motion starts and finishes when the XYZ motion starts and finishes.
Lines of this sort are hardly ever programmed.
If cutter compensation is active, the motion will differ from
the above; see the <<sec:cutter-compensation,Cutter Compensation>> Section.
The arc center is absolute or relative as set by <<gcode:g90.1-g91.1,G90.1
or G91.1>> respectively.
Two formats are allowed for specifying an arc:
Center Format and Radius Format.
It is an error if:
* No feed rate has been set.
* The P word is not an integer.
=== Center Format Arcs
Center format arcs are more accurate than radius format arcs and are
the preferred format to use.
The end point of the arc along with the offset to the center of the
arc from the current location are used to program arcs that are less
than a full circle. It is OK if the end point of the arc is the same
as the current location.
The offset to the center of the arc from the current location and
optionally the number of turns are used to program full circles.
When programming arcs an error due to rounding can result from using a
precision of less than 4 decimal places (0.0000) for inch and less than
3 decimal places (0.000) for millimeters.
.Incremental Arc Distance Mode
Arc center offsets are a relative distance from the start location of the arc.
Incremental Arc Distance Mode is default.
One or more axis words and one or more offsets must be programmed for an
arc that is less than 360 degrees.
No axis words and one or more offsets must be programmed for full circles.
The 'P' word defaults to 1 and is optional.
For more information on 'Incremental Arc Distance Mode see the
<<gcode:g90.1-g91.1,G91.1>> section.
.Absolute Arc Distance Mode
Arc center offsets are the absolute distance from the current 0 position of the axis.
One or more axis words and 'both' offsets must be programmed for arcs
less than 360 degrees.
No axis words and both offsets must be programmed for full circles.
The 'P' word defaults to 1 and is optional.
For more information on 'Absolute Arc Distance Mode see the
<<gcode:g90.1-g91.1,G90.1>> section.
.XY-plane (G17)
----
G2 or G3 <X- Y- Z- I- J- P->
----
* 'Z' - helix
* 'I' - X offset
* 'J' - Y offset
* 'P' - number of turns
.XZ-plane (G18)
----
G2 or G3 <X- Z- Y- I- K- P->
----
* 'Y' - helix
* 'I' - X offset
* 'K' - Z offset
* 'P' - number of turns
.YZ-plane (G19)
----
G2 or G3 <Y- Z- X- J- K- P->
----
* 'X' - helix
* 'J' - Y offset
* 'K' - Z offset
* 'P' - number of turns
It is an error if:
* No feed rate is set with the <<sec:set-feed-rate,F>> word.
* No offsets are programmed.
* When the arc is projected on the selected plane, the distance from
the current point to the center differs from the distance from the end
point to the center by more than (.05 inch/.5 mm)
OR ((.0005 inch/.005mm) AND .1% of radius).
Deciphering the Error message 'Radius to end of arc differs from radius to start:'
* 'start' - the current position
* 'center' - the center position as calculated using the i, j, or k words
* 'end' - the programmed end point
* 'r1' - radius from the start position to the center
* 'r2' - radius from the end position to the center
=== Center Format Examples
Calculating arcs by hand can be difficult at times. One option is to
draw the arc with a cad program to get the coordinates and offsets.
Keep in mind the tolerance mentioned above, you may have to change the
precision of your cad program to get the desired results. Another
option is to calculate the coordinates and offset using formulas. As
you can see in the following figures a triangle can be formed from the
current position the end position and the arc center.
In the following figure you can see the start position is X0 Y0, the
end position is X1 Y1. The arc center position is at X1 Y0. This gives
us an offset from the start position of 1 in the X axis and 0 in the Y
axis. In this case only an I offset is needed.
.G2 Example Line
[source,{ngc}]
----
G0 X0 Y0
G2 X1 Y1 I1 F10 (clockwise arc in the XY plane)
----
.G2 Example
image::images/g2.png[align="center", alt="G2 Example"]
In the next example we see the difference between the offsets for Y if
we are doing a G2 or a G3 move. For the G2 move the start position is
X0 Y0, for the G3 move it is X0 Y1. The arc center is at X1 Y0.5 for
both moves. The G2 move the J offset is 0.5 and the G3 move the J
offset is -0.5.
.G2-G3 Example Line
[source,{ngc}]
----
G0 X0 Y0
G2 X0 Y1 I1 J0.5 F25 (clockwise arc in the XY plane)
G3 X0 Y0 I1 J-0.5 F25 (counterclockwise arc in the XY plane)
----
.G2-G3 Example
image::images/g2-3.png[align="center", alt="G2-G3 Example"]
In the next example we show how the arc can make a helix in the Z axis
by adding the Z word.
.G2 Example Helix
[source,{ngc}]
----
G0 X0 Y0 Z0
G17 G2 X10 Y16 I3 J4 Z-1 (helix arc with Z added)
----
In the next example we show how to make more than one turn using the P word.
.P word Example
----
G0 X0 Y0 Z0
G2 X0 Y1 Z-1 I1 J0.5 P2 F25
----
In the center format, the radius of the arc is not specified, but it
may be found easily as the distance from the center of the circle to
either the current point or the end point of the arc.
=== Radius Format Arcs
----
G2 or G3 axes R- <P->
----
* 'R' - radius from current position
It is not good practice to program radius format arcs that are nearly
full circles or nearly semicircles because a small change in the
location of the end point will produce a much larger change in the
location of the center of the circle (and, hence, the middle of the
arc). The magnification effect is large enough that rounding error in a
number can produce out-of-tolerance cuts. For instance, a 1%
displacement of the endpoint of a 180 degree arc produced a 7%
displacement of the point 90 degrees along the arc. Nearly full circles
are even worse. Other size arcs (in the range tiny to 165 degrees or
195 to 345 degrees) are OK.
In the radius format, the coordinates of the end point of the arc in
the selected plane are specified along with the radius of the arc.
Program 'G2' 'axes' 'R-' (or use 'G3' instead of 'G2' ). R is the
radius. The axis words are all optional except that at
least one of the two words for the axes in the selected plane must be
used. The R number is the radius. A positive radius indicates that the
arc turns through less than 180 degrees, while a negative radius
indicates a turn of more than 180 degrees. If the arc is helical, the
value of the end point of the arc on the coordinate axis parallel to
the axis of the helix is also specified.
It is an error if:
* both of the axis words for the axes of the selected plane are omitted
* the end point of the arc is the same as the current point.
.G2 Example Line
[source,{ngc}]
----
G17 G2 X10 Y15 R20 Z5 (radius format with arc)
----
The above example makes a clockwise (as viewed from the positive Z-axis)
circular or helical arc whose axis is parallel to the Z-axis, ending
where X=10, Y=15, and Z=5, with a radius of 20. If the starting value
of Z is 5, this is an arc of a circle parallel to the XY-plane;
otherwise it is a helical arc.
[[gcode:g4]]
== G4 Dwell
(((G4 Dwell)))
----
G4 P-
----
* 'P' - seconds to dwell (floating point)
The P number is the time in seconds that all axes will remain unmoving.
The P number is a floating point number so fractions of a second may be used.
G4 does not affect spindle, coolant and any I/O.
.G4 Example Line
----
G4 P0.5 (wait for 0.5 seconds before proceeding)
----
It is an error if:
* the P number is negative or not specified.
[[gcode:g5]]
== G5 Cubic Spline
(((G5 Cubic spline)))
----
G5 X- Y- <I- J-> P- Q-
----
* 'I' - X incremental offset from start point to first control point
* 'J' - Y incremental offset from start point to first control point
* 'P' - X incremental offset from end point to second control point
* 'Q' - Y incremental offset from end point to second control point
G5 creates a cubic B-spline in the XY plane with the X and Y axes only.
P and Q must both be specified for every G5 command.
For the first G5 command in a series of G5 commands, I and J must both
be specified. For subsequent G5 commands, either both I and J must be
specified, or neither. If I and J are unspecified, the starting
direction of this cubic will automatically match the ending direction of
the previous cubic (as if I and J are the negation of the previous P and
Q).
For example, to program a curvy N shape:
.G5 Sample initial cubic spline
----
G90 G17
G0 X0 Y0
G5 I0 J3 P0 Q-3 X1 Y1
----
A second curvy N that attaches smoothly to this one can now be made
without specifying I and J:
.G5 Sample subsequent cubic spline
----
G5 P0 Q-3 X2 Y2
----
It is an error if:
* P and Q are not both specified
* Just one of I or J are specified
* I or J are unspecified in the first of a series of G5 commands
* An axis other than X or Y is specified
* The active plane is not G17
[[gcode:g5.1]]
== G5.1 Quadratic Spline
(((G5.1 Quadratic spline)))
----
G5.1 X- Y- I- J-
----
* 'I' - X incremental offset from start point to control point
* 'J' - Y incremental offset from start point to control point
G5.1 creates a quadratic B-spline in the XY plane with the X and Y axis
only. Not specifying I or J gives zero offset for the unspecified axis,
so one or both must be given.
For example, to program a parabola, through the origin, from X-2 Y4 to X2 Y4:
.G5.1 Sample quadratic spline
----
G90 G17
G0 X-2 Y4
G5.1 X2 I2 J-8
----
It is an error if:
* both I and J offset are unspecified or zero
* An axis other than X or Y is specified
* The active plane is not G17
[[gcode:g5.2-g5.3]]
== G5.2 G5.3 NURBS Block
(((G5.2 G5.3 NURBS Block)))
----
G5.2 <P-> <X- Y-> <L->
X- Y- <P->
...
G5.3
----
Warning: G5.2, G5.3 is experimental and not fully tested.
G5.2 is for opening the data block defining a NURBS and G5.3 for
closing the data block. In the lines between these two codes the curve
control points are defined with both their related 'weights' (P) and
the parameter (L) which determines the order of the curve.
The current coordinate, before the first G5.2 command, is always taken
as the first NURBS control point. To set the weight for this first
control point, first program G5.2 P- without giving any X Y.
The default weight if P is unspecified is 1. The default order if L is
unspecified is 3.
.G5.2 Example
[source,{ngc}]
----
G0 X0 Y0 (rapid move)
F10 (set feed rate)
G5.2 P1 L3
X0 Y1 P1
X2 Y2 P1
X2 Y0 P1
X0 Y0 P2
G5.3
; The rapid moves show the same path without the NURBS Block
G0 X0 Y1
X2 Y2
X2 Y0
X0 Y0
M2
----
.Sample NURBS Output
image:images/nurbs01.png[align="center", alt="Sample NURBS Output"]
More information on NURBS can be found here:
http://wiki.linuxcnc.org/cgi-bin/wiki.pl?NURBS[http://wiki.linuxcnc.org/cgi-bin/wiki.pl?NURBS]
[[gcode:g7]]
== G7 Lathe Diameter Mode
(((G7 Lathe Diameter Mode)))
----
G7
----
Program G7 to enter the diameter mode for axis X on a lathe. When in
the diameter mode the X axis moves on a lathe will be 1/2 the distance
to the center of the lathe. For example X1 would move the cutter to
0.500” from the center of the lathe thus giving a 1” diameter part.
[[gcode:g8]]
== G8 Lathe Radius Mode
(((G8 Lathe Radius Mode)))
----
G8
----
Program G8 to enter the radius mode for axis X on a lathe. When in
Radius mode the X axis moves on a lathe will be the distance from the
center. Thus a cut at X1 would result in a part that is 2" in diameter.
G8 is default at power up.
[[gcode:g10-l1]]
== G10 L1 Set Tool Table
(((G10 L1 Tool Table)))
----
G10 L1 P- axes <R- I- J- Q->
----
* 'P' - tool number
* 'R' - radius of tool
* 'I' - front angle (lathe)
* 'J' - back angle (lathe)
* 'Q' - orientation (lathe)
G10 L1 sets the tool table for the 'P' tool number to the values of the words.
A valid G10 L1 rewrites and reloads the tool table.
.G10 L1 Example Line
----
G10 L1 P1 Z1.5 (set tool 1 Z offset from the machine origin to 1.5)
G10 L1 P2 R0.015 Q3 (lathe example setting tool 2 radius to 0.015 and orientation to 3)
----
It is an error if:
* Cutter Compensation is on
* The P number is unspecified
* The P number is not a valid tool number from the tool table
* The P number is 0
For more information on cutter orientation used by the 'Q' word,
see the <<lathe-tool-orientation,Lathe Tool Orientation>> diagram.
[[gcode:g10-l2]]
== G10 L2 Set Coordinate System
(((G10 L2 Coordinate System)))
----
G10 L2 P- <axes R->
----
* 'P' - coordinate system (0-9)
* 'R' - rotation about the Z axis
G10 L2 offsets the origin of the axes in the coordinate system specified to
the value of the axis word. The offset is from the machine origin established
during homing. The offset value will replace any current offsets in effect for
the coordinate system specified. Axis words not used will not be changed.
Program P0 to P9 to specify which coordinate system to change.
.Coordinate System
[width="50%", options="header", cols="^,^,^"]
|========================================
|P Value |Coordinate System |G code
|0 |Active |n/a
|1 |1 |G54
|2 |2 |G55
|3 |3 |G56
|4 |4 |G57
|5 |5 |G58
|6 |6 |G59
|7 |7 |G59.1
|8 |8 |G59.2
|9 |9 |G59.3
|========================================
Optionally program R to indicate the rotation of the XY axis around the Z axis.
The direction of rotation is CCW as viewed from the positive end of the Z axis.
All axis words are optional.
Being in incremental distance mode (<<gcode:g90-g91,'G91'>>) has no effect on 'G10 L2'.
Important Concepts:
* G10 L2 Pn does not change from the current coordinate system to the one specified by P,
you have to use G54-59.3 to select a coordinate system.
* When a rotation is in effect jogging an axis will only move that axis
in a positive or negative direction and not along the rotated axis.
* If a 'G52' local offset or 'G92' origin offset was in effect before
'G10 L2', it will continue to be in effect afterwards.
* When programming a coordinate system with R, any 'G52' or 'G92' will
be applied *after* the rotation.
* The coordinate system whose origin is set by a 'G10' command may be
active or inactive at the time the 'G10' is executed.
If it is currently active, the new coordinates take effect immediately.
It is an error if:
* The P number does not evaluate to an integer in the range 0 to 9.
* An axis is programmed that is not defined in the configuration.
.G10 L2 Example Line
[source,{ngc}]
----
G10 L2 P1 X3.5 Y17.2
----
In the above example the origin of the first coordinate system
(the one selected by 'G54') is set to be X=3.5 and Y=17.2.
Because only X and Y are specified, the origin point is only moved in X and Y;
the other coordinates are not changed.
.G10 L2 Example Line
[source,{ngc}]
----
G10 L2 P1 X0 Y0 Z0 (clear offsets for X,Y & Z axes in coordinate system 1)
----
The above example sets the XYZ coordinates of the coordinate system 1 to the machine origin.
The coordinate system is described in the <<cha:coordinate-system,Coordinate System>> Section.
[[gcode:g10-l10]]
== G10 L10 Set Tool Table
(((G10 L10 Set Tool Table)))
----
G10 L10 P- axes <R- I- J- Q->
----
* 'P' - tool number
* 'R' - radius of tool
* 'I' - front angle (lathe)
* 'J' - back angle (lathe)
* 'Q' - orientation (lathe)
G10 L10 changes the tool table entry for tool P so that if the
tool offset is reloaded, with the machine in its current position
and with the current G5x and G52/G92 offsets active, the current coordinates
for the given axes will become the given values. The axes that are
not specified in the G10 L10 command will not be changed. This could be
useful with a probe move as described in the <<gcode:g38,G38>> section.
.G10 L10 Example
----
T1 M6 G43 (load tool 1 and tool length offsets)
G10 L10 P1 Z1.5 (set the current position for Z to be 1.5)
G43 (reload the tool length offsets from the changed tool table)
M2 (end program)
----
* See <<sec:select-tool,T>> & <<mcode:m6,M6>>, and
<<gcode:g43,G43>>/<<gcode:g43.1,G43.1>> sections for more information.
It is an error if:
* Cutter Compensation is on
* The P number is unspecified
* The P number is not a valid tool number from the tool table
* The P number is 0
[[gcode:g10-l11]]
== G10 L11 Set Tool Table
(((G10 L11 Set Tool Table)))
----
G10 L11 P- axes <R- I- J- Q->
----
* 'P' - tool number
* 'R' - radius of tool
* 'I' - front angle (lathe)
* 'J' - back angle (lathe)
* 'Q' - orientation (lathe)
G10 L11 is just like G10 L10 except that instead of setting the entry
according to the current offsets, it is set so that the current
coordinates would become the given value if the new tool offset
is reloaded and the machine is placed in the G59.3 coordinate
system without any G52/G92 offset active.
This allows the user to set the G59.3 coordinate system according to a
fixed point on the machine, and then use that fixture to measure tools
without regard to other currently-active offsets.
// .G10 L11 Example FIX ME!
// ----
// G10 L11 P1
// ----
It is an error if:
* Cutter Compensation is on
* The P number is unspecified
* The P number is not a valid tool number from the tool table
* The P number is 0
[[gcode:g10-l20]]
== G10 L20 Set Coordinate System
(((G10 L20 Set Coordinate System)))
----
G10 L20 P- axes
----
* 'P' - coordinate system (0-9)
G10 L20 is similar to G10 L2 except that instead of setting the
offset/entry to the given value, it is set to a calculated value that
makes the current coordinates become the given value.
.G10 L20 Example Line
----
G10 L20 P1 X1.5 (set the X axis current location in coordinate system 1 to 1.5)
----
It is an error if:
* The P number does not evaluate to an integer in the range 0 to 9.
* An axis is programmed that is not defined in the configuration.
[[gcode:g17-g19.1]]
== G17 - G19.1 Plane Select
(((G17 - G19.1 Plane Select)))
These codes set the current plane as follows:
* 'G17' - XY (default)
* 'G18' - ZX
* 'G19' - YZ
* 'G17.1' - UV
* 'G18.1' - WU
* 'G19.1' - VW
The UV, WU and VW planes do not support arcs.
It is a good idea to include a plane selection in the preamble
of each G code file.
The effects of having a plane selected are discussed in Section
<<gcode:g2-g3,G2 G3 Arcs>> and Section <<gcode:g80-g89,G81 G89>>
[[gcode:g20-g21]]
== G20, G21 Units
(((G20 Units)))
* 'G20' - to use inches for length units.
* 'G21' - to use millimeters for length units.
It is a good idea to include units in the preamble
of each G code file.
[[gcode:g28-g28.1]]
== G28, G28.1 Go/Set Predefined Position
(((G28 Go/Set Predefined Position)))
[WARNING]
Only use G28 when your machine is homed to a repeatable position and the
desired G28 position has been stored with G28.1.
G28 uses the values stored in <<sub:numbered-parameters,parameters>>
5161-5169 as the X Y Z A B C U V W final point to move to. The parameter
values are 'absolute' machine coordinates in the native machine 'units' as
specified in the ini file. All axes defined in the ini file will be moved when
a G28 is issued. If no positions are stored with G28.1 then all axes will go to
the <<sec.machine-corrdinate-system,machine origin>>.
* 'G28' - makes a <<gcode:g0,rapid move>> from the current
position to the 'absolute' position of the values in parameters 5161-5166.
* 'G28 axes' - makes a rapid move to the position specified by
'axes' including any offsets, then will make a rapid move to the 'absolute'
position of the values in parameters 5161-5166 for all 'axes' specified. Any
'axis' not specified will not move.
* 'G28.1' - stores the current 'absolute' position into parameters 5161-5166.
.G28 Example Line
----
G28 Z2.5 (rapid to Z2.5 then to Z location specified in #5163)
----
It is an error if :
* Cutter Compensation is turned on
[[gcode:g30-g30.1]]
== G30, G30.1 Go/Set Predefined Position
(((G30 Go/Set Predefined Position)))
[WARNING]
Only use G30 when your machine is homed to a repeatable position and the
desired G30 position has been stored with G30.1.
G30 functions the same as G28 but uses the values stored in
<<sub:numbered-parameters,parameters>> 5181-5189 as the X Y Z A B C U V W
final point to move to. The parameter values are 'absolute' machine
coordinates in the native machine 'units' as specified in the ini file.
All axes defined in the ini file will be moved when a G30 is issued. If no
positions are stored with G30.1 then all axes will go to the
<<sec.machine-corrdinate-system,machine origin>>.
[NOTE]
G30 parameters will be used to move the tool when a M6 is programmed
if TOOL_CHANGE_AT_G30=1 is in the [EMCIO] section of the ini file.
* 'G30' - makes a <<gcode:g0,rapid move>> from the current
position to the 'absolute' position of the values in parameters 5181-5186.
* 'G30 axes' - makes a rapid move to the position specified
by 'axes' including any offsets, then will make a rapid move to the
'absolute' position of the values in parameters 5181-5186 for all 'axes'
specified. Any 'axis' not specified will not move.
* 'G30.1' - stores the current absolute position into parameters 5181-5186.
.G30 Example Line
----
G30 Z2.5 (rapid to Z2.5 then to the Z location specified in #5i83)
----
It is an error if :
* Cutter Compensation is turned on
[[gcode:g33]]
== G33 Spindle Synchronized Motion
(((G33 Spindle Synchronized Motion)))
----
G33 X- Y- Z- K- $-
----
* 'K' - distance per revolution
For spindle-synchronized motion in one direction, code 'G33 X- Y- Z- K-'
where K gives the distance moved in XYZ for each revolution of the spindle.
For instance, if starting at 'Z=0', 'G33 Z-1 K.0625' produces
a 1 inch motion in Z over 16 revolutions of the spindle.
This command might be part of a program to produce a 16TPI thread.
Another example in metric, 'G33 Z-15 K1.5' produces
a movement of 15mm while the spindle rotates 10 times for a thread of 1.5mm.
The (optional) $ argument sets which spindle the motion is synchronised
to (default is zero). For example G33 Z10 K1 $1 will move the spindle in
synchrony with the spindle.N.revs HAL pin value.
Spindle-synchronized motion waits for the spindle index and spindle at speed
pins, so multiple passes line up. 'G33' moves end at the programmed endpoint.
G33 could be used to cut tapered threads or a fusee.
All the axis words are optional, except that at least one must be used.
[NOTE]
K follows the drive line described by 'X- Y- Z-'. K is not parallel to
the Z axis if X or Y endpoints are used for example when cutting tapered
threads.
.Technical Info[[gcode:g33-tech-info]]
At the beginning of each G33 pass, LinuxCNC uses the spindle speed and the
machine acceleration limits to calculate how long it will take Z to
accelerate after the index pulse, and determines how many degrees the
spindle will rotate during that time. It then adds that angle to the
index position and computes the Z position using the corrected spindle
angle. That means that Z will reach the correct position just as it
finishes accelerating to the proper speed, and can immediately begin
cutting a good thread.
.HAL Connections
The pin 'spindle.N.at-speed' must be set or driven true for the motion to
start. Additionally spindle.N.revs must increase by 1 for each revolution
of the spindle and the spindle.N.index-enable pin must be connected to
an encoder (or resolver) counter which resets index-enable once per rev.
See the Integrators Manual for more information on spindle synchronized motion.
.G33 Example
----
G90 (absolute distance mode)
G0 X1 Z0.1 (rapid to position)
S100 M3 (start spindle turning)
G33 Z-2 K0.125 (move Z axis to -2 at a rate to equal 0.125 per revolution)
G0 X1.25 (rapid move tool away from work)
Z0.1 (rapid move to starting Z position)
M2 (end program)
----
* See <<gcode:g90-g91,G90>> & <<gcode:g0,G0>> & <<mcode:m2-m30,M2>> sections for more information.
It is an error if:
* All axis words are omitted.
* The spindle is not turning when this command is executed
* The requested linear motion exceeds machine velocity limits
due to the spindle speed
[[gcode:g33.1]]
== G33.1 Rigid Tapping
(((G33.1 Rigid Tapping)))
----------------
G33.1 X- Y- Z- K- I- $-
----------------
* 'K' - distance per revolution
* 'I' - optional spindle speed multiplier for faster return move
* '$' - optional spindle selector
[WARNING]
For Z only tapping preposition the XY location prior to calling G33.1 and only
use a Z word in the G33.1. If the coordinates specified are not the current
coordinates when calling G33.1 for tapping the move will not be along the Z axis
but will be a coordinated, spindle-synchronized move from the current location
to the location specified and back.
For rigid tapping (spindle synchronized motion with return),
code 'G33.1 X- Y- Z- K-' where 'K-' gives the distance moved
for each revolution of the spindle.
A rigid tapping move consists of the following sequence:
. A move from the current coordinate to the specified coordinate, synchronized
with the selected spindle at the given ratio and starting from the
current coordinate with a spindle index pulse.
. When reaching the endpoint, a command to reverse the spindle, and speed up
by a factor set by the multiplier (e.g., from clockwise to counterclockwise).
. Continued synchronized motion beyond the specified end coordinate
until the spindle actually stops and reverses.
. Continued synchronized motion back to the original coordinate.
. When reaching the original coordinate,
a command to reverse the spindle a second time
(e.g., from counterclockwise to clockwise).
. Continued synchronized motion beyond the original coordinate
until the spindle actually stops and reverses.
. An *unsynchronized* move back to the original coordinate.
Spindle-synchronized motions wait for spindle index,
so multiple passes line up.'G33.1' moves end at the original coordinate.
All the axis words are optional, except that at least one must be used.
.G33.1 Example
[source,{ngc}]
----
G90 (set absolute mode)
G0 X1.000 Y1.000 Z0.100 (rapid move to starting position)
S100 M3 (turn on the spindle, 100 RPM)
G33.1 Z-0.750 K0.05 (rigid tap a 20 TPI thread 0.750 deep)
M2 (end program)
----
* See <<gcode:g90-g91,G90>> & <<gcode:g0,G0>> & <<mcode:m2-m30,M2>> sections for more information.
It is an error if:
* All axis words are omitted.
* The spindle is not turning when this command is executed
* The requested linear motion exceeds machine velocity limits
due to the spindle speed
[[gcode:g38]]
== G38.n Straight Probe
(((G38.n Probe)))
----
G38.n axes
----
* 'G38.2' - probe toward workpiece, stop on contact, signal error if failure
* 'G38.3' - probe toward workpiece, stop on contact
* 'G38.4' - probe away from workpiece, stop on loss of contact, signal error if failure
* 'G38.5' - probe away from workpiece, stop on loss of contact
[IMPORTANT]
You will not be able to use a probe move until your
machine has been set up to provide a probe input signal.
The probe input signal must be connected to 'motion.probe-input' in a .hal file.
G38.n uses motion.probe-input to determine when the probe has made (or lost) contact.
TRUE for probe contact closed (touching), FALSE for probe contact open.
Program 'G38.n axes' to perform a straight probe operation.
The axis words are optional, except that at least one of them must be used.
The axis words together define the destination point that the probe will move towards,
starting from the current location. If the probe is not tripped before the destination
is reached G38.2 and G38.4 will signal an error.
The tool in the spindle must be a probe or contact a probe switch.
In response to this command, the machine moves the controlled point
(which should be at the center of the probe ball) in a straight line at the
current <<sec:set-feed-rate,feed rate>> toward the programmed point.
In inverse time feed mode, the feed rate is such that the whole motion
from the current point to the programmed point would take the specified time.
The move stops (within machine acceleration limits)
when the programmed point is reached,
or when the requested change in the probe input takes place,
whichever occurs first.
After successful probing, parameters #5061 to #5069 will be set to the
X, Y, Z, A, B, C, U, V, W coordinates of the location of the controlled point
at the time the probe changed state (in the current work coordinate system).
After unsuccessful probing, they are set to the coordinates of the programmed point.
Parameter 5070 is set to 1 if the probe succeeded and 0 if the probe failed.
If the probing operation failed, G38.2 and G38.4 will signal an error
by posting an message on screen if the selected GUI supports that.
And by halting program execution.
A comment of the form '(PROBEOPEN filename.txt)' will open
'filename.txt' and store the 9-number coordinate consisting of
XYZABCUVW of each successful straight probe in it.
The file must be closed with '(PROBECLOSE)'. For more information
see the <<gcode:comments, Comments>> Section.
An example file 'smartprobe.ngc' is included (in the examples directory)
to demonstrate using probe moves to log to a file the coordinates of a part.
The program 'smartprobe.ngc' could be used with 'ngcgui' with minimal changes.
It is an error if:
* the current point is the same as the programmed point.
* no axis word is used
* cutter compensation is enabled
* the feed rate is zero
* the probe is already in the target state
[[gcode:g40]]
== G40 Compensation Off
(((G40 Cutter Compensation Off)))
* 'G40' - turn cutter compensation off. If tool compensation was on the
next move must be a linear move and longer than the tool diameter.
It is OK to turn compensation off when it is already off.
.G40 Example
----
; current location is X1 after finishing cutter compensated move
G40 (turn compensation off)
G0 X1.6 (linear move longer than current cutter diameter)
M2 (end program)
----
See <<gcode:g0,G0>> & <<mcode:m2-m30,M2>> sections for more information.
It is an error if:
* A G2/G3 arc move is programmed next after a G40.
* The linear move after turning compensation off is less than the tool diameter.
[[gcode:g41-g42]]
== G41, G42 Cutter Compensation
(((G41 G42 Cutter Compensation)))
----
G41 <D-> (left of programmed path)
G42 <D-> (right of programmed path)
----
* 'D' - tool number
The D word is optional; if there is no D word the radius of the currently
loaded tool will be used (if no tool is loaded and no D word is given,
a radius of 0 will be used).
If supplied, the D word is the tool number to use. This would normally
be the number of the tool in the spindle (in which case the D word is
redundant and need not be supplied), but it may be any valid tool number.
[NOTE]
'G41/G42 D0' is a little special. Its behavior is different on
random tool changer machines and nonrandom tool changer machines
(see the <<mcode:m6,Tool Change>> section). On nonrandom
tool changer machines, 'G41/G42 D0' applies the TLO of the tool currently
in the spindle, or a TLO of 0 if no tool is in the spindle. On random
tool changer machines, 'G41/G42 D0' applies the TLO of the tool T0 defined
in the tool table file (or causes an error if T0 is not defined in the
tool table).
To start cutter compensation to the left of the part profile, use G41.
G41 starts cutter compensation to the left of the programmed line
as viewed from the positive end of the axis perpendicular to the plane.
To start cutter compensation to the right of the part profile, use G42.
G42 starts cutter compensation to the right of the programmed line
as viewed from the positive end of the axis perpendicular to the plane.
The lead in move must be at least as long as the tool radius.
The lead in move can be a rapid move.
Cutter compensation may be performed if the XY-plane or XZ-plane is active.
User M100-M199 commands are allowed when Cutter Compensation is on.
The behavior of the machining center when cutter compensation
is on is described in the <<sec:cutter-compensation,Cutter Compensation>>
Section along with code examples.
It is an error if:
* The D number is not a valid tool number or 0.
* The YZ plane is active.
* Cutter compensation is commanded to turn on when it is already on.
[[gcode:g41.1-g42.1]]
== G41.1, G42.1 Dynamic Cutter Compensation
(((G41.1 G42.1 Dynamic Compensation)))
----
G41.1 D- <L-> (left of programmed path)
G42.1 D- <L-> (right of programmed path)
----
* 'D' - cutter diameter
* 'L' - tool orientation (see <<lathe-tool-orientation,lathe tool orientation>>)
G41.1 & G42.1 function the same as G41 & G42 with the added scope of being able
to program the tool diameter. The L word defaults to 0 if unspecified.
It is an error if:
* The YZ plane is active.
* The L number is not in the range from 0 to 9 inclusive.
* The L number is used when the XZ plane is not active.
* Cutter compensation is commanded to turn on when it is already on.
[[gcode:g43]]
== G43 Tool Length Offset
(((G43 Tool Length Offset)))
----
G43 <H->
----
* 'H' - tool number (optional)
G43 enables tool length compensation. G43 changes subsequent motions
by offsetting the axis coordinates by the length of the offset. G43
does not cause any motion. The next time a compensated axis is moved,
that axis's endpoint is the compensated location.
'G43' without an H word uses the currently loaded tool from the last
'Tn M6'.
'G43 Hn' uses the offset for tool n.
[NOTE]
'G43 H0' is a little special. Its behavior is different on random
tool changer machines and nonrandom tool changer machines (see the
<<sec:tool-changers,Tool Changers>> section). On nonrandom tool changer
machines, 'G43 H0' applies the TLO of the tool currently in the spindle,
or a TLO of 0 if no tool is in the spindle. On random tool changer
machines, 'G43 H0' applies the TLO of the tool T0 defined in the tool
table file (or causes an error if T0 is not defined in the tool table).
.G43 H- Example Line
----
G43 H1 (set tool offsets using the values from tool 1 in the tool table)
----
It is an error if:
* the H number is not an integer, or
* the H number is negative, or
* the H number is not a valid tool number (though note that 0 is a valid
tool number on nonrandom tool changer machines, it means "the tool
currently in the spindle")
[[gcode:g43.1]]
== G43.1: Dynamic Tool Length Offset
(((G43.1 Dynamic Tool Length Offset)))
----
G43.1 axes
----
* 'G43.1 axes' - change subsequent motions by replacing the current offset(s)
of axes. G43.1 does not cause any motion. The next time a compensated axis
is moved, that axis's endpoint is the compensated location.
.G43.1 Example
----
G90 (set absolute mode)
T1 M6 G43 (load tool 1 and tool length offsets, Z is at machine 0 and DRO shows Z1.500)
G43.1 Z0.250 (offset current tool offset by 0.250, DRO now shows Z1.250)
M2 (end program)
----
* See <<gcode:g90-g91,G90>> & <<sec:select-tool,T>> & <<mcode:m6,M6>>
sections for more information.
It is an error if:
* motion is commanded on the same line as 'G43.1'
NOTE: G43.1 does not write to the tool table.
[[gcode:g43.2]]
== G43.2: Apply additional Tool Length Offset
(((G43.2 Apply additional Tool Length Offset)))
----
G43.2 H-
----
* 'H' - tool number
G43.2 applies an additional simultaneous tool offset.
.G43.2 Example
----
G90 (set absolute mode)
T1 M6 (load tool 1)
G43 (or G43 H1 - replace all tool offsets with T1's offset)
G43.2 H10 (also add in T10's tool offset)
M2 (end program)
----
You can sum together an arbitrary number of offsets by calling G43.2
more times. There are no built-in assumptions about which numbers are geometry
offsets and which are wear offsets, or that you should have only one of each.
Like the other G43 commands, G43.2 does not cause any motion. The next time a
compensated axis is moved, that axis's endpoint is the compensated location.
It is an error if:
* 'H' is unspecified, or
* the given tool number does not exist in the tool table
NOTE: G43.2 does not write to the tool table.
[[gcode:g49]]
== G49: Cancel Tool Length Compensation
(((G49 Cancel Tool Length Offset)))
* 'G49' - cancels tool length compensation
It is OK to program using the same offset already in use. It is also
OK to program using no tool length offset if none is currently being
used.
[[gcode:g53]]
== G53 Move in Machine Coordinates
(((G53 Machine Coordinates)))
----
G53 axes
----
To move in the <<sec.machine-corrdinate-system,machine coordinate system>>,
program 'G53' on the same line as a linear move. 'G53' is not modal and must be
programmed on each line. 'G0' or 'G1' does not have to be programmed on the same
line if one is currently active.
For example 'G53 G0 X0 Y0 Z0' will move the axes to the home position even if
the currently selected coordinate system has offsets in effect.
.G53 Example
----
G53 G0 X0 Y0 Z0 (rapid linear move to the machine origin)
G53 X2 (rapid linear move to absolute coordinate X2)
----
* See <<gcode:g0,G0>> section for more information.
It is an error if:
* G53 is used without G0 or G1 being active,
* or G53 is used while cutter compensation is on.
[[gcode:g54-g59.3]]
== G54-G59.3 Select Coordinate System
(((G54-G59.3 Select Coordinate System)))
* 'G54' - select coordinate system 1
* 'G55' - select coordinate system 2
* 'G56' - select coordinate system 3
* 'G57' - select coordinate system 4
* 'G58' - select coordinate system 5
* 'G59' - select coordinate system 6
* 'G59.1' - select coordinate system 7
* 'G59.2' - select coordinate system 8
* 'G59.3' - select coordinate system 9
The coordinate systems store the axis values and the
XY rotation angle around the Z axis
in the parameters shown in the following table.
.Coordinate System Parameters
[width="80%", options="header", cols="<,11*^"]
|============================================================
|Select|CS|X |Y |Z |A |B |C |U |V |W |R
|G54 |1 |5221|5222|5223|5224|5225|5226|5227|5228|5229|5230
|G55 |2 |5241|5242|5243|5244|5245|5246|5247|5248|5249|5250
|G56 |3 |5261|5262|5263|5264|5265|5266|5267|5268|5269|5270
|G57 |4 |5281|5282|5283|5284|5285|5286|5287|5288|5289|5290
|G58 |5 |5301|5302|5303|5304|5305|5306|5307|5308|5309|5310
|G59 |6 |5321|5322|5323|5324|5325|5326|5327|5328|5329|5330
|G59.1 |7 |5341|5342|5343|5344|5345|5346|5347|5348|5349|5350
|G59.2 |8 |5361|5362|5363|5364|5365|5366|5367|5368|5369|5370
|G59.3 |9 |5381|5382|5383|5384|5385|5386|5387|5388|5389|5390
|============================================================
It is an error if:
* selecting a coordinate system is used while cutter compensation is on.
See the <<cha:coordinate-system,Coordinate System>> Section for an overview of coordinate
systems.
[[gcode:g61-g61.1]]
== G61, G61.1 Exact Path Mode
(((G61 G61.1 G64 Path Mode)))
* 'G61' - Exact path mode, movement exactly as programed. Moves will slow or
stop as needed to reach every programed point. If two sequential moves are
exactly co-linear movement will not stop.
* 'G61.1' - Exact stop mode, movement will stop at the end of each programed
segment.
[[gcode:g64]]
== G64 Path Blending
(((G64 Path Blending)))
----
G64 <P- <Q->>
----
* 'P' - motion blending tolerance
* 'Q' - naive cam tolerance
* 'G64' - best possible speed.
* 'G64 P- <Q- >' blending with tolerance.
* 'G64' - without P means to keep the best speed possible, no matter how
far away from the programmed point you end up.
* 'G64 P- Q-' - is a way to fine tune your system for best compromise
between speed and accuracy. The P- tolerance means that the actual path
will be no more than P- away from the programmed endpoint. The velocity
will be reduced if needed to maintain the path. In addition, when you
activate G64 P- Q- it turns on the 'naive cam detector'; when there are
a series of linear XYZ feed moves at the same <<sec:set-feed-rate,feed rate>>
that are less than Q- away from being collinear, they are collapsed into a
single linear move. On G2/G3 moves in the G17 (XY) plane when the maximum
deviation of an arc from a straight line is less than the G64 P-
tolerance the arc is broken into two lines (from start of arc to
midpoint, and from midpoint to end). those lines are then subject to
the naive cam algorithm for lines. Thus, line-arc, arc-arc, and
arc-line cases as well as line-line benefit from the 'naive cam
detector'. This improves contouring performance by simplifying the
path. It is OK to program for the mode that is already active. See also
the <<sec:trajectory-control,Trajectory Control>> Section for more
information on these modes.
If Q is not specified then it will have the same behavior as before and
use the value of P-.
.G64 P- Example Line
----
G64 P0.015 (set path following to be within 0.015 of the actual path)
----
It is a good idea to include a path control specification in the preamble
of each G code file.
[[gcode:g73]]
== G73 Drilling Cycle with Chip Breaking
(((G73 Drilling Cycle Chip Break)))
----
G73 X- Y- Z- R- Q- <L->
----
* 'R' - retract position along the Z axis.
* 'Q' - delta increment along the Z axis.
* 'L' - repeat
The 'G73' cycle is drilling or milling with chip breaking.
This cycle takes a Q number which represents a 'delta' increment along the Z axis.
. Preliminary motion.
** If the current Z position is below the R position, The Z axis does a
<<gcode:g0,rapid move>> to the R position.
** Move to the X Y coordinates
. Move the Z-axis only at the current <<sec:set-feed-rate,feed rate>> downward
by delta or to the Z position, whichever is less deep.
. Rapid up a bit.
. Repeat steps 2 and 3 until the Z position is reached at step 2.
. The Z axis does a rapid move to the R position.
It is an error if:
* the Q number is negative or zero.
* the R number is not specified
[[gcode:g74]]
== G74 Left-hand Tapping Cycle, Dwell
(((G74 Left-hand Tapping Cycle Dwell)))
----
G74 (X- Y- Z-) or (U- V- W-) R- L- P- $-
----
The 'G74' cycle is intended for tapping with floating chuck and dwell at the bottom of the hole.
1. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
2. Disable Feed and Speed Overrides.
3. Move the Z-axis at the current feed rate to the Z position.
4. Stop the selected spindle (chosen by the $ parameter)
5. Start spindle rotation clockwise.
6. Dwell for the P number of seconds.
7. Move the Z-axis at the current feed rate to clear Z
8. Restore Feed and Speed override enables to previous state
The length of the dwell is specified by a 'P-' word in the G84 block. Thread pitch is F divided by S.
In example S100 F125 gives pitch of 1.25MM per revolution.
[[gcode:g76]]
== G76 Threading Cycle
(((G76 Threading Cycle)))
----
G76 P- Z- I- J- R- K- Q- H- E- L- $-
----
.G76 Threading
image::images/g76-threads.png[align="center", alt="G76 Threading"]
* 'Drive Line' - A line through the initial X position parallel to the Z.
* 'P-' - The 'thread pitch' in distance per revolution.
* 'Z-' - The final position of threads. At the end of the cycle the tool will
be at this Z position.
[NOTE]
When G7 'Lathe Diameter Mode' is in force the values for 'I', 'J' and 'K' are
diameter measurements. When G8 'Lathe Radius Mode' is in force the values for
'I', 'J' and 'K' are radius measurements.
* 'I-' - The 'thread peak' offset from the 'drive line'. Negative 'I' values
are external threads, and positive 'I' values are internal threads.
Generally the material has been turned to this size before the 'G76' cycle.
* 'J-' - A positive value specifying the 'initial cut depth'. The first
threading cut will be 'J' beyond the 'thread peak' position.
* 'K-' - A positive value specifying the 'full thread depth'. The final
threading cut will be 'K' beyond the 'thread peak' position.
Optional settings
* '$-' - The spindle number to which the motion will be synchronised
(default 0). For example is $1 is programmed then the motion will begin
on the reset od spindle.1.index-enable and proceed in synchrony with the
value of spindle.1.revs
* 'R-' - The 'depth degression'. 'R1.0' selects constant depth on successive
threading passes. 'R2.0' selects constant area. Values between 1.0 and
2.0 select decreasing
depth but increasing area. Values above 2.0 select decreasing area.
Beware that unnecessarily high degression values will cause a large
number of passes to be used. (degression = a descent by stages or
steps.)
* 'Q-' - The 'compound slide angle' is the angle (in degrees) describing to
what extent successive passes should be offset along the drive line.
This is used to cause one side of the tool to remove more material than
the other. A positive 'Q' value causes the leading edge of the tool to
cut more heavily.
Typical values are 29, 29.5 or 30.
* 'H-' - The number of 'spring passes'. Spring passes are additional passes at
full thread depth. If no additional passes are desired, program 'H0'.
* 'E-' - Specifies the distance along the drive line used for the taper. The
angle of the taper will be so the last pass tapers to the thread crest
over the distance specified with E.' E0.2' will give a taper for the
first/last 0.2 length units along the
thread. For a 45 degree taper program E the same as K
* 'L-' - Specifies which ends of the thread get the taper. Program 'L0' for no
taper (the default), 'L1' for entry taper, 'L2' for exit taper, or 'L3'
for both entry and exit tapers. Entry tapers will pause at the drive line to
synchronize with the index pulse then move at the <<sec:set-feed-rate,feed rate>>
in to the beginning of the taper. No entry taper and the tool will rapid to the
cut depth then synchronize and begin the cut.
The tool is moved to the initial X and Z positions prior to issuing
the G76. The X position is the 'drive line' and the Z position is the
start of the threads.
The tool will pause briefly for synchronization before each threading
pass, so a relief groove will be required at the entry unless the
beginning of the thread is past the end of the material or an entry
taper is used.
Unless using an exit taper, the exit move is not synchronized to the spindle
speed and will be a <<gcode:g0,rapid move>>. With a slow spindle, the
exit move might take only a small fraction of a revolution. If the spindle
speed is increased after several passes are complete, subsequent exit
moves will require a larger portion of a revolution, resulting in a
very heavy cut during the exit move. This can be avoided by providing a
relief groove at the exit, or by not changing the spindle speed while
threading.
The final position of the tool will be at the end of the 'drive line'.
A safe Z move will be needed with an internal thread to remove the tool
from the hole.
It is an error if:
* The active plane is not the ZX plane
* Other axis words, such as X- or Y-, are specified
* The 'R-' degression value is less than 1.0.
* All the required words are not specified
* 'P-', 'J-', 'K-' or 'H-' is negative
* 'E-' is greater than half the drive line length
.HAL Connections
The pins 'spindle.N.at-speed' and the 'encoder.n.phase-Z' for the
spindle must be connected in your HAL file before G76 will work.
See the <<sec:motion-pins, spindle>> pins in the Motion section for more
information.
.Technical Info
The G76 canned cycle is based on the G33 Spindle Synchronized Motion. For more
information see the G33 <<gcode:g33-tech-info,Technical Info>>.
The sample program 'g76.ngc' shows the use of the G76 canned cycle,
and can be previewed and
executed on any machine using the 'sim/lathe.ini' configuration.
.G76 Example
[source,{ngc}]
---------------
G0 Z-0.5 X0.2
G76 P0.05 Z-1 I-.075 J0.008 K0.045 Q29.5 L2 E0.045
---------------
In the figure the tool is in the final position after the G76 cycle
is completed. You can see the entry path on the right from the Q29.5
and the exit path on the left from the L2 E0.045. The white lines
are the cutting moves.
.G76 Example
image::images/g76-01.png[align="center", alt="G76 Example"]
[[gcode:g80-g89]]
== Canned Cycles
(((G80-G89 Canned Cycles)))
The canned cycles 'G81' through 'G89' and the canned cycle stop 'G80'
are described in this section.
All canned cycles are performed with respect to the currently-selected
plane. Any of the nine planes may be selected. Throughout this section,
most of the descriptions assume the XY-plane has been selected. The
behavior is analogous if another plane is selected, and the correct
words must be used. For instance, in the 'G17.1' plane, the action of
the canned cycle is along W, and the locations
or increments are given with U and V. In this case substitute U,V,W for
X,Y,Z in the instructions below.
Rotary axis words are not allowed in canned cycles. When the
active plane is one of the XYZ family, the UVW axis words are not
allowed. Likewise, when the active plane is one of the UVW family, the
XYZ axis words are not allowed.
=== Common Words
All canned cycles use X, Y, Z, or U, V, W groups depending on the
plane selected and R words. The R (usually meaning retract) position is
along the axis perpendicular to the currently selected plane (Z-axis
for XY-plane, etc.) Some canned cycles use additional arguments.
=== Sticky Words
For canned cycles, we will call a number 'sticky' if, when the same
cycle is used on several lines of code in a row, the number must be
used the first time, but is optional on the rest of the lines. Sticky
numbers keep their value on the rest of the lines if they are not
explicitly programmed to be different. The R number is always sticky.
In incremental distance mode X, Y, and R numbers are treated as
increments from the current position and Z as an increment from the
Z-axis position before the move involving Z takes place. In absolute
distance mode, the X, Y, R, and Z numbers are absolute positions in the
current coordinate system.
=== Repeat Cycle
The L number is optional and represents the number of repeats.
L=0 is not allowed. If the repeat feature is used, it is
normally used in incremental distance mode, so that the same sequence
of motions is repeated in several equally spaced places along a
straight line. When L- is greater than 1 in incremental mode with the
XY-plane selected, the X and Y positions are determined by adding the
given X and Y numbers either to the current X and Y positions (on the
first go-around) or to the X and Y positions at the end of the previous
go-around (on the repetitions). Thus, if you program 'L10' , you will
get 10 cycles. The first cycle will be distance X,Y from
the original location. The R and Z positions do not change during the
repeats. The L number is not sticky. In absolute distance mode,
L>1 means 'do the same cycle in the same place several
times', Omitting the L word is equivalent to specifying L=1.
=== Retract Mode
The height of the retract move at the end of each repeat (called
'clear Z' in the descriptions below) is determined by the setting of
the retract mode: either to the original Z position (if that is above
the R position and the retract mode is 'G98', OLD_Z), or otherwise to
the R position. See the <<gcode:g98-g99,G98 G99>> Section.
[[gcode:canned-cycle-errors]]
=== Canned Cycle Errors
It is an error if:
* axis words are all missing during a canned cycle,
* axis words from different groups (XYZ) (UVW) are used together,
* a P number is required and a negative P number is used,
* an L number is used that does not evaluate to a positive integer,
* rotary axis motion is used during a canned cycle,
* inverse time feed rate is active during a canned cycle,
* or cutter compensation is active during a canned cycle.
If the XY plane is active, the Z number is sticky, and it is an error
if:
* the Z number is missing and the same canned cycle was not already
active,
* or the R number is less than the Z number.
If other planes are active, the error conditions are analogous to the
XY conditions above.
[[gcode:preliminary-motion]]
=== Preliminary and In-Between Motion
Preliminary motion is a set of motions that is common to all of the
milling canned cycles. If the current Z position is below the R position,
the Z axis does a <<gcode:g0,rapid move>> to the R position. This happens only
once, regardless of the value of L.
In addition, at the beginning of the first cycle and each repeat, the
following one or two moves are made
. A <<gcode:g0,rapid move>> parallel to the XY-plane to
the given XY-position,
. The Z-axis make a rapid move to the R position, if it is
not already at the R position.
If another plane is active, the preliminary and in-between motions are
analogous.
=== Why use a canned cycle?
There are at least two reasons for using canned cycles. The first is
the economy of code. A single bore would take several lines of code to
execute.
The G81 <<gcode:g81-example,Example 1>> demonstrates how a canned cycle could be
used to produce 8 holes with ten lines of G code within the canned cycle mode.
The program below will produce the same set of 8 holes using five lines
for the canned cycle. It does not follow exactly the same path nor does
it drill in the same order as the earlier example. But the program
writing economy of a good canned cycle should be obvious.
NOTE: Line numbers are not needed but help clarify these examples
.Eight Holes
----
N100 G90 G0 X0 Y0 Z0 (move coordinate home)
N110 G1 F10 X0 G4 P0.1
N120 G91 G81 X1 Y0 Z-1 R1 L4(canned drill cycle)
N130 G90 G0 X0 Y1
N140 Z0
N150 G91 G81 X1 Y0 Z-0.5 R1 L4(canned drill cycle)
N160 G80 (turn off canned cycle)
N170 M2 (program end)
----
The G98 to the second line above means that the return move will be to
the value of Z in the first line since it is higher that the R value
specified.
image::images/eight.png[align="center"]
.Twelve Holes in a Square
This example demonstrates the use of the L word to repeat a set of
incremental drill cycles for successive blocks of code within the same
G81 motion mode. Here we produce 12 holes using five lines of code in
the canned motion mode.
----
N1000 G90 G0 X0 Y0 Z0 (move coordinate home)
N1010 G1 F50 X0 G4 P0.1
N1020 G91 G81 X1 Y0 Z-0.5 R1 L4 (canned drill cycle)
N1030 X0 Y1 R0 L3 (repeat)
N1040 X-1 Y0 L3 (repeat)
N1050 X0 Y-1 L2 (repeat)
N1060 G80 (turn off canned cycle)
N1070 G90 G0 X0 (rapid move home)
N1080 Y0
N1090 Z0
N1100 M2 (program end)
----
image::images/twelve.png[align="center"]
The second reason to use a canned cycle is that they all produce
preliminary moves and returns that you can anticipate and control
regardless of the start point of the canned cycle.
[[gcode:g80]]
== G80 Cancel Canned Cycle
(((G80 Cancel Modal Motion)))
* 'G80' - cancel canned cycle modal motion. 'G80' is part of modal group 1,
so programming any other G code from modal group 1 will also
cancel the canned cycle.
It is an error if:
* Axis words are programmed when G80 is active.
.G80 Example
----
G90 G81 X1 Y1 Z1.5 R2.8 (absolute distance canned cycle)
G80 (turn off canned cycle motion)
G0 X0 Y0 Z0 (rapid move to coordinate home)
----
The following code produces the same final position and machine state as
the previous code.
.G0 Example
----
G90 G81 X1 Y1 Z1.5 R2.8 (absolute distance canned cycle)
G0 X0 Y0 Z0 (rapid move to coordinate home)
----
The advantage of the first set is that, the G80 line clearly turns off the
G81 canned cycle. With the first set of blocks, the programmer must turn
motion back on with G0, as is done in the next line, or any other motion
mode G word.
If a canned cycle is not turned off with G80 or another motion word, the
canned cycle will attempt to repeat itself using the next block of code
that contains an X, Y, or Z word. The following file drills (G81) a set
of eight holes as shown in the following caption.
.G80 Example 1
----
N100 G90 G0 X0 Y0 Z0 (coordinate home)
N110 G1 X0 G4 P0.1
N120 G81 X1 Y0 Z0 R1 (canned drill cycle)
N130 X2
N140 X3
N150 X4
N160 Y1 Z0.5
N170 X3
N180 X2
N190 X1
N200 G80 (turn off canned cycle)
N210 G0 X0 (rapid move home)
N220 Y0
N230 Z0
N240 M2 (program end)
----
[NOTE]
Notice the z position change after the first four holes.
Also, this is one of the few places where line numbers have some value,
being able to point a reader to a specific line of code.
.G80 Cycle
image::images/G81mult.png[align="center", alt="G80 Cycle"]
The use of G80 in line N200 is optional because the G0 on the next
line will turn off the G81 cycle. But using the G80 as shown in
Example 1, will provide for easier to read canned cycle. Without it, it
is not so obvious that all of the blocks between N120 and N200 belong
to the canned cycle.
[[gcode:g81]]
== G81 Drilling Cycle
(((G81 Drilling Cycle)))
----
G81 (X- Y- Z-) or (U- V- W-) R- L-
----
The 'G81' cycle is intended for drilling.
The cycle functions as follows:
. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
. Move the Z-axis at the current <<sec:set-feed-rate,feed rate>> to the Z
position.
. The Z-axis does a <<gcode:g0,rapid move>> to clear Z.
.Example 1 - Absolute Position G81[[gcode:g81-example]]
Suppose the current position is (X1, Y2, Z3) and the following line of NC
code is interpreted.
[source,{ngc}]
----
G90 G98 G81 X4 Y5 Z1.5 R2.8
----
This calls for absolute distance mode (G90) and OLD_Z retract mode
(G98) and calls for the G81 drilling cycle to be performed once.
The X value and X position are 4.
The Y value and Y position are 5.
The Z value and Z position are 1.5.
The R value and clear Z are 2.8. OLD_Z is 3.
The following moves take place:
. a <<gcode:g0,rapid move>> parallel to the XY plane to (X4, Y5)
. a rapid move move parallel to the Z-axis to (Z2.8).
. move parallel to the Z-axis at the <<sec:set-feed-rate,feed rate>> to (Z1.5)
. a rapid move parallel to the Z-axis to (Z3)
image::images/G81ex1.png[align="center"]
.Example 2 - Relative Position G81
Suppose the current position is (X1, Y2, Z3) and the following line of NC
code is interpreted.
[source,{ngc}]
----
G91 G98 G81 X4 Y5 Z-0.6 R1.8 L3
----
This calls for incremental distance mode (G91) and OLD_Z retract mode
(G98). It also calls for the G81 drilling cycle to be repeated three
times. The X value is 4, the Y value is 5, the Z value is -0.6 and the
R value is 1.8. The initial X position is 5 (=1+4), the initial Y
position is 7 (=2+5), the clear Z position is 4.8 (=1.8+3), and the Z
position is 4.2 (=4.8-0.6). OLD_Z is 3.
The first preliminary move is a maximum rapid move along the Z axis to
(X1,Y2,Z4.8), since OLD_Z < clear Z.
The first repeat consists of 3 moves.
. a <<gcode:g0,rapid move>> parallel to the XY-plane to (X5, Y7)
. move parallel to the Z-axis at the <<sec:set-feed-rate,feed rate>> to (Z4.2)
. a rapid move parallel to the Z-axis to (X5, Y7, Z4.8)
The second repeat consists of 3 moves. The X position is reset to
9 (=5+4) and the Y position to 12 (=7+5).
. a <<gcode:g0,rapid move>> parallel to the XY-plane to (X9, Y12, Z4.8)
. move parallel to the Z-axis at the feed rate to (X9, Y12, Z4.2)
. a rapid move parallel to the Z-axis to (X9, Y12, Z4.8)
The third repeat consists of 3 moves. The X position is reset to
13 (=9+4) and the Y position to 17 (=12+5).
. a <<gcode:g0,rapid move>> parallel to the XY-plane to (X13, Y17, Z4.8)
. move parallel to the Z-axis at the feed rate to (X13, Y17, Z4.2)
. a rapid move parallel to the Z-axis to (X13, Y17, Z4.8)
image::images/G81ex2.png[align="center"]
.Example 3 - Relative Position G81
Now suppose that you execute the first G81 block of code but from (X0,
Y0, Z0) rather than from (X1, Y2, Z3).
----
G90 G98 G81 X4 Y5 Z1.5 R2.8
----
Since OLD_Z is below the R value, it adds
nothing for the motion but since the initial value of Z is less than
the value specified in R, there will be an initial Z move during the
preliminary moves.
image::images/G81.png[align="center"]
.Example 4 - Absolute G81 R > Z
This is a plot of the path of motion for the second g81 block of code.
----
G91 G98 G81 X4 Y5 Z-0.6 R1.8 L3
----
Since this plot starts with (X0, Y0, Z0), the interpreter adds the
initial Z0 and R1.8 and rapid moves to that location. After that initial Z
move, the repeat feature works the same as it did in example 3 with the
final Z depth being 0.6 below the R value.
image::images/G81a.png[align="center"]
.Example 5 - Relative position R > Z
----
G90 G98 G81 X4 Y5 Z-0.6 R1.8
----
Since this plot starts with (X0, Y0, Z0), the interpreter adds the initial Z0
and R1.8 and rapid moves to that location as in 'Example 4'. After that initial Z
move, the <<gcode:g0,rapid move>> to X4 Y5 is done. Then the final Z
depth being 0.6 below the R value. The repeat function would make the Z move
in the same location again.
[[gcode:g82]]
== G82 Drilling Cycle, Dwell
(((G82 Drilling Cycle Dwell)))
----
G82 (X- Y- Z-) or (U- V- W-) R- L- P-
----
The 'G82' cycle is intended for drilling with a dwell at the bottom of
the hole.
. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
. Move the Z-axis at the current <<sec:set-feed-rate,feed rate>> to the Z position.
. Dwell for the P number of seconds.
. The Z-axis does a <<gcode:g0,rapid move>> to clear Z.
The motion of a G82 canned cycle looks just like G81 with the
addition of a dwell at the bottom of the Z move. The length of
the dwell is specified by a 'P-' word in the G82 block.
[[gcode:g83]]
== G83 Peck Drilling Cycle
(((G83 Peck Drilling)))
----
G83 (X- Y- Z-) or (U- V- W-) R- L- Q-
----
The 'G83' cycle (often called peck drilling) is intended for deep
drilling or
milling with chip breaking. The retracts in this cycle clear the hole
of chips and cut off any long stringers (which are common when drilling
in aluminum). This cycle takes a Q number which represents a 'delta'
increment along the Z-axis. The retract before final depth will always
be to the 'retract' plane even if G98 is in effect. The final retract will
honor the G98/99 in effect. G83 functions the same as G81 with the addition
of retracts during the drilling operation.
. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
. Move the Z-axis at the current <<sec:set-feed-rate,feed rate>> downward by
delta or to the Z position, whichever is less deep.
. Rapid move back out to the retract plane specified by the R word.
. Rapid move back down to the current hole bottom, backed off a bit.
. Repeat steps 2, 3, and 4 until the Z position is reached at step 2.
. The Z-axis does a <<gcode:g0,rapid move>> to clear Z.
It is an error if:
* the Q number is negative or zero.
[[gcode:g84]]
== G84 Right-hand Tapping Cycle, Dwell
(((G84 Right-hand Tapping Cycle Dwell)))
----
G84 (X- Y- Z-) or (U- V- W-) R- L- P- $-
----
The 'G84' cycle is intended for tapping with floating chuck and dwell at the bottom of the hole.
1. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
2. Disable Feed and Speed Overrides.
3. Move the Z-axis at the current feed rate to the Z position.
4. Stop the seleted spindle (chosen by the $ parameter)
5. Start spindle rotation counterclockwise.
6. Dwell for the P number of seconds.
7. Move the Z-axis at the current feed rate to clear Z
8. Restore Feed and Speed override enables to previous state
The length of the dwell is specified by a 'P-' word in the G84 block. Thread pitch is F divided by S.
In example S100 F125 gives pitch of 1.25MM per revolution.
[[gcode:g85]]
== G85 Boring Cycle, Feed Out
(((G85 Boring, Feed Out)))
----
G85 (X- Y- Z-) or (U- V- W-) R- L-
----
The 'G85' cycle is intended for boring or reaming, but could be used
for drilling or milling.
. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
. Move the Z-axis only at the current <<sec:set-feed-rate,feed rate>> to the Z
position.
. Retract the Z-axis at the current feed rate to the R plane if it is lower
than the initial Z.
. Retract at the traverse rate to clear Z.
[[gcode:g86]]
== G86 Boring Cycle, Spindle Stop, Rapid Move Out
(((G86 Boring, Spindle Stop, Rapid Move Out)))
----
G86 (X- Y- Z-) or (U- V- W-) R- L- P- $-
----
The 'G86' cycle is intended for boring. This cycle uses a P number
for the number of seconds to dwell.
. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
. Move the Z-axis only at the current <<sec:set-feed-rate,feed rate>> to the Z
position.
. Dwell for the P number of seconds.
. Stop the selected spindle turning. (Chosen by the $ parameter)
. The Z-axis does a <<gcode:g0,rapid move>> to clear Z.
. Restart the spindle in the direction it was going.
It is an error if:
* the spindle is not turning before this cycle is executed.
== G87 Back Boring Cycle
This code is currently unimplemented in LinuxCNC. It is accepted, but the
behavior is undefined.
== G88 Boring Cycle, Spindle Stop, Manual Out
This code is currently unimplemented in LinuxCNC. It is accepted, but the
behavior is undefined.
[[gcode:g89]]
== G89 Boring Cycle, Dwell, Feed Out
(((G89 Boring, Dwell, Feed Out)))
----
G89 (X- Y- Z-) or (U- V- W-) R- L- P-
----
The 'G89' cycle is intended for boring. This cycle uses a P number,
where P specifies the number of seconds to dwell.
. Preliminary motion, as described in the
<<gcode:preliminary-motion,Preliminary and In-Between Motion>> section.
. Move the Z-axis only at the current <<sec:set-feed-rate,feed rate>> to the Z
position.
. Dwell for the P number of seconds.
. Retract the Z-axis at the current feed rate to clear Z.
[[gcode:g90-g91]]
== G90, G91 Distance Mode
(((G90, G91 Distance Mode)))
* 'G90' - absolute distance mode In absolute
distance mode, axis numbers (X, Y, Z, A, B, C, U, V, W)
usually represent positions in terms of the currently active
coordinate system. Any exceptions to that rule are described
explicitly in the <<gcode:g80-g89,G80 G89>> Section.
* 'G91' - incremental distance mode In incremental
distance mode, axis numbers usually represent
increments from the current coordinate.
.G90 Example
----
G90 (set absolute distance mode)
G0 X2.5 (rapid move to coordinate X2.5 including any offsets in effect)
----
.G91 Example
----
G91 (set incremental distance mode)
G0 X2.5 (rapid move 2.5 from current position along the X axis)
----
* See <<gcode:g0,G0>> section for more information.
[[gcode:g90.1-g91.1]]
== G90.1, G91.1 Arc Distance Mode
(((Arc Distance Mode)))
* 'G90.1' - absolute distance mode for I, J & K offsets.
When G90.1 is in effect I and J both must be specified with G2/3
for the XY plane or J and K for the XZ plane or it is an error.
* 'G91.1' - incremental distance mode for I, J & K offsets. G91.1 Returns
I, J & K to their default behavior.
[[gcode:g92]]
== G92 Coordinate System Offset
(((G92 Coordinate System Offset)))
----
G92 axes
----
[WARNING]
Only use 'G92' after your machine has been positioned to the desired point.
'G92' makes the current point have the coordinates you want (without
motion), where the axis words contain the axis numbers you want.
All axis words are optional, except that at least one must be used.
If an axis word is not used for a given axis, the offset for that axis
will be zero.
When 'G92' is executed, the <<sec.machine-corrdinate-system,origins>>
of all coordinate systems move. They move such that the value of the
current controlled point, in the currently active coordinate system,
becomes the specified value. All of the coordinate system's origins
(G53-G59.3) are offset this same distance.
'G92' uses the values stored in <<sub:numbered-parameters,parameters>>
5211-5219 as the X Y Z A B C U V W offset values for each axis.
The parameter values are 'absolute' machine coordinates
in the native machine 'units' as specified in the ini file.
All axes defined in the ini file will be offset when G92 is active.
If an axis was not entered following the G92, that axis' offset
will be zero.
For example, suppose the current point is at X=4 and there is
currently no 'G92' offset active. Then 'G92 X7' is programmed. This
moves all origins -3 in X, which causes the
current point to become X=7. This -3 is saved in parameter 5211.
Being in incremental distance mode (G91 instead of G90) has no effect
on the action of 'G92'.
'G92' offsets may be already be in effect when the 'G92' is called.
If this is the case, the offset is replaced with a new
offset that makes the current point become the specified value.
It is an error if:
* all axis words are omitted.
LinuxCNC stores the G92 offsets and reuses them on the next run of a
program. To prevent this, one can program a G92.1 (to erase them), or
program a G92.2 (to remove them - they are still stored).
[NOTE]
The 'G52' command can also be used to change this offset; see the
<<sec:g52-and-g92-offsets,Offsets>> Section for more details about
'G92' and 'G52' and how they interact.
See the <<cha:coordinate-system,Coordinate System>> Section for an
overview of coordinate systems.
See the <<gcode:parameters,Parameters>> Section for more information.
[[gcode:g92.1-g92.2]]
== G92.1, G92.2 Reset G92 Offsets
* 'G92.1' - turn off G92 offsets and reset <<sub:numbered-parameters,parameters>> 5211 - 5219 to zero.
* 'G92.2' - turn off G92 offsets but keep <<sub:numbered-parameters,parameters>> 5211 - 5219 available.
[NOTE]
G92.1 only clears G92 offsets, to change G53-G59.3 coordinate system offsets
in G code use either <<gcode:g10-l2,G10 L2>> or <<gcode:g10-l20,G10 L20>>.
[[gcode:g92.3]]
== G92.3 Restore G92 Offsets
(((G92.3 Restore G92 Offsets)))
* 'G92.3' - set the G92 offset to the values saved in parameters 5211 to 5219
You can set axis offsets in one program and use the same offsets in
another program. Program 'G92' in the first program. This will set
parameters 5211 to 5219. Do not use 'G92.1' in the remainder of the
first program. The parameter values will be saved when the first
program exits and restored when the second one starts up.
Use 'G92.3' near the beginning of the second program. That will restore
the offsets saved in the first program.
[[gcode:g93-g94-g95]]
== G93, G94, G95: Feed Rate Mode
(((G93, G94, G95: Feed Rate Mode)))
* 'G93' - is Inverse Time Mode. In inverse time feed rate mode, an F word
means the move should be completed in [one divided by the F number]
minutes. For example, if the F number is 2.0, the move should be
completed in half a minute.
+
When the inverse time feed rate mode is active, an F word must appear
on every line which has a G1, G2, or G3 motion, and an F word on a line
that does not have G1, G2, or G3 is ignored. Being in inverse time feed
rate mode does not affect G0 (<<gcode:g0,rapid move>>) motions.
* 'G94' - is Units per Minute Mode.
In units per minute feed mode, an F word is interpreted to mean
the controlled point should move at a certain number of inches per
minute, millimeters per minute, or degrees per minute, depending upon
what length units are being used and which axis or axes are moving.
* 'G95' - is Units per Revolution Mode
In units per revolution mode, an F word is interpreted to mean the
controlled point should move a certain number of inches per revolution
of the spindle, depending on what length units are being used and which
axis or axes are moving. G95 is not suitable for threading, for
threading use G33 or G76.
G95 requires that spindle.N.speed-in to be connected. The actual spindle
to which the feed is synchronised is chosen by the $ parameter
It is an error if:
* Inverse time feed mode is active and a line with G1, G2, or G3
(explicitly or implicitly) does not have an F word.
* A new feed rate is not specified after switching to G94 or G95
[[gcode:g96-g97]]
== G96, G97 Spindle Control Mode
(((G96, G97 Spindle Control Mode)))
----
G96 <D-> S- <$-> (Constant Surface Speed Mode)
G97 S- <$-> (RPM Mode)
----
* 'D' - maximum spindle RPM
* 'S' - surface speed
* '$" - the spindle of which the speed will be varied.
* 'G96 D- S-' - selects constant surface speed of 'S' feet per minute
(if G20 is in effect) or meters per minute
(if G21 is in effect). D- is optional.
+
When using G96, ensure that X0 in
the current coordinate system (including offsets and tool lengths) is
the center of rotation or LinuxCNC will not give the desired ssurface speed.
G96 is not affected by radius or diameter mode.
To achieve CSS mode on selected spindles programme successive G96 commands
for each spindle prior to issuing M3.
* 'G97' selects RPM mode.
.G96 Example Line
----
G96 D2500 S250 (set CSS with a max rpm of 2500 and a surface speed of 250)
----
It is an error if:
* S is not specified with G96
* A feed move is specified in G96 mode while the spindle is not turning
[[gcode:g98-g99]]
== G98, G99 Canned Cycle Return Level
(((G98, G99 Canned Cycle Return)))
* 'G98' - retract to the position that axis was in just before this series
of one or more contiguous canned cycles was started.
* 'G99' - retract to the position specified by the R word of the canned cycle.
Program a 'G98' and the canned cycle will use the Z position prior to
the canned cycle as the Z return position if it is higher than the R
value specified in the cycle. If it is lower, the R value will be
used. The R word has different meanings in absolute distance mode and
incremental distance mode.
.G98 Retract to Origin
----
G0 X1 Y2 Z3
G90 G98 G81 X4 Y5 Z-0.6 R1.8 F10
----
The G98 to the second line above means that the return move will be to
the value of Z in the first line since it is higher that the R value
specified.
The 'initial' (G98) plane is reset any time cycle motion mode is
abandoned, whether explicitly (G80) or implicitly (any motion code
that is not a cycle). Switching among cycle modes (say G81
to G83) does NOT reset the 'initial' plane. It is possible to switch
between G98 and G99 during a series of cycles.
// vim: set syntax=asciidoc:
[[cha:m-codes]]
= M Codes
:ini: {basebackend@docbook:'':ini}
:hal: {basebackend@docbook:'':hal}
:ngc: {basebackend@docbook:'':ngc}
== M Code Quick Reference Table
[width="60%", options="header", cols="2^,5<"]
|========================================
|Code | Description
|<<mcode:m0-m1,M0 M1>> | Program Pause
|<<mcode:m2-m30,M2 M30>> | Program End
|<<mcode:m60, M60>> | Pallet Change Pause
|<<mcode:m3-m4-m5,M3 M4 M5>> | Spindle Control
|<<mcode:m6,M6>> | Tool Change
|<<mcode:m7-m8-m9,M7 M8 M9>> | Coolant Control
|<<mcode:m19,M19>> | Orient Spindle
|<<mcode:m48-m49,M48 M49>> | Feed & Spindle Overrides Enable/Disable
|<<mcode:m50,M50>> | Feed Override Control
|<<mcode:m51,M51>> | Spindle Override Control
|<<mcode:m52,M52>> | Adaptive Feed Control
|<<mcode:m53,M53>> | Feed Stop Control
|<<mcode:m61,M61>> | Set Current Tool Number
|<<mcode:m62-m65,m62-m65>> | Output Control
|<<mcode:m66,M66>> | Input Control
|<<mcode:m67,M67>> | Analog Output Control
|<<mcode:m68,M68>> | Analog Output Control
|<<mcode:m70,M70>> | Save Modal State
|<<mcode:m71,M71>> | Invalidate Stored Modal State
|<<mcode:m72,M72>> | Restore Modal State
|<<mcode:m73,M73>> | Save Autorestore Modal State
|<<mcode:m98-m99,M98 M99>> | Call and Return From Subprogram
|<<mcode:m100-m199,M100-M199>> | User Defined M-Codes
|========================================
[[mcode:m0-m1]]
== M0, M1 Program Pause
(((M0, M1 Program Pause)))
* 'M0' - pause a running program temporarily. LinuxCNC remains in the Auto Mode
so MDI and other manual actions are not enabled. Pressing the resume
button will restart the program at the following line.
* 'M1' - pause a running program temporarily if the optional stop switch is on.
LinuxCNC remains in the Auto Mode so MDI and other manual actions are
not enabled. Pressing the resume button will restart the program at the
following line.
[NOTE]
It is OK to program 'M0' and 'M1' in MDI mode,
but the effect will probably not be noticeable,
because normal behavior in MDI mode is
to stop after each line of input anyway.
[[mcode:m2-m30]]
== M2, M30 Program End
(((M2, M30 Program End)))
* 'M2' - end the program. Pressing r will
start the program at the beginning of the file.
* 'M30' - exchange pallet shuttles and end the program.
Pressing cycle start will start the program
at the beginning of the file.
Both of these commands have the following effects:
. Change from Auto mode to MDI mode.
. Origin offsets are set to the default (like 'G54').
. Selected plane is set to XY plane (like 'G17').
. Distance mode is set to absolute mode (like 'G90').
. Feed rate mode is set to units per minute (like 'G94').
. Feed and speed overrides are set to ON (like 'M48').
. Cutter compensation is turned off (like 'G40').
. The spindle is stopped (like 'M5').
. The current motion mode is set to feed (like 'G1').
. Coolant is turned off (like 'M9').
[NOTE]
Lines of code after M2/M30 will not be executed. Pressing cycle start will
start the program at the beginning of the file.
[WARNING]
Using % to wrap the G code does not do the same thing as a 'Program End'. See
<<gcode:file-requirements,File Requirements>> for more information on what using
% does not do.
[[mcode:m60]]
== M60 Pallet Change Pause
(((M60 Pallet Change Pause)))
* 'M60' - exchange pallet shuttles and then pause a running program
temporarily (regardless of the setting of the optional stop
switch). Pressing the cycle start button
will restart the program at the following line.
[[mcode:m3-m4-m5]]
== M3, M4, M5 Spindle Control
(((M3, M4, M5 Spindle Control)))
* 'M3' - start the selected spindle clockwise at the 'S' speed.
* 'M4' - start the selected spindle counterclockwise at the 'S' speed.
* 'M5' - stop the selected spindle.
Use $ to operate on specific spindles. If $ is omitted then thr commands
operate on all spindles.
For example
[source,{ngc}]
---
S100 $0
S200 $1
S300 $2
M3
----
Will start all three spindles simultaneously at different speeds
[source,{ngc]]
----
M4 $1
----
Will then reverse spindle 1 but leave the other spindles rotating forwards.
If the $ is omitted then behaviour is exactly as normal for a single
spindle machine
It is OK to use 'M3' or 'M4' if the <<sec:set-spindle-speed,S>>
spindle speed is set to zero. If this is done
(or if the speed override switch is enabled and set to zero),
the spindle will not start turning.
If, later, the spindle speed is set above zero
(or the override switch is turned up),
the spindle will start turning.
It is OK to use 'M3' or 'M4' when the spindle is already
turning or to use 'M5' when the spindle is already stopped.
[[mcode:m6]]
== M6 Tool Change
(((M6-Tool-Change)))
=== Manual Tool Change
If the HAL component hal_manualtoolchange is loaded,
M6 will stop the spindle and prompt the user to change the tool
based on the last 'T-' number programmed.
For more information on hal_manualtoolchange see
the <<sec:manual-tool-change,Manual Tool Change>> section.
=== Tool Changer
To change a tool in the spindle from the tool currently in the spindle
to the tool most recently selected (using a T word - see Section
<<sec:select-tool,Select Tool>>), program 'M6'.
When the tool change is complete:
* The spindle will be stopped.
* The tool that was selected (by a T word on the same line or on any
line after the previous tool change) will be in the spindle.
* If the selected tool was not in the spindle before the tool change,
the tool that was in the spindle (if there was one) will be placed
back into the tool changer magazine.
* If configured in the .ini file some axis positions may move when a M6
is issued. See the <<sec:emcio-section,EMCIO section>> for more
information on tool change options.
* No other changes will be made. For example, coolant will continue to
flow during the tool change unless it has been turned off by an 'M9'.
[WARNING]
The tool length offset is not changed by 'M6', use 'G43' after the
'M6' to change the tool length offset.
The tool change may include axis motion.
It is OK (but not useful) to program a change to the tool already in the spindle.
It is OK if there is no tool in the selected slot;
in that case, the spindle will be empty after the tool change.
If slot zero was last selected,
there will definitely be no tool in the spindle after a tool change. The tool
changer will have to be setup to perform the tool change in hal and possibly
classicladder.
[[mcode:m7-m8-m9]]
== M7, M8, M9 Coolant Control
(((M7, M8, M9 Coolant Control)))
* 'M7' - turn mist coolant on. M7 controls iocontrol.0.coolant-mist pin.
* 'M8' - turn flood coolant on. M8 controls iocontrol.0.coolant-flood pin.
* 'M9' - turn both M7 and M8 off.
Connect one or both of the coolant control pins in HAL before M7 or M8 will
control an output. M7 and M8 can be used to turn on any output via G code.
It is OK to use any of these commands, regardless of the current coolant
state.
[[mcode:m19]]
== M19 Orient Spindle
(((M19 Orient Spindle)))
* 'M19 R- Q- [P-] [$-]'
* 'R' Position to rotate to from 0, valid range is 0-360 degrees
* 'Q' Number of seconds to wait until orient completes. If
spindle.N.is-oriented does not become true within Q timeout
an error occurs.
* 'P' Direction to rotate to position.
** '0' rotate for smallest angular movement (default)
** '1' always rotate clockwise (same as M3 direction)
** '2' always rotate counterclockwise (same as M4 direction)
* '$' The spindle to orient (actually only determines which HAL pins
carry the spindle position commands)
M19 is cleared by any of M3,M4,M5.
Spindle orientation requires a quadrature encoder with an index to sense the
spindle shaft position and direction of rotation.
INI Settings in the [RS274NGC] section.
ORIENT_OFFSET = 0-360 (fixed offset in degrees added to M19 R word)
HAL Pins
* 'spindle.N.orient-angle' (out float)
Desired spindle orientation for M19. Value of the M19 R word parameter
plus the value of the [RS274NGC]ORIENT_OFFSET ini parameter.
* 'spindle.N.orient-mode' (out s32)
Desired spindle rotation mode. Reflects M19 P parameter word, Default = 0
* 'spindle.N.orient' (out bit)
Indicates start of spindle orient cycle. Set by M19. Cleared by any of
M3,M4,M5.
If spindle-orient-fault is not zero during spindle-orient true, the
M19 command fails with an error message.
* 'spindle.N.is-oriented' (in bit)
Acknowledge pin for spindle-orient. Completes orient cycle. If
spindle-orient was true when spindle-is-oriented
was asserted, the spindle-orient pin is cleared and the spindle-locked
pin is asserted. Also, the spindle-brake pin is asserted.
* 'spindle.N.orient-fault' (in s32)
Fault code input for orient cycle. Any value other than zero will
cause the orient cycle to abort.
* 'spindle.N.locked' (out bit)
Spindle orient complete pin. Cleared by any of M3,M4,M5.
[[mcode:m48-m49]]
== M48, M49 Speed and Feed Override Control
(((M48, M49 Speed and Feed Override Control)))
* 'M48' - enable the spindle speed and feed rate override controls.
* 'M49' - disable both controls.
These commands also take an optional $ parameter to determine which
spindle they operate on.
It is OK to enable or disable the controls when
they are already enabled or disabled.
See the <<sub:feed-rate,Feed Rate>> Section for more details.
[[mcode:m50]]
== M50 Feed Override Control
(((M50 Feed Override Control)))
* 'M50 <P1>' - enable the feed rate override control. The P1
is optional.
* 'M50 P0' - disable the feed rate control.
While disabled the feed override will have no influence,
and the motion will be executed at programmed feed rate.
(unless there is an adaptive feed rate override active).
[[mcode:m51]]
== M51 Spindle Speed Override Control
(((M51 Spindle Speed Override)))
* 'M51 <P1> <$->'- enable the spindle speed override control for the
selected spindle. The P1 is optional.
* 'M51 P0 <$->' - disable the spindle speed override control program.
While disabled the spindle speed override will have
no influence, and the spindle speed will have the
exact program specified value of the S-word
(described in <<sec:set-spindle-speed,Spindle Speed>> Section).
[[mcode:m52]]
== M52 Adaptive Feed Control
(((M52 Adaptive Feed Control)))
* 'M52 <P1>' - use an adaptive feed. The P1 is optional.
* 'M52 P0' - stop using adaptive feed.
When adaptive feed is enabled, some external input value is used together
with the user interface feed override value and the commanded feed rate
to set the actual feed rate. In LinuxCNC, the HAL pin 'motion.adaptive-feed'
is used for this purpose. Values on 'motion.adaptive-feed' should range
from 0 (feed hold) to 1 (full speed).
[[mcode:m53]]
== M53 Feed Stop Control
(((M53 Feed Stop Control)))
* 'M53 <P1>' - enable the feed stop switch. The P1 is optional.
Enabling the feed stop switch will allow motion to be
interrupted by means of the feed stop control. In LinuxCNC,
the HAL pin 'motion.feed-hold' is used for this purpose. A 'true'
value will cause the motion to stop when 'M53' is active.
* 'M53 P0' - disable the feed stop switch. The state of 'motion.feed-hold'
will have no effect on feed when M53 is not active.
[[mcode:m61]]
== M61 Set Current Tool
(((M61 Set Current Tool)))
* 'M61 Q-' - change the current tool number while in MDI or Manual mode.
One use is when you power up LinuxCNC with a tool currently in
the spindle you can set that tool number without doing a tool change.
It is an error if:
* Q- is not 0 or greater
[[mcode:m62-m65]]
== M62 - M65 Digital Output Control
(((M62 - M65 Digital Output Control)))
* 'M62 P-' - turn on digital output synchronized with motion.
The P- word specifies the digital output number.
* 'M63 P-' - turn off digital output synchronized with motion.
The P- word specifies the digital output number.
* 'M64 P-' - turn on digital output immediately.
The P- word specifies the digital output number.
* 'M65 P-' - turn off digital output immediately.
The P- word specifies the digital output number.
The P-word ranges from 0 to a default value of 3. If needed the the
number of I/O can be increased by using the num_dio parameter when loading
the motion controller. See the <<sec:motion,Motion Section>> for more
information.
The M62 & M63 commands will be queued. Subsequent commands referring
to the same output number will overwrite the older settings. More than
one output change can be specified by issuing more than one M62/M63
command.
The actual change of the specified outputs will happen at the
beginning of the next motion command. If there is no subsequent motion
command, the queued output changes won't happen. It's best to always
program a motion G code (G0, G1, etc) right after the M62/63.
M64 & M65 happen immediately as they are received by the motion
controller. They are not synchronized with movement, and they will
break blending.
[NOTE]
M62-65 will not function unless the appropriate motion.digital-out-nn pins are
connected in your hal file to outputs.
[[mcode:m66]]
== M66 Wait on Input
(((M66 Wait on Input)))
----
M66 P- | E- <L->
----
* 'P-' - specifies the digital input number from 0 to 3.
* 'E-' - specifies the analog input number from 0 to 3.
* 'L-' - specifies the wait mode type.
** 'Mode 0: IMMEDIATE' - no waiting, returns immediately.
The current value of the input is stored in parameter #5399
** 'Mode 1: RISE' - waits for the selected input to perform a rise event.
** 'Mode 2: FALL' - waits for the selected input to perform a fall event.
** 'Mode 3: HIGH' - waits for the selected input to go to the HIGH state.
** 'Mode 4: LOW' - waits for the selected input to go to the LOW state.
* 'Q-' - specifies the timeout in seconds for waiting. If the timeout is
exceeded, the wait is interrupt, and the variable #5399 will be holding
the value -1. The Q value is ignored if the L-word is zero (IMMEDIATE).
A Q value of zero is an error if the L-word is non-zero.
* Mode 0 is the only one permitted for an analog input.
.M66 Example Lines
----
M66 P0 L3 Q5 (wait up to 5 seconds for digital input 0 to turn on)
----
M66 wait on an input stops further execution of the program, until the
selected event (or the programmed timeout) occurs.
It is an error to program M66 with both a P-word and an E-word (thus
selecting both an analog and a digital input). In LinuxCNC these
inputs are not monitored in real time and thus should not be used for
timing-critical applications.
The number of I/O can be increased by using the num_dio or num_aio parameter
when loading the motion controller. See the <<sec:motion,Motion Section>>
for more information.
[NOTE]
M66 will not function unless the appropriate motion.digital-in-nn pins or
motion.analog-in-nn pins are connected in your hal file to an input.
.Example HAL Connection
----
net signal-name motion.digital-in-00 <= parport.0.pin10-in
----
[[mcode:m67]]
== M67 Analog Output,Synchronized
(((M67 Analog Output, Synchronized)))
----
M67 E- Q-
----
* 'M67' - set an analog output synchronized with motion.
* 'E-' - output number ranging from 0 to 3.
* 'Q-' - is the value to set (set to 0 to turn off).
The actual change of the specified outputs will happen at the
beginning of the next motion command. If there is no subsequent motion
command, the queued output changes won't happen. It's best to always
program a motion G code (G0, G1, etc) right after the M67. M67 functions
the same as M62-63.
The number of I/O can be increased by using the num_dio or num_aio parameter
when loading the motion controller. See the <<sec:motion,Motion Section>> for
more information.
[NOTE]
M67 will not function unless the appropriate motion.analog-out-nn pins are
connected in your hal file to outputs.
[[mcode:m68]]
== M68 Analog Output, Immediate
(((M68 Analog Output)))
----
M68 E- Q-
----
* 'M68' - set an analog output immediately.
* 'E-' - output number ranging from 0 to 3.
* 'Q-' - is the value to set (set to 0 to turn off).
M68 output happen immediately as they are received by the motion
controller. They are not synchronized with movement, and they will
break blending. M68 functions the same as M64-65.
The number of I/O can be increased by using the num_dio or num_aio parameter
when loading the motion controller. See the <<sec:motion,Motion Section>> for
more information.
[NOTE]
M68 will not function unless the appropriate motion.analog-out-nn pins are
connected in your hal file to outputs.
[[mcode:m70]]
== M70 Save Modal State
(((M70 Save Modal State)))
To explicitly save the modal state at the current call level, program
'M70'. Once modal state has been saved with 'M70', it can be restored
to exactly that state by executing an 'M72'.
A pair of 'M70' and 'M72' instructions will typically be used to
protect a program against inadvertant modal changes within
subroutines.
[[mcode:m70-saved-state]]
The state saved consists of:
* current G20/G21 settings (imperial/metric)
* selected plane (G17/G18/G19 G17.1,G18.1,G19.1)
* status of cutter compensation (G40,G41,G42,G41.1,G42,1)
* distance mode - relative/absolute (G90/G91)
* feed mode (G93/G94,G95)
* current coordinate system (G54-G59.3)
* tool length compensation status (G43,G43.1,G49)
* retract mode (G98,G99)
* spindle mode (G96-css or G97-RPM)
* arc distance mode (G90.1, G91.1)
* lathe radius/diameter mode (G7,G8)
* path control mode (G61, G61.1, G64)
* current feed and speed ('F' and 'S' values)
* spindle status (M3,M4,M5) - on/off and direction
* mist (M7) and flood (M8) status
* speed override (M51) and feed override (M50) settings
* adaptive feed setting (M52)
* feed hold setting (M53)
Note that in particular, the motion mode (G1 etc) is NOT restored.
'current call level' means either:
* executing in the main program. There is a single storage location
for state at the main program level; if several 'M70' instructions
are executed in turn, only the most recently saved state is restored
when an 'M72' is executed.
* executing within a G-code subroutine. The state saved with 'M70'
within a subroutine behaves exactly like a local named parameter - it
can be referred to only within this subroutine invocation with an
'M72' and when the subroutine exits, the parameter goes away.
A recursive invocation of a subroutine introduces a new call level.
[[mcode:m71]]
== M71 Invalidate Stored Modal State
(((M71 Invalidate Stored Modal State)))
Modal state saved with an 'M70' or by an 'M73' at the current call
level is invalidated (cannot be restored from anymore).
A subsequent 'M72' at the same call level will fail.
If executed in a subroutine which protects modal state by an 'M73', a
subsequent return or endsub will *not* restore modal state.
The usefulness of this feature is dubious. It should not be relied upon as it might
go away.
[[mcode:m72]]
== M72 Restore Modal State
(((M72 Restore Modal State)))
<<mcode:m70-saved-state,Modal state saved with an 'M70'>> code can be
restored by executing an 'M72'.
The handling of G20/G21 is specially treated as feeds are interpreted
differently depending on G20/G21: if length units (mm/in) are about to
be changed by the restore operation, 'M72 'will restore the distance
mode first, and then all other state including feed to make sure the
feed value is interpreted in the correct unit setting.
It is an error to execute an 'M72' with no previous 'M70' save
operation at that level.
The following example demonstrates saving and explicitely restoring
modal state around a subroutine call using 'M70' and 'M72'. Note that
the 'imperialsub' subroutine is not "aware" of the M7x features and can be
used unmodified:
[source,{ngc}]
----
O<showstate> sub
(DEBUG, imperial=#<_imperial> absolute=#<_absolute> feed=#<_feed> rpm=#<_rpm>)
O<showstate> endsub
O<imperialsub> sub
g20 (imperial)
g91 (relative mode)
F5 (low feed)
S300 (low rpm)
(debug, in subroutine, state now:)
o<showstate> call
O<imperialsub> endsub
; main program
g21 (metric)
g90 (absolute)
f200 (fast speed)
S2500 (high rpm)
(debug, in main, state now:)
o<showstate> call
M70 (save caller state in at global level)
O<imperialsub> call
M72 (explicitely restore state)
(debug, back in main, state now:)
o<showstate> call
m2
----
[[mcode:m73]]
== M73 Save and Autorestore Modal State
(((M73 Save and Autorestore Modal State)))
To save modal state within a subroutine, and restore state on
subroutine 'endsub' or any 'return' path, program 'M73'.
Aborting a running program in a subroutine which has an 'M73'
operation will *not* restore state .
Also, the normal end ('M2') of a main program which contains an 'M73'
will *not* restore state.
The suggested use is at the beginning of a O-word subroutine as in the
following example. Using 'M73' this way enables designing subroutines
which need to modify modal state but will protect the calling program
against inadvertant modal changes. Note the use of
<<gcode:predefined-named-parameters, predefined named parameters>> in
the 'showstate' subroutine.
[source,{ngc}]
----
O<showstate> sub
(DEBUG, imperial=#<_imperial> absolute=#<_absolute> feed=#<_feed> rpm=#<_rpm>)
O<showstate> endsub
O<imperialsub> sub
M73 (save caller state in current call context, restore on return or endsub)
g20 (imperial)
g91 (relative mode)
F5 (low feed)
S300 (low rpm)
(debug, in subroutine, state now:)
o<showstate> call
; note - no M72 is needed here - the following endsub or an
; explicit 'return' will restore caller state
O<imperialsub> endsub
; main program
g21 (metric)
g90 (absolute)
f200 (fast speed)
S2500 (high rpm)
(debug, in main, state now:)
o<showstate> call
o<imperialsub> call
(debug, back in main, state now:)
o<showstate> call
m2
----
[[mcode:m98-m99]]
== M98 and M99 ==
The interpreter supports Fanuc-style main- and sub-programs with the
'M98' and 'M99' M-codes. See <<ocode:fanuc-style-programs,Fanuc-Style
Programs>>.
=== Selectively Restoring Modal State
Executing an 'M72' or returning from a subroutine which contains an
'M73' will restore <<mcode:m70-saved-state,*all* modal state saved>>.
If only some aspects of modal state should be preserved, an
alternative is the usage of <<gcode:predefined-named-parameters,
predefined named parameters>>, local parameters and conditional
statements. The idea is to remember the modes to be restored at the
beginning of the subroutine, and restore these before exiting. Here is
an example, based on snippet of 'nc_files/tool-length-probe.ngc':
[source,{ngc}]
----
O<measure> sub (measure reference tool)
;
#<absolute> = #<_absolute> (remember in local variable if G90 was set)
;
g30 (above switch)
g38.2 z0 f15 (measure)
g91 g0z.2 (off the switch)
#1000=#5063 (save reference tool length)
(print,reference length is #1000)
;
O<restore_abs> if [#<absolute>]
g90 (restore G90 only if it was set on entry:)
O<restore_abs> endif
;
O<measure> endsub
----
[[mcode:m100-m199]]
== M100 - M199 User Defined Commands
(((M100 - M199 User Defined Commands)))
----
M1-- <P- Q->
----
* 'M1--' - an integer in the range of 100 - 199.
* 'P-' - a number passed to the file as the first parameter.
* 'Q-' - a number passed to the file as the second parameter.
[NOTE]
After creating a new 'M1nn' file you must restart the GUI so it is aware
of the new file, otherwise you will get an 'Unkown m code' error.
The external program named 'M100' through 'M199' (no extension and a capitol M)
is executed with the optional P and Q values as its two arguments.
Execution of the G code file pauses until the external program exits.
Any valid executable file can be used. The file must be located in the search
path specificed in the ini file configuration. See the
<<sec:display-section,Display Section>> for more information on search paths.
[WARNING]
Do not use a word processor to create or edit the files. A word processor
will leave unseen codes that will cause problems and may prevent a bash or
python file from working. Use a text editor like Gedit in Ubuntu or Notepad++
in other operating systems to create or edit the files.
The error 'Unknown M code used' denotes one of the following
* The specified User Defined Command does not exist
* The file is not an executable file
* The file name has an extension
* The file name does not follow this format M1nn where nn = 00 through 99
* The file name used a lower case M
For example to open and close a collet closer that is controlled by a
parallel port pin using a bash script file using M101 and M102. Create two
files named M101 and M102. Set them as executable files (typically
right click/properties/permissions) before running LinuxCNC. Make sure the
parallel port pin is not connected to anything in a HAL file.
.M101 Example File
----
#!/bin/bash
# file to turn on parport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out True
exit 0
----
.M102 Example File
----
#!/bin/bash
# file to turn off parport pin 14 to open the collet closer
halcmd setp parport.0.pin-14-out False
exit 0
----
To pass a variable to a M1nn file you use the P and Q option like this:
----
M100 P123.456 Q321.654
----
.M100 Example file
----
#!/bin/bash
voltage=$1
feedrate=$2
halcmd setp thc.voltage $voltage
halcmd setp thc.feedrate $feedrate
exit 0
----
To display a graphic message and stop until the message window is closed
use a graphic display program like Eye of Gnome to display the graphic
file. When you close it the program will resume.
.M110 Example file
----
#!/bin/bash
eog /home/john/linuxcnc/nc_files/message.png
exit 0
----
To display a graphic message and continue processing the G code file
suffix an ampersand to the command.
.M110 Example display and keep going
----
#!/bin/bash
eog /home/john/linuxcnc/nc_files/message.png &
exit 0
----
// vim: set syntax=asciidoc:
[[cha:cnc-machine-overview]]
= CNC Machine Overview
This section gives a brief description of how a CNC machine is viewed
from the input and output ends of the Interpreter.
== Mechanical Components
A CNC machine has many mechanical components that may be controlled or
may affect the way in which control is exercised. This section
describes the subset of those components that interact with the
Interpreter. Mechanical components that do not interact directly with
the Interpreter, such as the jog buttons, are not described here, even
if they affect control.
=== Axes
Any CNC machine has one or more Axes. Different types of CNC machines
have different combinations. For instance, a '4-axis milling machine'
may have XYZA or XYZB axes. A lathe typically has XZ axes. A
foam-cutting machine may have XYUV axes. In LinuxCNC, the case of a XYYZ
'gantry' machine with two motors for one axis is better handled by
kinematics rather than by a second linear axis. footnote:[If the
motion of mechanical components is not independent, as with
hexapod machines, the RS274/NGC language and the canonical machining
functions will still be usable, as long as the lower levels of control
know how to control the actual mechanisms to produce the same relative
motion of tool and workpiece as would be produced by independent axes.
This is called 'kinematics'.]
.Primary Linear Axes (((axes, primary linear)))
The X, Y, and Z axes produce linear motion in three mutually
orthogonal directions.
.Secondary Linear Axes (((axes, secondary linear)))
The U, V, and W axes produce linear motion in three mutually
orthogonal directions. Typically, X and U are parallel, Y and V are
parallel, and Z and W are parallel.
.Rotational Axes (((axes, rotational)))
The A, B and C axes produce angular motion (rotation). Typically, A
rotates around a line parallel to X, B rotates around a line parallel
to Y, and C rotates around a line parallel to Z.
=== Spindle (((spindle)))
A CNC machine typically has a spindle which holds one cutting tool,
probe, or the material in the case of a lathe. The spindle may or may
not be controlled by the CNC software.
LinuxCNC offers suport for up to 8 spindles, which can be individually
controlled and can run simultaneously at different speeds and in different
directions.
=== Coolant (((coolant)))
If a CNC machine has components to provide mist coolant and/or flood
coolant they can be controlled by G codes.
=== Feed and Speed Override
A CNC machine can have separate feed and speed override controls,
which let the operator specify that the actual feed rate or spindle
speed used in machining at some percentage of the programmed rate.
=== Block Delete Switch
A CNC machine can have a block delete switch. See the
<<sub:block-delete-switch,Block Delete>> Section.
=== Optional Program Stop Switch
A CNC machine can have an optional program stop switch. See the
<<sub:optional-program-stop,Optional Program Stop>> Section.
== Control and Data Components
=== Linear Axes
The X, Y, and Z axes form a standard right-handed coordinate system of
orthogonal linear axes. Positions of the three linear motion mechanisms
are expressed using coordinates on these axes.
The U, V and W axes also form a standard right-handed coordinate
system. X and U are parallel, Y and V are parallel, and Z and W are
parallel (when A, B, and C are rotated to zero).
=== Rotational Axes
The rotational axes are measured in degrees as wrapped linear axes in
which the direction of positive rotation is counterclockwise when
viewed from the positive end of the corresponding X, Y, or Z-axis. By
'wrapped linear axis', we mean one on which the angular position
increases without limit (goes towards plus infinity) as the axis turns
counterclockwise and deceases without limit (goes towards minus
infinity) as the axis turns clockwise. Wrapped linear axes are used
regardless of whether or not there is a mechanical limit on rotation.
Clockwise or counterclockwise is from the point of view of the
workpiece. If the workpiece is fastened to a turntable which turns on a
rotational axis, a counterclockwise turn from the point of view of the
workpiece is accomplished by turning the turntable in a direction that
(for most common machine configurations) looks clockwise from the point
of view of someone standing next to the machine. footnote:[If the
parallelism requirement is violated, the system builder will
have to say how to distinguish clockwise from counterclockwise.]
=== Controlled Point
The controlled point is the point whose position and rate of motion
are controlled. When the tool length offset is zero (the default
value), this is a point on the spindle axis (often called the gauge
point) that is some fixed distance beyond the end of the spindle,
usually near the end of a tool holder that fits into the spindle. The
location of the controlled point can be moved out along the spindle
axis by specifying some positive amount for the tool length offset.
This amount is normally the length of the cutting tool in use, so that
the controlled point is at the end of the cutting tool. On a lathe,
tool length offsets can be specified for X and Z axes, and the
controlled point is either at the tool tip or slightly outside it
(where the perpendicular, axis-aligned lines touched by the 'front' and
'side' of the tool intersect).
=== Coordinated Linear Motion
To drive a tool along a specified path, a machining center must often
coordinate the motion of several axes. We use the term 'coordinated
linear motion' to describe the situation in which, nominally, each axis
moves at constant speed and all axes move from their starting positions
to their end positions at the same time. If only the X, Y, and Z axes
(or any one or two of them) move, this produces motion in a straight
line, hence the word 'linear' in the term. In actual motions, it is
often not possible to maintain constant speed because acceleration or
deceleration is required at the beginning and/or end of the motion. It
is feasible, however, to control the axes so that, at all times, each
axis has completed the same fraction of its required motion as the
other axes. This moves the tool along same path, and we also call this
kind of motion coordinated linear motion.
Coordinated linear motion can be performed either at the prevailing
feed rate, or at traverse rate, or it may be synchronized to the
spindle rotation. If physical limits on axis speed make the desired
rate unobtainable, all axes are slowed to maintain the desired path.
[[sub:feed-rate]](((Feed Rate)))
=== Feed Rate
The rate at which the controlled point moves is nominally a steady
rate which may be set by the user. In the Interpreter, the feed
rate is interpreted as follows (unless 'inverse time feed' or 'feed
per revolution' modes are being used, in which case see Section
<<gcode:g93-g94-g95,G93-G94-G95-Mode,G93 G94 G95>>).
. If any of XYZ are moving, F is in units per minute in the XYZ
cartesian system, and all other axes (ABCUVW) move so as to start and
stop in coordinated fashion.
. Otherwise, if any of UVW are moving, F is in units per minute in the
UVW cartesian system, and all other axes (ABC) move so as to start and
stop in coordinated fashion.
. Otherwise, the move is pure rotary motion and the F word is in rotary
units in the ABC 'pseudo-cartesian' system.
=== Coolant (((coolant)))
Flood coolant and mist coolant may each be turned on independently.
The RS274/NGC language turns them off together see Section
<<mcode:m7-m8-m9,M7 M8 M9>>.
=== Dwell (((dwell)))
A machining center may be commanded to dwell (i.e., keep all axes
unmoving) for a specific amount of time. The most common use of dwell
is to break and clear chips, so the spindle is usually turning during a
dwell. Regardless of the Path Control Mode (see Section
<<sec:path-control-mode,Path Control>>) the machine will stop exactly at the end of
the previous programmed move, as though it was in exact path mode.
=== Units (((units)))
Units used for distances along the X, Y, and Z axes may be measured in
millimeters or inches. Units for all other quantities involved in
machine control cannot be changed. Different quantities use different
specific units. Spindle speed is measured in revolutions per minute.
The positions of rotational axes are measured in degrees. Feed rates
are expressed in current length units per minute, or degrees per
minute, or length units per spindle revolution, as described in Section
<<gcode:g93-g94-g95,G93 G94 G95>>.
=== Current Position
The controlled point is always at some location called the 'current
position', and the controller always knows where that is. The numbers
representing the current position must be adjusted in the absence of
any axis motion if any of several events take place:
. Length units are changed.
. Tool length offset is changed.
. Coordinate system offsets are changed.
=== Selected Plane
There is always a 'selected plane', which must be the XY-plane, the
YZ-plane, or the XZ-plane of the machining center. The Z-axis is, of
course, perpendicular to the XY-plane, the X-axis to the YZ-plane, and
the Y-axis to the XZ-plane.
=== Tool Carousel
Zero or one tool is assigned to each slot in the tool carousel.
=== Tool Change
A machining center may be commanded to change tools.
=== Pallet Shuttle
The two pallets may be exchanged by command.
[[sec:path-control-mode]](((Path Control Mode)))
=== Path Control Mode
The machining center may be put into any one of three path control
modes: (1) exact stop mode, (2) exact path mode, or (3) continuous mode
with optional tolerance. In exact stop mode, the machine stops briefly
at the end of each programmed move. In exact path mode, the machine
follows the programmed path as exactly as possible, slowing or stopping
if necessary at sharp corners of the path. In continuous mode, sharp
corners of the path may be rounded slightly so that the feed rate may
be kept up (but by no more than the tolerance, if specified). See
Sections <<gcode:g61-g61.1,G61/G61.1>> and <<gcode:g64,G64>>.
== Interpreter Interaction with Switches
The Interpreter interacts with several switches. This section
describes the interactions in more detail. In no case does the
Interpreter know what the setting of any of these switches is.
=== Feed and Speed Override Switches
The Interpreter will interpret RS274/NGC commands which enable 'M48'
or disable 'M49' the feed and speed override switches. For certain
moves, such as the
traverse out of the end of a thread during a threading cycle, the
switches are disabled automatically.
LinuxCNC reacts to the speed and feed override settings when these
switches are enabled.
See the <<mcode:m48-m49,M48 M49 Override>> section for more
information.
[[sub:block-delete-switch]]
=== Block Delete Switch
If the block delete switch is on, lines of G code which start
with a slash (the block delete character) are not interpreted. If the
switch is off, such lines are interpreted. Normally the block delete
switch should be set before starting the NGC program.
[[sub:optional-program-stop]]
=== Optional Program Stop Switch
If this switch is on and an M1 code is encountered, program execution
is paused.
== Tool Table
A tool table is required to use the Interpreter. The file tells which
tools are in which tool changer slots and what the size and type of
each tool is. The name of the tool table is defined in the ini file:
----
[EMCIO]
# tool table file
TOOL_TABLE = tooltable.tbl
----
The default filename probably looks something like the above, but
you may prefer to give your machine its own tool table, using the
same name as your ini file, but with a tbl extension:
----
TOOL_TABLE = acme_300.tbl
----
or
----
TOOL_TABLE = EMC-AXIS-SIM.tbl
----
For more information on the specifics of the tool table format,
see the <<sec:tool-table,Tool Table Format>> Section.
== Parameters
In the RS274/NGC language view, a machining center maintains an array
of numerical parameters defined by a system definition
(RS274NGC_MAX_PARAMETERS). Many of them have specific uses especially
in defining coordinate systems. The number of numerical parameters can
increase as development adds support for new parameters. The parameter
array persists over time, even if the machining center is powered down.
LinuxCNC uses a parameter file to ensure persistence and gives the
Interpreter the responsibility for maintaining the file. The
Interpreter reads the file when it starts up, and writes the file when
it exits.
All parameters are available for use in G code programs.
The format of a parameter file is shown in the following table.
The file consists of any number of
header lines, followed by one blank line, followed by any number of
lines of data. The Interpreter skips over the header lines. It is
important that there be exactly one blank line (with no spaces or tabs,
even) before the data. The header line shown in the following table
describes the data columns, so it is
suggested (but not required) that that line always be included in the
header.
The Interpreter reads only the first two columns of the table. The
third column, 'Comment', is not read by the Interpreter.
Each line of the file contains the index number of a parameter in the
first column and the value to which that parameter should be set in the
second column. The value is represented as a double-precision floating
point number inside the Interpreter, but a decimal point is not
required in the file. All of the parameters shown in the following table
are required parameters and must be
included in any parameter file, except that any parameter representing
a rotational axis value for an unused axis may be omitted. An error
will be signaled if any required parameter is missing. A parameter
file may include any other parameter, as long as its number is in the
range 1 to 5400. The parameter numbers must be arranged in ascending
order. An error will be signaled if not. Any parameter included in the
file read by the Interpreter will be included in the file it writes as
it exits. The original file is saved as a backup file when the new file
is written. Comments are not preserved when the file is written.
.Parameter File Format
[width="75%", options="header", cols="^,^,<"]
|========================================
|Parameter Number | Parameter Value | Comment
|5161 | 0.0 | G28 Home X
|5162 | 0.0 | G28 Home Y
|========================================
See the <<gcode:parameters,Parameters>> section for more information.
[[cha:o-codes]]
= O Codes
O-codes provide for flow control in NC programs. Each block has an
associated number, which is the number used after O. Care must be taken
to properly match the O-numbers. O codes use the letter 'O' not the
number zero as the first character in the number like O100 or o100.
== Numbering
Numbered O codes must have a unique number for each subroutine,
.Numbering Example
----
(the start of o100)
o100 sub
(notice that the if-endif block uses a different number)
(the start of o110)
o110 if [#2 GT 5]
(some code here)
(the end of o110)
o110 endif
(some more code here)
(the end of o100)
o100 endsub
----
[[ocode:comments]]
== Comments
(((Comments)))
Comments on the same line as the O word should not be used as the behavior can
change in the future.
The behavior is undefined if:
* The same number is used for more than one block
* Other words are used on a line with an O- word
* Comments are used on a line with an O-word
[NOTE]
Using the lower case o makes it easier to distinguish from a 0
that might have been mistyped. For example o100 is easier to
see than O100 that it is not a 0.
[[ocode:subroutines]]
== Subroutines
(((Subroutines)))
Subroutines starts at 'Onnn sub' and ends at 'Onnn endsub'. The lines between
'Onnn sub' and 'Onnn endsub' are not executed until the subroutine is called
with 'Onnn call'. Each subroutine must use a unique number.
.Subroutine Example
----
o100 sub
G53 G0 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
(the subroutine is called)
o100 call
M2
----
See <<gcode:g53,G53>> & <<gcode:g0,G0>> & <<mcode:m2-m30,M2>> sections for more
information.
.O- Return
Inside a subroutine, 'O- return' can be executed. This immediately
returns to the calling code, just as though 'O- endsub' was encountered.
.O- Return Example
----
o100 sub
(test if parameter #2 is greater than 5)
o110 if [#2 GT 5]
(return to top of subroutine if test is true)
o100 return
o110 endif
(this only gets executed if parameter #2 is not greater than 5)
(DEBUG, parameter 1 is [#1])
o100 endsub
----
See the <<gcode:binary-operators,Binary Operators>> & <<gcode:parameters,Parameters>> sections for more information.
.O- Call
'O- Call' takes up to 30 optional arguments, which are passed to the
subroutine
as '#1', '#2' , ..., #N. Parameters from #N+1 to #30 have the same
value as in the
calling context. On return from the subroutine, the values of
parameters #1 through #30 (regardless of the number of arguments) will
be restored to the values they had before the call. Parameters #1 - #30
are local to the subroutine.
Because '1 2 3' is parsed as the number 123, the parameters must be
enclosed in
square brackets. The following calls a subroutine with 3 arguments:
.O- Call Example
----
o100 sub
(test if parameter #2 is greater than 5)
o110 if [#2 GT 5]
(return to top of subroutine if test is true)
o100 return
o110 endif
(this only gets executed if parameter #2 is not greater than 5)
(DEBUG, parameter 1 is [#1])
o100 endsub
o100 call [1] [2]
----
Subroutine bodies may not be nested. They may only be called after
they are defined. They may be called from other functions, and may call
themselves recursively if it makes sense to do so. The maximum
subroutine nesting level is 10.
Subroutines do not have 'return values', but they may change the value
of parameters above #30 and those changes will be visible to the
calling code. Subroutines may also change the value of global named
parameters.
[[ocode:fanuc-style-programs]]
=== Fanuc-Style Numbered Programs ===
(((Subroutines, M98, M99)))
Numbered programs (both main and subprograms), the 'M98' call and
'M99' return M-codes, and their respective semantic differences are an
alternative to the rs274ngc subroutines described above, provided for
compatibility with Fanuc and other machine controllers.
Numbered programs are enabled by default, and may be disabled by
placing `DISABLE_FANUC_STYLE_SUB = 1` in the `[RS274NGC]` section
of the `.ini` file.
[NOTE]
Numbered main and subprogram definitions and calls differ from
traditional rs274ngc both in syntax and execution. To reduce the
possibility of confusion, the interpreter will raise an error if
definitions of one style are mixed with calls of another.
.Numbered Subprogram Simple Example
[source,{ngc}]
----
o1 (Example 1) ; Main program 1, "Example 1"
M98 P100 ; Call subprogram 100
M30 ; End main program
o100 ; Beginning of subprogram 100
G53 G0 X0 Y0 Z0 ; Rapid move to machine home
M99 ; Return from subprogram 100
----
.`o1 (Title)`
The optional main program beginning block gives the main program the
number `1`. Some controllers treat an optional following
parenthesized comment as a program title, `Example 1` in this example,
but this has no special meaning in the rs274ngc interpreter.
.`M98 P- <L\->`
Call a numbered subprogram. The block `M98 P100` is analogous to the
traditional `o100 call` syntax, but may only be used to call a
following numbered subprogram defined with `o100`...`M99`. An
optional 'L'-word specifies a loop count.
.`M30`
The main program must be terminated with `M02` or `M30` (or `M99`; see
below).
.`O-` subprogram definition start
Marks the start of a numbered subprogram definition. The block `O100`
is similar to `o100 sub`, except that it must be placed later in the
file than the `M98 P100` calling block.
.`M99` return from numbered subroutine
The block `M99` is analogous to the traditional `o100 endsub` syntax,
but may only terminate a numbered program (`o100` in this example),
and may not terminate a subroutine beginning with the `o100 sub`
syntax.
The `M98` subprogram call differs from rs274ngc `O call` in the
following ways:
* The numbered subprogram must follow the `M98` call in the program
file. The interpreter will throw an error if the subprogram precedes
the call block.
* Parameters `#1`, `#2`, ..., `#30` are global and accessible in
numbered subprograms, similar to higher-numbered parameters in
traditional style calls. Modifications to these parameters within a
subprogram are global modifications, and will be persist after
subprogram return.
* `M98` subprogram calls have no return value.
* `M98` subprogram call blocks may contain an optional L-word
specifying a loop repeat count. Without the L-word, the subprogram
will execute once only (equivalent to `M98 L1`). An `M98 L0` block
will not execute the subprogram.
In rare cases, the `M99` M-code may be used to terminate the main
program, where it indicates an 'endless program'. When the
interpreter reaches an `M99` in the main program, it will skip back to
the beginning of the file and resume execution at the first line. An
example use of an endless program is in a machine warm-up cycle; a
block delete program end `/M30` block might be used to stop the cycle
at a tidy point when the operator is ready.
.Numbered Subprogram Full Example
[source,{ngc}]
----
O1 ; Main program 1
#1 = 0
(PRINT,X MAIN BEGIN: 1=#1)
M98 P100 L5 ; Call subprogram 100
(PRINT,X MAIN END: 1=#1)
M30 ; End main program
O100 ; Subprogram 100
#1 = [#1 + 1]
M98 P200 L5 ; Call subprogram 200
(PRINT,>> O100: #1)
M99 ; Return from Subprogram 100
O200 ; Subprogram 200
#1 = [#1 + 0.01]
(PRINT,>>>> O200: #1)
M99 ; Return from Subprogram 200
----
In this example, parameter `#1` is initialized to `0`. Subprogram
`O100` is called five times in a loop. Nested within each call to
`O100`, subprogram `O200` is called five times in a loop, for 25 times
total.
Note that parameter `#1` is global. At the end of the main program,
after updates within `O100` and `O200`, its value will equal `5.25`.
[[ocode:looping]]
== Looping
(((Subroutines, Looping)))
The 'while loop' has two structures: 'while/endwhile', and 'do/while'. In
each case, the loop is exited when the 'while' condition evaluates to
false. The difference is when the test condition is done. The 'do/while'
loop runs the code in the loop then checks the test condition. The
'while/endwhile' loop does the test first.
.While Endwhile Example
----
(draw a sawtooth shape)
G0 X1 Y0 (move to start position)
#1 = 0 (assign parameter #1 the value of 0)
F25 (set a feed rate)
o101 while [#1 LT 10]
G1 X0
G1 Y[#1/10] X1
#1 = [#1+1] (increment the test counter)
o101 endwhile
M2 (end program)
----
.Do While Example
----
#1 = 0 (assign parameter #1 the value of 0)
o100 do
(debug, parameter 1 = #1)
o110 if [#1 EQ 2]
#1 = 3 (assign the value of 3 to parameter #1)
(msg, #1 has been assigned the value of 3)
o100 continue (skip to start of loop)
o110 endif
(some code here)
#1 = [#1 + 1] (increment the test counter)
o100 while [#1 LT 3]
(msg, Loop Done!)
M2
----
Inside a while loop, 'O- break' immediately exits the loop, and 'O-
continue' immediately skips to the next evaluation of the 'while'
condition. If it is still true, the loop begins again at the top. If
it is false, it exits the loop.
[[ocode:conditional]]
== Conditional
(((Subroutines, Conditional Loops)))
The 'if' conditional consists of a group of statements with the same 'o' number
that start with 'if' and end with 'endif'. Optional 'elseif' and 'else' conditions
may be between the starting 'if' and the ending 'endif'.
If the 'if' conditional evaluates to true then the group of statements
following the 'if' up to the next conditional line are executed.
If the 'if' conditional evaluates to false then the 'elseif' conditions are
evaluated in order until one evaluates to true. If the 'elseif' condition is
true then the statements following the 'elseif' up to the next conditional
line are executed. If none of the 'if' or 'elseif' conditions evaluate to true
then the statements following the 'else' are executed. When a condition is
evaluated to true no more conditions are evaluated in the group.
.If Endif Example
----
(if parameter #31 is equal to 3 set S2000)
o101 if [#31 EQ 3]
S2000
o101 endif
----
.If ElseIf Else EndIf Example
----
(if parameter #2 is greater than 5 set F100)
o102 if [#2 GT 5]
F100
o102 elseif [#2 LT 2]
(else if parameter #2 is less than 2 set F200)
F200
(else if parameter #2 is 2 through 5 set F150)
o102 else
F150
o102 endif
----
Several conditons may be tested for by 'elseif' statements until the
'else' path is finally executed if all preceding conditons are false:
.If Elseif Else Endif Example
----
(if parameter #2 is greater than 5 set F100)
O102 if [#2 GT 5]
F100
(else if parameter #2 less than 2 set F200)
O102 elseif [#2 LT 2]
F20
(parameter #2 is between 2 and 5)
O102 else
F200
O102 endif
----
[[ocode:repeat]]
== Repeat
(((Subroutines, Repeat Loop)))
The 'repeat' will execute the statements inside of the
repeat/endrepeat the specified number of times. The example shows how
you might mill a diagonal series of shapes starting at the present
position.
.Repeat Example
----
(Mill 5 diagonal shapes)
G91 (Incremental mode)
o103 repeat [5]
... (insert milling code here)
G0 X1 Y1 (diagonal move to next position)
o103 endrepeat
G90 (Absolute mode)
----
[[ocode:indirection]]
== Indirection
(((Indirection)))
The O-number may be given by a parameter and/or calculation.
.Indirection Example
----
o[#101+2] call
----
.Computing values in O-words
For more information on computing values see the following sections
* <<gcode:parameters,Parameters>>
* <<gcode:expressions,Expressions>>
* <<gcode:binary-operators,Binary Operators>>
* <<gcode:functions,Functions>>
[[ocode:calling-files]]
== Calling Files
(((Calling Files)))
To call a separate file with a subroutine name the file the same as
your call and include a sub and endsub in the file. The file must be in the
directory pointed to by 'PROGRAM_PREFIX' or 'SUBROUTINE_PATH' in the ini file.
The file name can include *lowercase* letters, numbers, dash, and underscore
only. A named subroutine file can contain only a single subroutine definition.
.Named File Example
----
o<myfile> call
----
.Numbered File Example
----
o123 call
----
In the called file you must include the oxxx sub and endsub and the
file must be a valid file.
.Called File Example
----
(filename myfile.ngc)
o<myfile> sub
(code here)
o<myfile> endsub
M2
----
[NOTE]
The file names are lowercase letters only so 'o<MyFile>' is converted to 'o<myfile>'
by the interpreter. More information about the search path and options for the
search path are in the INI Configuration Section.
== Subroutine return values(((Return Values)))
Subroutines may optionally return a value by an optional expression at
an 'endsub' or 'return' statement.
.Return value example
----
o123 return [#2 *5]
...
o123 endsub [3 * 4]
----
A subroutine return value is stored in the '#<_value>'
<<gcode:predefined-named-parameters, predefined named parameter>> , and
the '#<_value_returned>' predefined parameter is set to 1, to indicate
a value was returned. Both parameters are global, and are cleared just
before the next subroutine call.
[[ocode:errors]]
== Errors
(((O-Code Errors)))
The following statements cause an error message and abort the
interpreter:
- a `return` or `endsub` not within a sub defintion
- a label on `repeat` which is defined elsewhere
- a label on `while` which is defińed elsewhere and not referring to a `do`
- a label on `if` defined elsewhere
- a undefined label on `else` or `elseif`
- a label on `else`, `elseif` or `endif` not pointing to a matching `if`
- a label on `break` or `continue` which does not point to a matching `while` or `do`
- a label on `endrepeat` or `endwhile` no referring to a corresponding `while` or `repeat`
To make these errors non-fatal warnings on stderr, set bit 0x20 in
the `[RS274NGC]FEATURE=` mask ini option.
// vim: set syntax=asciidoc:
[[cha:other-codes]]
= Other Codes
[[sec:set-feed-rate]]
== F: Set Feed Rate
(((F: Set Feed Rate)))
'Fx' - set the feed rate to 'x'. 'x' is usually in machine units
(inches or millimeters) per minute.
The application of the feed rate is as described in the
<<sub:feed-rate,Feed Rate>> Section, unless 'inverse time feed rate mode'
or 'feed per revolution mode' are in effect, in which case the feed rate
is as described in the <<gcode:g93-g94-g95,G93 G94 G95>> Section.
[[sec:set-spindle-speed]]
== S: Set Spindle Speed
(((S: Set Spindle Speed)))
'Sx' - set the speed of the spindle to 'x' revolutions per minute (RPM).
The spindle will turn at that speed when a 'M3' or 'M4' is in effect.
It is OK to program an S word whether the spindle is turning or not.
If the speed override switch is enabled and not set at 100%,
the speed will be different from what is programmed.
It is OK to program S0, the spindle will not turn if that is done.
It is an error if:
* the S number is negative.
[[sec:select-tool]]
== T: Select Tool
(((T: Select Tool)))
'Tx' - prepare to change to tool 'x'.
The tool is not changed until an 'M6' is programmed (see Section
<<mcode:m6,M6>>). The T word may appear on the same line as the
'M6' or on a previous line. It is OK if T words appear on two or more
lines with no tool change. Only the the most recent T word will take
effect at the next tool change.
NOTE: When LinuxCNC is configured for a nonrandom toolchanger (see
the entry for RANDOM_TOOLCHANGER in the <<sec:emcio-section,EMCIO
Section>>), 'T0' gets special handling: no tool will be selected. This
is useful if you want the spindle to be empty after a tool change.
NOTE: When LinuxCNC is configured for a random toolchanger (see
the entry for RANDOM_TOOLCHANGER in the <<sec:emcio-section,EMCIO
Section>>), 'T0' does not get any special treatment: T0 is a valid
tool like any other. It is customary to use T0 on a random toolchanger
machine to track an empty pocket, so that it behaves like a nonrandom
toolchanger machine and unloads the spindle.
It is an error if:
* a negative T number is used,
* T number is used that does not appear in the tool table file (with
the exception that T0 on nonrandom toolchangers *is* accepted,
as noted above).
On some machines, the carousel will move when a T word is programmed,
at the same time machining is occurring. On such machines, programming
the T word several lines before a tool change will save time. A common
programming practice for such machines is to put the T word for the
next tool to be used on the line after a tool change. This maximizes
the time available for the carousel to move.
Rapid moves after a 'T<n>' will not show on the AXIS preview until after
a feed move. This is for machines that travel long distances to change
the tool like a lathe. This can be very confusing at first. To turn
this feature off for the current tool program a G1 without any
move after the 'T<n>'.
// vim: set syntax=asciidoc:
[[cha:g-code-overview]]
= G Code Overview
:ini: {basebackend@docbook:'':ini}
:hal: {basebackend@docbook:'':hal}
:ngc: {basebackend@docbook:'':ngc}
// begin a listing of ini/hal/ngc files like so:
//[source,{ini}]
//[source,{hal}]
//[source,{ngc}]
== Overview
The LinuxCNC G Code language is based on the RS274/NGC language. The G
Code language is based on lines of code. Each line (also called a
'block') may include commands to do several different things. Lines of
code may be collected in a file to make a program.
A typical line of code consists of an optional line number at the
beginning followed by one or more 'words'. A word consists of a letter
followed by a number (or something that evaluates to a number). A word
may either give a command or provide an argument to a command. For
example, 'G1 X3' is a valid line of code with two words. 'G1' is a
command meaning 'move in a straight line at the programmed feed
rate to the programmed end point', and 'X3' provides an argument
value (the value of X should be 3 at the end of the move).
Most LinuxCNC G Code commands start with either G or M (for
General and Miscellaneous). The words for these commands are called 'G
codes' and 'M codes.'
The LinuxCNC language has no indicator for the start of a program. The
Interpreter, however, deals with files. A single program may be in a
single file, or a program may be spread across several files. A file
may demarcated with percents in the following way. The first non-blank
line of a file may contain nothing but a percent sign, '%', possibly
surrounded by white space, and later in the file (normally at the end
of the file) there may be a similar line. Demarcating a file with
percents is optional if the file has an 'M2' or 'M30' in it, but is
required if not. An error will be signaled if a file
has a percent line at the beginning but not at the end. The useful
contents of a file demarcated by percents stop after the second percent
line. Anything after that is ignored.
The LinuxCNC G Code language has two commands ('M2' or 'M30'), either of
which ends a program. A program may end before the end of
a file. Lines of a file that occur after the end of a program are not
to be executed. The interpreter does not even read them.
== Format of a line
A permissible line of input code consists of the following, in order,
with the restriction that there is a maximum (currently 256) to the
number of characters allowed on a line.
. an optional block delete character, which is a slash '/'.
. an optional line number.
. any number of words, parameter settings, and comments.
. an end of line marker (carriage return or line feed or both).
Any input not explicitly allowed is illegal and will cause the
Interpreter to signal an error.
Spaces and tabs are allowed anywhere on a line of code and do not
change the meaning of the line, except inside comments. This makes some
strange-looking input legal. The line 'G0X +0. 12 34Y 7' is
equivalent to 'G0 x+0.1234 Y7', for example.
Blank lines are allowed in the input. They are to be ignored.
Input is case insensitive, except in comments, i.e., any letter
outside a comment may be in upper or lower case without changing the
meaning of a line.
[[sub:block-delete]](((Block Delete)))
=== Block Delete
The optional block delete character the slash '/' when placed first on a line
can be used by some user interfaces to skip lines of code when needed. In Axis
the key combination Alt-m-/ toggles block delete on and off. When block delete
is on any lines starting with the slash '/' are skipped.
=== Line Number
(((Line Number)))
A line number is the letter N followed by an unsigned integer,
optionally followed by a period and another unsigned integer. For
example, 'N1234' and 'N56.78' are valid line numbers. They may be
repeated or used out of order, although normal practice is to avoid
such usage. Line numbers may also be skipped, and that is normal
practice. A line number is not required to be used, but must be in the
proper place if used.
=== Word
A word is a letter other than N followed by a real value.
Words may begin with any of the letters shown in the following Table.
The table includes N for completeness, even
though, as defined above, line numbers are not words. Several letters
(I, J, K, L, P, R) may have different meanings in different contexts.
Letters which refer to axis names are not valid on a machine which does
not have the corresponding axis.
.Words and their meanings
[width="75%", options="header", cols="^1,<5"]
|====
|Letter | Meaning
|A | A axis of machine
|B | B axis of machine
|C | C axis of machine
|D | Tool radius compensation number
|F | Feed rate
|G | General function (See table <<cap:modal-groups,Modal Groups>>)
|H | Tool length offset index
|I | X offset for arcs and G87 canned cycles
|J | Y offset for arcs and G87 canned cycles
.2+|K | Z offset for arcs and G87 canned cycles.
<| Spindle-Motion Ratio for G33 synchronized movements.
|L | generic parameter word for G10, M66 and others
|M | Miscellaneous function (See table <<cap:modal-groups,Modal Groups>>)
|N | Line number
.2+|P | Dwell time in canned cycles and with G4.
<| Key used with G10.
|Q | Feed increment in G73, G83 canned cycles
|R | Arc radius or canned cycle plane
|S | Spindle speed
|T | Tool selection
|U | U axis of machine
|V | V axis of machine
|W | W axis of machine
|X | X axis of machine
|Y | Y axis of machine
|Z | Z axis of machine
|====
=== Number
The following rules are used for (explicit) numbers. In these rules a
digit is a single character between 0 and 9.
* A number consists of (1) an optional plus or minus sign, followed by
(2) zero to many digits, followed, possibly, by (3) one decimal point,
followed by (4) zero to many digits - provided that there is at least
one digit somewhere in the number.
* There are two kinds of numbers: integers and decimals. An integer does
not have a decimal point in it; a decimal does.
* Numbers may have any number of digits, subject to the limitation on
line length. Only about seventeen significant figures will be retained,
however (enough for all known applications).
* A non-zero number with no sign as the first character is assumed to be
positive.
Notice that initial (before the decimal point and the first non-zero
digit) and trailing (after the decimal point and the last non-zero
digit) zeros are allowed but not required. A number written with
initial or trailing zeros will have the same value when it is read as
if the extra zeros were not there.
Numbers used for specific purposes in RS274/NGC are often restricted
to some finite set of values or some to some range of values. In many
uses, decimal numbers must be close to integers; this includes the
values of indices (for parameters and carousel slot numbers, for
example), M codes, and G codes multiplied by ten. A decimal number
which is intended to represent an integer is considered close enough if
it is within 0.0001 of an integer value.
[[gcode:parameters]](((Parameters)))
== Parameters
The RS274/NGC language supports 'parameters' - what in other
programming languages would be called 'variables'. There are several
types of parameter of different purpose and appearance, each described
in the following sections. The only value type supported by parameters
is floating-point; there are no string, boolean or integer types in
G-code like in other programming languages. However, logic expressions
can be formulated with <<gcode:binary-operators,boolean operators>>
( 'AND', 'OR', 'XOR', and the comparison operators
'EQ','NE','GT','GE','LT','LE'), and the 'MOD', 'ROUND', 'FUP' and
'FIX' <<gcode:functions,operators>> support integer arithmetic.
Parameters differ in syntax, scope, behavior when not yet
initialized, mode, persistence and intended use.
Syntax:: There are three kinds of syntactic appearance:
* 'numbered' - #4711
* 'named local' - #<localvalue>
* 'named global' - #<_globalvalue>
Scope:: The scope of a parameter is either global, or local within a
subroutine. Subroutine parameters and local named variables have local
scope. Global named parameters and numbered parameters starting from
number 31 are global in scope. RS274/NGC uses 'lexical scoping' -
in a subroutine only the local variables defined therein, and any
global variables are visible. The local variables of a
calling procedure are not visible in a called procedure.
Behavior of uninitialized parameters::
* Uninitialized global parameters, and unused subroutine parameters
return the value zero when used in an expression.
* Uninitialized named parameters signal an error when used in an expression.
Mode:: Most parameters are read/write and may be assigned to
within an assignment statement. However, for many predefined
parameters this does not make sense, so they are are read-only - they
may appear in expressions, but not on the left-hand side of an
assignment statement.
Persistence:: When LinuxCNC is shut down, volatile parameters lose their
values. All parameters except numbered parameters in the current
persistent range footnoteref:[persistent_range,The range of persistent
parameters may change as development progresses. This range is
currently 5161- 5390. It is defined in the '_required_parameters array'
in file the src/emc/rs274ngc/interp_array.cc .] are volatile.
Persistent parameters are saved in the .var file and
restored to their previous values when LinuxCNC is started again. Volatile
numbered parameters are reset to zero.
Intended Use::
* user parameters:: numbered parameters in the range 31..5000, and named
global and local parameters except predefined parameters. These are
available for general-purpose storage of floating-point values, like
intermediate results, flags etc, throughout program execution. They
are read/write (can be assigned a value).
* <<sub:subroutine-parameters,subroutine parameters>> - these are used to
hold the actual parameters passed to a subroutine.
* <<sub:numbered-parameters,numbered parameters>> - most of these are used
to access offsets of coordinate systems.
* <<sub:system-parameters,system parameters>> - used to determine the current
running version. They are read-only.
[[sub:numbered-parameters]]
=== Numbered Parameters
A numbered parameter is the pound character '#' followed by an
integer between 1 and (currently) 5602 footnote:[The RS274/NGC interpreter
maintains an array of numbered parameters. Its size is defined by the
symbol 'RS274NGC_MAX_PARAMETERS' in the file
src/emc/rs274ngc/interp_internal.hh). This number of numerical
parameters may also increase as development adds support for new
parameters. ]. The parameter is referred
to by this integer, and its value is whatever number is stored in the
parameter.
A value is stored in a parameter with the = operator; for example:
----
#3 = 15 (set parameter 3 to 15)
----
A parameter setting does not take
effect until after all parameter values on the same line have been
found. For example, if parameter 3 has been previously set to 15 and
the line '#3=6 G1 X#3' is interpreted, a straight move to a point
where X equals 15 will
occur and the value of parameter 3 will be 6.
The '\#' character takes precedence over other operations, so that, for
example, '\#1+2' means the number found by adding 2 to the value of
parameter 1, not
the value found in parameter 3. Of course, '\#[1+2]' does mean the
value found in parameter 3. The '\#' character may be repeated; for
example '##2' means the value of the parameter whose index is the
(integer) value of parameter 2.
* '31-5000' - G code user parameters. These parameters are global in the G
code file, and available for general use. Volatile.
* '5061-5069' - Coordinates of a <<gcode:g38,G38>> probe result (X, Y,
Z, A, B, C, U, V & W). Coordinates are in the coordinate system in
which the G38 took place. Volatile.
* '5070' - <<gcode:g38,G38>> probe result: 1 if success, 0 if probe
failed to close. Used with G38.3 and G38.5. Volatile.
* '5161-5169' - "G28" Home for X, Y, Z, A, B, C, U, V & W. Persistent.
* '5181-5189' - "G30" Home for X, Y, Z, A, B, C, U, V & W. Persistent.
* '5210' - 1 if "G52" or "G92" offset is currently applied, 0
otherwise. Volatile by default; persistent if
'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
'.ini' file.
* '5211-5219' - Shared "G52" and "G92" offset for X, Y, Z, A, B, C, U,
V & W. Volatile by default; persistent if
'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
'.ini' file.
* '5220' - Coordinate System number 1 - 9 for G54 - G59.3. Persistent.
* '5221-5230' - Coordinate System 1, G54 for X, Y, Z, A, B, C, U, V, W & R.
R denotes the XY rotation angle around the Z axis. Persistent.
* '5241-5250' - Coordinate System 2, G55 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5261-5270' - Coordinate System 3, G56 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5281-5290' - Coordinate System 4, G57 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5301-5310' - Coordinate System 5, G58 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5321-5330' - Coordinate System 6, G59 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5341-5350' - Coordinate System 7, G59.1 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5361-5370' - Coordinate System 8, G59.2 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5381-5390' - Coordinate System 9, G59.3 for X, Y, Z, A, B, C, U, V, W & R.
Persistent.
* '5399' - Result of M66 - Check or wait for input. Volatile.
* '5400' - Tool Number. Volatile.
* '5401-5409' - Tool Offsets for X, Y, Z, A, B, C, U, V & W. Volatile.
* '5410' - Tool Diameter. Volatile.
* '5411' - Tool Front Angle. Volatile.
* '5412' - Tool Back Angle. Volatile.
* '5413' - Tool Orientation. Volatile.
* '5420-5428' - Current relative position in the active coordinate system
including all offsets and in the current program units for
X, Y, Z, A, B, C, U, V & W, volatile.
* '5599' - Flag for controlling the output of (DEBUG,) statements.
1=output, 0=no output; default=1. Volatile.
* '5600' - Toolchanger fault indicator. Used with the iocontrol-v2 component.
1: toolchanger faulted, 0: normal. Volatile.
* '5601' - Toolchanger fault code. Used with the iocontrol-v2 component.
Reflects the value of the 'toolchanger-reason' HAL pin if a fault occurred.
Volatile.
.Numbered Parameters Persistence
The values of parameters in the persistent range are retained over
time, even if the machining center is powered down. LinuxCNC uses a
parameter file to ensure persistence. It is managed by the
Interpreter. The Interpreter reads the file when it starts up, and
writes the file when it exits.
The format of a parameter file is shown in Table
<<gcode:format-parameter-file,Parameter File Format>>.
The Interpreter expects the file to have two columns. It skips any
lines which do not contain exactly two numeric values. The first
column is expected to contain an integer value (the parameter's
number). The second column contains a floating point number (this
parameter's last value). The value is represented as a
double-precision floating point number inside the Interpreter, but a
decimal point is not required in the file.
Parameters in the user-defined range (31-5000) may be added to this
file. Such parameters will be read by the Interpreter and written to
the file as it exits.
Missing Parameters in the persistent range will be initialized to zero
and written with their current values on the next save operation.
The parameter numbers must be arranged in ascending order. An
'Parameter file out of order' error will be signaled if they are not in
ascending order.
The original file is saved as a backup file when the new file
is written.
[[gcode:format-parameter-file]]
.Parameter File Format
[width="90%", options="header"]
|====
|Parameter Number | Parameter Value
|5161 | 0.0
|5162 | 0.0
|====
[[sub:subroutine-parameters]]
=== Subroutine Parameters
* '1-30' Subroutine local parameters of call arguments. These parameters are
local to the subroutine. Volatile. See also the chapter on
<<cha:o-codes,O-Codes>>.
=== Named Parameters
Named parameters work like numbered parameters but are easier to read.
All parameter names are converted to lower case and have spaces and
tabs removed, so '#<param>' and '#<P a R am >' refer to the same
parameter. Named parameters must be enclosed with '< >' marks.
'#<named parameter>' is a local named parameter. By default, a
named parameter is local to the scope in which it is assigned. You can't
access a local parameter outside of its subroutine. This means that two
subroutines can use the same parameter names without fear of one subroutine
overwriting the values in another.
'#<_global named parameter>' is a global named parameter. They
are accessible from within called subroutines and may set values within
subroutines that are accessible to the caller. As far as scope is concerned,
they act just like regular numeric parameters. They are not stored in files.
Examples:
.Declaration of named global variable
----
#<_endmill_dia> = 0.049
----
.Reference to previously declared global variable
----
#<_endmill_rad> = [#<_endmill_dia>/2.0]
----
.Mixed literal and named parameters
----
o100 call [0.0] [0.0] [#<_inside_cutout>-#<_endmill_dia>] [#<_Zcut>] [#<_feedrate>]
----
Named parameters spring into existence when they are assigned a value
for the first time. Local named parameters vanish when their scope is
left: when a subroutine returns, all its local parameters are deleted
and cannot be referred to anymore.
It is an error to use a non-existent named parameter within an
expression, or at the right-hand side of an assignment. Printing the
value of a non-existent named parameter with a DEBUG statement - like
'(DEBUG, #<no_such_parameter>)' will display the string '######'.
Global parameters, as well as local parameters assigned to at the
global level, retain their value once assigned even when the program
ends, and have these values when the program is run again.
The <<gcode:functions,'EXISTS' function>> tests whether a given named parameter exists.
[[gcode:predefined-named-parameters]]
=== Predefined Named Parameters
The following global read only named parameters are available to
access internal state of the interpreter and machine state. They can
be used in arbitrary expressions, for instance to control flow of the
program with if-then-else statements. Note that new
<<remap:adding-predefined-named-parameters,predefined named parameters>>
can be added easily without changes to the source code.
* '#<_vmajor>' - Major package version. If current version was 2.5.2 would return 2.5.
* '#<_vminor>' - Minor package version. If current version was 2.6.2 it would return 0.2.
* '#<_line>' - Sequence number. If running a G-Code file, this returns the current line number.
* '#<_motion_mode>' - Return the interpreter's current motion mode:
[width="20%",options="header"]
|====
|Motion mode | return value
|G1| 10
|G2| 20
|G3| 30
|G33| 330
|G38.2| 382
|G38.3| 383
|G38.4| 384
|G38.5| 385
|G5.2| 52
|G73| 730
|G76| 760
|G80| 800
|G81| 810
|G82| 820
|G83| 830
|G84| 840
|G85| 850
|G86| 860
|G87| 870
|G88| 880
|G89| 890
|====
* '#<_plane>' -
returns the value designating the current plane:
[width="20%",options="header"]
|====
|Plane | return value
|G17| 170
|G18| 180
|G19| 190
|G17.1| 171
|G18.1| 181
|G19.1| 191
|====
* '#<_ccomp>' -
Status of cutter compensation. Return values:
[width="20%",options="header"]
|====
|Mode | return value
|G40 | 400
|G41 | 410
|G41.1| 411
|G41 | 410
|G42 | 420
|G42.1 | 421
|====
* '#<_metric>' -
Return 1 if G21 is on, else 0.
* '#<_imperial>' -
Return 1 if G20 is on, else 0.
* '#<_absolute>' -
Return 1 if G90 is on, else 0.
* '#<_incremental>' -
Return 1 if G91 is on, else 0.
* '#<_inverse_time>' -
Return 1 if inverse feed mode (G93) is on, else 0.
* '#<_units_per_minute>' -
Return 1 if Units/minute feed mode (G94) is on, else 0.
* '#<_units_per_rev>' -
Return 1 if Units/revolution mode (G95) is on, else 0.
* '#<_coord_system>' -
Return a float of the current coordinate system name(G54..G59.3).
For example if your in G55 coordinate system the return value is
550.000000 and if your in G59.1 the return value is 591.000000.
[width="20%",options="header"]
|====
|Mode | return value
|G54| 554
|G55| 550
|G56| 560
|G57| 570
|G58| 580
|G59| 590
|G59.1|591
|G59.2|592
|G59.3|593
|====
* '#<_tool_offset>' -
Return 1 if tool offset (G43) is on, else 0.
* '#<_retract_r_plane>' -
Return 1 if G98 is set, else 0.
* '#<_retract_old_z>' -
Return 1 if G99 is on, else 0.
[[sub:system-parameters]]
=== System Parameters
* '#<_spindle_rpm_mode>' -
Return 1 if spindle rpm mode (G97) is on, else 0.
* '#<_spindle_css_mode>' -
Return 1 if constant surface speed mode (G96) is on, else 0.
* '#<_ijk_absolute_mode>' -
Return 1 if Absolute Arc distance mode (G90.1) is on, else 0.
* '#<_lathe_diameter_mode>' -
Return 1 if this is a lathe configuration and diameter (G7) mode is on, else 0.
* '#<_lathe_radius_mode>' -
Return 1 if this is a lathe configuration and radius (G8) mode is on, else 0.
* '#<_spindle_on>' -
Return 1 if spindle currently running (M3 or M4) else 0.
* '#<_spindle_cw>' -
Return 1 if spindle direction is clockwise (M3) else 0.
* '#<_mist>' -
Return 1 if mist (M7) is on.
* '#<_flood>' -
Return 1 if flood (M8) is on.
* '#<_speed_override>' -
Return 1 if feed override (M48 or M50 P1) is on, else 0.
* '#<_feed_override>' -
Return 1 if feed override (M48 or M51 P1) is on, else 0.
* '#<_adaptive_feed>' -
Return 1 if adaptive feed (M52 or M52 P1) is on, else 0.
* '#<_feed_hold>' -
Return 1 if feed hold switch is enabled (M53 P1), else 0.
* '#<_feed>' -
Return the current value of F, not the actual feed rate.
* '#<_rpm>' -
Return the current value of S, not the actual spindle speed.
* '#<_x>' -
Return current relative X coordinate including all offsets. Same as #5420.
* '#<_y>' -
Return current relative Y coordinate including all offsets. Same as #5421.
* '#<_z>' -
Return current relative Z coordinate including all offsets. Same as #5422.
* '#<_a>' -
Return current relative A coordinate including all offsets. Same as #5423.
* '#<_b>' -
Return current relative B coordinate including all offsets. Same as #5424.
* '#<_c>' -
Return current relative C coordinate including all offsets. Same as #5425.
* '#<_u>' -
Return current relative U coordinate including all offsets. Same as #5426.
* '#<_v>' -
Return current relative V coordinate including all offsets. Same as #5427.
* '#<_w>' -
Return current relative W coordinate including all offsets. Same as #5428.
* '#<_current_tool>' -
Return number of the current tool in spindle. Same as #5400.
* '#<_current_pocket>' -
Return pocket number of the current tool.
* '#<_selected_tool>' -
Return number of the selected tool post a T code. Default -1.
* '#<_selected_pocket>' -
Return number of the selected pocket post a T code. Default -1
(no pocket selected).
* '#<_value>' -
Return value from the last O-word 'return' or 'endsub'. Default
value 0 if no expression after 'return' or 'endsub'. Initialized
to 0 on program start.
* '#<_value_returned>' -
1.0 if the last O-word 'return' or 'endsub' returned a value, 0
otherwise. Cleared by the next O-word call.
* '#<_task>' -
1.0 if the executing interpreter instance is part of milltask, 0.0
otherwise. Sometimes it is necessary to treat this case specially
to retain proper preview, for instance when testing the success of
a probe (G38.n) by inspecting #5070, which will always fail in the
preview interpreter (e.g. Axis).
* '#<_call_level>' -
current nesting level of O-word procedures. For debugging.
* '#<_remap_level>' -
current level of the remap stack. Each remap in a block adds one
to the remap level. For debugging.
[NOTE]
Additional system parameters can be enabled by using 'FEATURES' in the
[RS274NGC] section of the ini file. More information
<<remap:ini-features, here>>.
[[gcode:expressions]]
== Expressions
An expression is a set of characters starting with a left bracket '['
and ending with a balancing right bracket ']' . In between the brackets
are numbers, parameter values, mathematical
operations, and other expressions. An expression is evaluated to
produce a number. The expressions on a line are evaluated when the line
is read, before anything on the line is executed. An example of an
expression is '[1 + acos[0] - [#3 ** [4.0/2]]]'.
[[gcode:binary-operators]]
== Binary Operators
Binary operators only appear inside expressions. There are four basic
mathematical operations: addition ('+'), subtraction ('-'),
multiplication ('\*'), and division ('/'). There are three logical
operations: non-exclusive or ('OR'), exclusive or ('XOR'), and logical
and ('AND'). The eighth operation is the modulus operation ('MOD'). The
ninth operation is the 'power' operation ('**') of raising the number
on the left of the operation to the power on
the right. The relational operators are equality ('EQ'), inequality
('NE'), strictly greater than ('GT'), greater than or equal to ('GE'),
strictly less than ('LT'), and less than or equal to ('LE').
The binary operations are divided into several groups according to their
precedence. If operations in different precedence groups are strung together
(for example in the expression '[2.0 / 3 * 1.5 - 5.5 / 11.0]'), operations
in a higher group are to be performed before operations
in a lower group. If an expression contains more than one operation
from the same group (such as the first '/' and '*' in the example),
the operation on the left is performed first. Thus,
the example is equivalent to: '[ [ [2.0 / 3] * 1.5] - [5.5 / 11.0] ]' ,
which is equivalent to to '[1.0 - 0.5]' , which is '0.5'.
The logical operations and modulus are to be performed on any real
numbers, not just on integers. The number zero is equivalent to logical
false, and any non-zero number is equivalent to logical true.
.Operator Precedence
[width="60%", options="header", cols="2*^"]
|====
|Operators | Precedence
|** | 'highest'
|* / MOD |
|+ - |
|EQ NE GT GE LT LE |
|AND OR XOR | 'lowest'
|====
== Equality and floating-point values
The RS274/NGC language only supports floating-point values of finite
precision. Therefore, testing for equality or inequality of two
floating-point values is inherently problematic. The interpreter
solves this problem by considering values equal if their absolute
difference is less than 0.0001 (this value is defined as
'TOLERANCE_EQUAL' in src/emc/rs274ngc/interp_internal.hh).
[[gcode:functions]]
== Functions
The available functions are shown in following table. Arguments to unary
operations which take angle measures ('COS', 'SIN', and 'TAN' ) are in
degrees. Values returned by unary operations which return angle measures
('ACOS', 'ASIN', and 'ATAN') are also in degrees.
.Functions
[width="75%", options="header", cols="^,<"]
|====
|Function Name | Function result
|ATAN[arg]/[arg] | Four quadrant inverse tangent
|ABS[arg] | Absolute value
|ACOS[arg] | Inverse cosine
|ASIN[arg] | Inverse sine
|COS[arg] | Cosine
|EXP[arg] | e raised to the given power
|FIX[arg] | Round down to integer
|FUP[arg] | Round up to integer
|ROUND[arg] | Round to nearest integer
|LN[arg] | Base-e logarithm
|SIN[arg] | Sine
|SQRT[arg] | Square Root
|TAN[arg] | Tangent
|EXISTS[arg] | Check named Parameter
|====
The 'FIX' function rounds towards the left (less positive or more negative)
on a number line, so that 'FIX[2.8] =2' and 'FIX[-2.8] = -3'.
The 'FUP' operation rounds towards the right (more positive or less
negative) on a number line; 'FUP[2.8] = 3' and 'FUP[-2.8] = -2'.
The 'EXISTS' function checks for the existence of a single named parameter.
It takes only one named parameter and returns 1 if it exists and 0 if it does
not exist. It is an error if you use a numbered parameter or an expression.
Here is an example for the usage of the EXISTS function:
----
o<test> sub
o10 if [EXISTS[#<_global>]]
(debug, _global exists and has the value #<_global>)
o10 else
(debug, _global does not exist)
o10 endif
o<test> endsub
o<test> call
#<_global> = 4711
o<test> call
m2
----
== Repeated Items
A line may have any number of G words, but two G words from the same
modal group may not appear on the
same line See the <<gcode:modal-groups,Modal Groups>> Section for more information.
A line may have zero to four M words. Two M words from the same modal
group may not appear on the same line.
For all other legal letters, a line may have only one word beginning
with that letter.
If a parameter setting of the same parameter is repeated on a line,
'#3=15 #3=6', for example, only the last setting will take effect.
It is silly,
but not illegal, to set the same parameter twice on the same line.
If more than one comment appears on a line, only the last one will be
used; each of the other comments will be read and its format will be
checked, but it will be ignored thereafter. It is expected that putting
more than one comment on a line will be very rare.
== Item order
The three types of item whose order may vary on a line (as given at
the beginning of this section) are word, parameter setting, and
comment. Imagine that these three types of item are divided into three
groups by type.
The first group (the words) may be reordered in any way without
changing the meaning of the line.
If the second group (the parameter settings) is reordered, there will
be no change in the meaning of the line unless the same parameter is
set more than once. In this case, only the last setting of the
parameter will take effect. For example, after the line '#3=15 #3=6'
has been interpreted, the value of parameter 3 will be 6. If the
order is reversed to '#3=6 #3=15' and the line is interpreted, the
value of parameter 3 will be 15.
If the third group (the comments) contains more than one comment and
is reordered, only the last comment will be used.
If each group is kept in order or reordered without changing the
meaning of the line, then the three groups may be interleaved in any
way without changing the meaning of the line. For example, the line
'g40 g1 #3=15 (foo) #4=-7.0' has five items and means exactly the
same thing in any of the 120
possible orders (such as '#4=-7.0 g1 #3=15 g40 (foo)') for the five
items.
== Commands and Machine Modes
Many commands cause the controller to change from one mode to another,
and the mode stays active until some other command changes it
implicitly or explicitly. Such commands are called 'modal'. For
example, if coolant is turned on, it stays on until it is explicitly
turned off. The G codes for motion are also modal. If a G1 (straight
move) command is given on one line, for example, it will be executed
again on the next line if one or more axis words is available on the
line, unless an explicit command is given on that next line using the
axis words or canceling motion.
'Non-modal' codes have effect only on the lines on which they occur.
For example, G4 (dwell) is non-modal.
(((Polar Coordinates)))
== Polar Coordinates
Polar Coordinates can be used to specify the XY coordinate of a move.
The @n is the distance and ^n is the angle. The advantage of this is
for things like bolt hole circles which can be done very simply by
moving to a point in the center of the circle, setting the offset and
then moving out to the first hole then run the drill cycle.
Polar Coordinates always are from the current XY zero position.
To shift the Polar Coordinates from machine zero use an offset
or select a coordinate system.
In Absolute Mode the distance and angle is from the XY zero position
and the angle starts with 0 on the X Positive axis and increases in a CCW
direction about the Z axis. The code G1 @1^90 is the same as G1 Y1.
In Relative Mode the distance and angle is also from the XY zero
position but it is cumulative.
This can be confusing at first how this works in incremental mode.
For example if you have the following program you might expect it to
be a square pattern.
----
F100 G1 @.5 ^90
G91 @.5 ^90
@.5 ^90
@.5 ^90
@.5 ^90
G90 G0 X0 Y0 M2
----
You can see from the following figure that the output is not what you
might expect. Because we added 0.5 to the distance each time the
distance from the XY zero position increased with each line.
.Polar Spiral
image::images/polar01.png[align="center", alt="Polar Spiral"]
The following code will produce our square pattern.
----
F100 G1 @.5 ^90
G91 ^90
^90
^90
^90
G90 G0 X0 Y0 M2
----
As you can see by only adding to the angle by 90 degrees each time the
end point distance is the same for each line.
.Polar Square
image::images/polar02.png[align="center", alt="Polar Square"]
It is an error if:
* An incremental move is started at the origin
* A mix of Polar and and X or Y words are used
[[gcode:modal-groups]](((Modal Groups)))
== Modal Groups
Modal commands are arranged in sets called 'modal groups', and only
one member of a modal group may be in force at any given time. In
general, a modal group contains commands for which it is logically
impossible for two members to be in effect at the same time - like
measure in inches vs. measure in millimeters. A machining center may be
in many modes at the same time, with one mode from each modal group
being in effect. The modal groups are shown in the following Table.
.G-Code Modal Groups[[cap:modal-groups]]
[width="80%", cols="4,6", options="header"]
|====
|Modal Group Meaning | Member Words
|Non-modal codes (Group 0) | G4, G10 G28, G30, G52, G53, G92, G92.1, G92.2, G92.3,
.2+|Motion (Group 1) | G0, G1, G2, G3, G33, G38.n, G73, G76, G80, G81
| G82, G83, G84, G85, G86, G87, G88, G89
|Plane selection (Group 2) | G17, G18, G19, G17.1, G18.1, G19.1
|Distance Mode (Group 3) | G90, G91
|Arc IJK Distance Mode (Group 4) | G90.1, G91.1
|Feed Rate Mode (Group 5) | G93, G94, G95
|Units (Group 6) | G20, G21
|Cutter Diameter Compensation (Group 7)| G40, G41, G42, G41.1, G42.1
|Tool Length Offset (Group 8) | G43, G43.1, G49
|Canned Cycles Return Mode (Group 10) | G98, G99
|Coordinate System (Group 12) | G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3
|Control Mode (Group 13) | G61, G61.1, G64
|Spindle Speed Mode (Group 14) | G96, G97
|Lathe Diameter Mode (Group 15) | G7, G8
|====
.M-Code Modal Groups
[width="80%", cols="4,6", options="header"]
|====
|Modal Group Meaning |Member Words
|Stopping (Group 4) |M0, M1, M2, M30, M60
|Spindle (Group 7) |M3, M4, M5
|Coolant (Group 8) |(M7 M8 can both be on), M9
|Override Switches (Group 9) |M48, M49
|User Defined (Group 10) |M100-M199
|====
For several modal groups, when a machining center is ready to accept
commands, one member of the group must be in effect. There are default
settings for these modal groups. When the machining center is turned on
or otherwise re-initialized, the default values are automatically in
effect.
Group 1, the first group on the table, is a group of G codes for
motion. One of these is always in effect. That one is called the
current motion mode.
It is an error to put a G-code from group 1 and a G-code from group 0
on the same line if both of them use axis words. If an axis word-using
G-code from group 1 is implicitly in effect on a line (by having been
activated on an earlier line), and a group 0 G-code that uses axis
words appears on the line, the activity of the group 1 G-code is
suspended for that line. The axis word-using G-codes from group 0 are
G10, G28, G30, G52 and G92.
It is an error to include any unrelated words on a line with 'O-' flow
control.
[[gcode:comments]]
== Comments
Comments can be added to lines of G code to help clear up the
intention of the programmer. Comments can be embedded in a line using
parentheses () or for the remainder of a line using a semi-colon. The
semi-colon is not treated as the start of a comment when enclosed in
parentheses.
Comments may appear between words, but not between words and their
corresponding parameter. So, 'S100(set speed)F200(feed)' is OK while
'S(speed)100F(feed)' is not.
----
G0 (Rapid to start) X1 Y1
G0 X1 Y1 (Rapid to start; but don't forget the coolant)
M2 ; End of program.
----
There are several 'active' comments which look like comments but cause
some action, like '(debug,..)' or '(print,..)'. If there are
several comments on a line, only the last comment will be interpreted
according to these rules. Hence, a normal comment following an active
comment will in effect disable the active comment. For example, '(foo)
(debug,#1)' will print the value of parameter '#1', however
'(debug,#1)(foo)' will not.
A comment introduced by a semicolon is by definition the last comment
on that line, and will always be interpreted for active comment syntax.
NOTE: Inline comments on O words should not be used see the O Code
<<ocode:comments, comments>> section for more information.
[[gcode:messages]]
== Messages
* '(MSG,)' - displays message if 'MSG' appears after the left parenthesis
and before any other printing characters. Variants of 'MSG' which include
white space and lower case characters are allowed. The rest of the
characters before the right parenthesis are considered to be a message.
Messages should be displayed on the message display device of the user
interface if provided.
.Message Example
----
(MSG, This is a message)
----
(((Probe Logging)))
== Probe Logging
* '(PROBEOPEN filename.txt)' - will open filename.txt and store the 9-number
coordinate consisting of XYZABCUVW of each successful straight probe in it.
* '(PROBECLOSE)' - will close the open probelog file. For more information on
probing see the <<gcode:g38,G38>> Section.
(((Logging)))
== Logging
* '(LOGOPEN,filename.txt)' - opens the named log file. If the file already
exists, it is truncated.
* '(LOGAPPEND,filename)' - opens the named log file. If the file already
exists, the data is appended.
* '(LOGCLOSE)' - closes an open log file.
* '(LOG,)' - everything past the ',' is written to the log file if it is open.
Supports expansion of parameters as described below.
Examples of logging are in 'nc_files/examples/smartprobe.ngc' and in
'nc_files/ngcgui_lib/rectange_probe.ngc' sample G code files.
[[gcode:debug]]
== Debug Messages
(((Debug Messages)))
* '(DEBUG,)' - displays a message like '(MSG,)' with the addition of special
handling for comment parameters as described below.
[[gcode:print]]
== Print Messages
(((Print Messages)))
* '(PRINT,)' - messages are output to 'stderr' with special handling for
comment parameters as described below.
[[gcode:comment-parameters]]
== Comment Parameters
(((Comment Parameters)))
In the DEBUG, PRINT and LOG comments, the values of parameters in the
message are expanded.
For example: to print a named global variable to stderr (the default
console window).
.Parameters Example
----
(print,endmill dia = #<_endmill_dia>)
(print,value of variable 123 is: #123)
----
Inside the above types of comments, sequences like '\#123' are replaced
by the value of the parameter 123. Sequences like '\#<named parameter>'
are replaced by the value of the named parameter. Named parameters
will have white space removed from them. So, '\#<named parameter>'
will be converted to '#<namedparameter>'.
[[gcode:file-requirements]]
== File Requirements
A G code file must contain one or more lines of G code and be terminated
with a <<mcode:m2-m30,Program End>>. Any G code past the program end
is not evaluated.
If a program end code is not used a pair of percent signs '%' with the first
percent sign on the first line of the file followed by one or more lines of
G code and a second percent sign. Any code past the second percent sign is not
evaluated.
[WARNING]
Using % to wrap a G code file will not do the same thing as using a program
end. The machine will be in what ever state the program left it in using %,
the spindle and coolant may still be on and things like G90/91 are left as the
last program set them. If you don't use a proper preamble the next program
could start in a dangerous condition.
[NOTE]
The file must be created with a text editor like Gedit and not a word
processor like Open Office Word Processor.
== File Size
The interpreter and task are carefully written so that the only limit
on part program size is disk capacity. The TkLinuxCNC and Axis interface
both load the program text to display it to the user, though, so RAM
becomes a limiting factor. In Axis, because the preview plot is drawn
by default, the redraw time also becomes a practical limit on program
size. The preview can be turned off in Axis to speed up loading large
part programs. In Axis sections of the preview can be turned off using
<<axis:preview-control,preview control>> comments.
[[gcode:order-of-execution]](((G Code Order of Execution)))
== G Code Order of Execution
The order of execution of items on a line is defined not by the
position of each item on the line, but by the following list:
* O-word commands (optionally followed by a comment but no other words allowed
on the same line)
* Comment (including message)
* Set feed rate mode (G93, G94).
* Set feed rate (F).
* Set spindle speed (S).
* Select tool (T).
* HAL pin I/O (M62-M68).
* Change tool (M6) and Set Tool Number (M61).
* Spindle on or off (M3, M4, M5).
* Save State (M70, M73), Restore State (M72), Invalidate State (M71).
* Coolant on or off (M7, M8, M9).
* Enable or disable overrides (M48, M49,M50,M51,M52,M53).
* User-defined Commands (M100-M199).
* Dwell (G4).
* Set active plane (G17, G18, G19).
* Set length units (G20, G21).
* Cutter radius compensation on or off (G40, G41, G42)
* Cutter length compensation on or off (G43, G49)
* Coordinate system selection (G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3).
* Set path control mode (G61, G61.1, G64)
* Set distance mode (G90, G91).
* Set retract mode (G98, G99).
* Go to reference location (G28, G30) or change coordinate system
data (G10) or set axis offsets (G52, G92, G92.1, G92.2, G94).
* Perform motion (G0 to G3, G33, G38.n, G73, G76, G80 to G89), as modified
(possibly) by G53.
* Stop (M0, M1, M2, M30, M60).
(((G Code Best Practices)))
== G Code Best Practices
.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.
.Use consistent white space
G-code is most legible when at least one space appears before words.
While it is permitted to insert white space in the middle of numbers,
there is no reason to do so.
.Use 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.
.Use a Preamble set modal groups
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 previous programs and from the MDI commands.
.Example Preamble for a Mill
[source,{ngc}]
----
G17 G20 G40 G49 G54 G80 G90 G94
----
G17 use XY plane, G20 inch mode, G40 cancel diameter compensation,
G49 cancel length offset, G54 use coordinate system 1, G80 cancel canned
cycles, G90 absolute distance mode, G94 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.
.Don't put too many things on one line
Ignore everything in Section <<gcode:order-of-execution,Order of Execution>>, and instead
write no line of code that is the slightest bit ambiguous.
.Don't set & use a parameter on the same line
Don't use and set a parameter on the same line, even though the
semantics are well defined. Updating a variable to a new value, such as
'#1=[#1+#2]' is OK.
.Don't use line numbers
Line numbers offer no benefits. When line numbers are reported in
error messages, the numbers refer to the line number in the file, not
the N-word value.
== Linear and Rotary Axis
Because the meaning of an F-word in feed-per-minute mode varies
depending on which axes are commanded to move, and because the amount
of material removed does not depend only on the feed rate, it may be
easier to use G93 inverse time feed mode to achieve the desired
material removal rate.
== Common Error Messages
* 'G code out of range' - A G code greater than G99 was used, the scope of G
codes in LinuxCNC is 0 - 99. Not every number between 0 and 99 is a valid
G code.
* 'Unknown g code used' - A G code was used that is not part of the LinuxCNC
G code language.
* 'i,j,k word with no Gx to use it' - i, j and k words must be used on the same
line as the G code.
* 'Cannot use axis values without a g code that uses them' - Axis values can
not be used on a line without either a modal G code in effect or a G code
on the same line.
* 'File ended with no percent sign or program end' - Every G code file must
end in a M2 or M30 or be wrapped with the percent sign %.
[[cha:rs274ngc-programs]]
= RS274/NGC Differences
== Changes from RS274/NGC
.Differences that change the meaning of RS274/NGC programs
Location after a tool change::
In LinuxCNC, the machine does not return to its original position
after a tool change. This change was made because the new tool
might be longer than the old tool, and the move to the original
machine position could therefore leave the tool tip too low.
Offset parameters are ini file units::
In LinuxCNC, the values stored in parameters for the G28 and G30 home
locations, the P1...P9 coordinate systems, and the G92 offset are
in "ini file units". This change was made because otherwise the
meaning of a location changed depending on whether G20 or G21 was
active when G28, G30, G10 L2, or G92.3 is programmed.
Tool table lengths/diameters are in ini file units::
In LinuxCNC, the tool lengths (offsets) and diameters in the tool
table are specified in ini file units only. This change was made
because otherwise the length of a tool and its diameter would
change based on whether G20 or G21 was active when initiating
G43, G41, G42 modes. This made it impossible to run G code in the
machine's non-native units, even when the G code was simple and
well-formed (starting with G20 or G21, and didn't change units
throughout the program), without changing the tool table.
G84, G87 not implemented::
G84 and G87 are not currently implemented, but may be added to a
future release of LinuxCNC.
G28, G30 with axis words::
When G28 or G30 is programmed with only some axis words present,
LinuxCNC only moves the named axes. This is common on other machine
controls. To move some axes to an intermediate point and then
move all axes to the predefined point, write two lines of G code:
+
G0 X- Y- (axes to move to intermediate point) G28 (move all axes
to predefined point)
== Additions to RS274/NGC
.Differences that do not change the meaning of RS274/NGC programs
G33, G76 threading codes::
These codes are not defined in RS274/NGC.
G38.2::
The probe tip is not retracted after a G38.2 movement. This
retraction move may be added in a future release of LinuxCNC.
G38.3...G38.5::
These codes are not defined in RS274/NGC
O-codes::
These codes are not defined in RS274/NGC
M50...M53 overrides::
These codes are not defined in RS274/NGC
M61..M66::
These codes are not defined in RS274/NGC
G43, G43.1::
'Negative Tool Lengths'
+
The RS274/NGC spec says "it is expected that" all tool lengths
will be positive. However, G43 works for negative tool lengths.
+
'Lathe tools'
+
G43 tool length compensation can offset the tool in both the X
and Z dimensions. This feature is primarily useful on lathes.
+
'Dynamic tool lengths'
+
LinuxCNC allows specification of a computed tool length through G43.1
I K.
G41.1, G42.1::
LinuxCNC allows specification of a tool diameter and, if in lathe
mode, orientation in the G code. The format is G41.1/G42.1 D L,
where D is diameter and L (if specified) is the lathe tool
orientation.
G43 without H word::
In ngc, this is not allowed. In LinuxCNC, it sets length offsets for
the currently loaded tool. If no tool is currently loaded, it is
an error. This change was made so the user doesn't have to
specify the tool number in two places for each tool change, and
because it's consistent with the way G41/G42 work when the D word
is not specified.
U, V, and W axes::
LinuxCNC allows machines with up to 9 axes by defining an additional
set of 3 linear axes known as U, V and W
[[cha:tool-compensation]]
= Tool Compensation
== Tool Length Offsets
=== Touch Off(((Touch Off)))
Using the Touch Off Screen in the AXIS interface you can update the
tool table automatically.
Typical steps for updating the tool table:
* After homing load a tool with 'Tn M6' where 'n' is the tool number.
* Move tool to an established point using a gauge or take a test cut and
measure.
* Click the "Touch Off" button in the Manual Control tab (or hit the
End button on your keyboard).
* Select 'Tool Table' in the Coordinate System drop down box.
* Enter the gauge or measured dimension and select OK.
The Tool Table will be changed with the correct Z length to make the
DRO display the correct Z position and a G43 command will be issued so
the new tool Z length will be in effect. Tool table touch off is only
available when a tool is loaded with 'Tn M6'.
.Touch Off Tool Table
image::images/ToolTable-TouchOff.png[align="center", alt="Touch Off Tool Table"]
=== Using G10 L1/L10/L11
The G10 L1/L10/L11 commands can be used to set tool table offsets:
* 'G10 L1 Pn' - Set offset(s) to a value. Current position irrelevant.
(see <<gcode:g10-l1,G10 L1>> for details)
* 'G10 L10 Pn' - Set offset(s) so current position w/ fixture 1-8 becomes a value.
(see <<gcode:g10-l10,G10 L10>> for details)
* 'G10 L11 Pn' - Set offset(s) so current position w/ fixture 9 becomes a value.
(see <<gcode:g10-l11,G10 L11>> for details)
[[sec:tool-table]]
== Tool Table
The 'Tool Table' is a text file that contains information about each
tool. The file is located in the same directory as your configuration
and is called 'tool.tbl'. The tools might be in a tool changer or just
changed manually. The file can be edited with a text editor or be
updated using G10 L1. See the <<sec:lathe-tool-table,Lathe Tool Table>>
Section for an example of the lathe tool table format.
The maximum number of entries in the tool table is 56.
The maximum tool and pocket number is 99999.
The <<cha:tooledit-gui,Tool Editor>> or a text editor can be used to edit the
tool table. If you use a text editor make sure you reload the tool table in
the GUI.
=== Tool Table Format
(((Tool-Table-Format)))
.Tool Table Format
[width="100%", options="header"]
|====
|T# |P# |X |Y |Z |A |B |C |U |V |W |Dia |FA |BA |Ori |Rem
|; 15+^|(no data after opening semicolon)
|T1 |P17 |X0 |Y0 |Z0 |A0 |B0 |C0 |U0 |V0 |W0 |D0 |I0 |J0 |Q0 |;rem
|T2 |P5 |X0 |Y0 |Z0 |A0 |B0 |C0 |U0 |V0 |W0 |D0 |I0 |J0 |Q0 |;rem
|T3 |P12 |X0 |Y0 |Z0 |A0 |B0 |C0 |U0 |V0 |W0 |D0 |I0 |J0 |Q0 |;rem
|====
In general, the new tool table line format is:
- ; - opening semicolon, no data
- T - tool number, 0-99999 (tool numbers must be unique)
- P - pocket number, 1-99999 (pocket numbers must be unique)
- X..W - tool offset on specified axis - floating-point
- D - tool diameter - floating-point, absolute value
- I - front angle (lathe only) - floating-point
- J - back angle (lathe only) - floating-point
- Q - tool orientation (lathe only) - integer, 0-9
- ; - beginning of comment or remark - text
The file consists of one opening semicolon on the first line,
followed by up to a maximum of 56 tool entries.
[NOTE]
Although tool numbers up to 99999 are allowed, the number of entries in the
tool table, at the moment, is still limited to a maximum of 56 tools for
technical reasons. The LinuxCNC developers plan to remove that limitation
eventually. If you have a very large tool changer, please be patient.
Earlier versions of LinuxCNC had two different tool table formats for
mills and lathes, but since the 2.4.x release, one tool table format
is used for all machines. Just ignore the parts of the tool table
that don't pertain to your machine, or which you don't need to use.
Each line of the tool table file after the opening semicolon contains
the data for one tool. One line may contain as many as 16 entries,
but will likely contain much fewer.
The units used for the length, diameter, etc., are in machine units.
You will probably want to keep the tool entries in ascending order,
especially if you are going to be using a randomizing tool changer.
Although the tool table does allow for tool numbers in any order.
Each line may have up to 16 entries. The first two entries are required.
The last entry (a remark or comment, preceded by a semicolon) is
optional. It makes reading easier if the entries are arranged in
columns, as shown in the table, but the only format requirement is
that there be at least one space or tab after each of the entries on
a line and a newline character at the end of each entry.
The meanings of the entries and the type of data to be put in each are
as follows.
.Tool Number (required)
The 'T' column contains the number (unsigned integer) which
represents a code number for the tool. The user may use any code for
any tool, as long as the codes are unsigned integers.
.Pocket Number (required)
The 'P' column contains the number (unsigned integer) which
represents the pocket number (slot number) of the tool changer slot
where the tool can be found. The entries in this column must all be
different.
The pocket numbers will typically start at 1 and go up to the highest
available pocket on your tool changer. But not all tool changers follow
this pattern. Your pocket numbers will be determined by the numbers
that your tool changer uses to refer to the pockets. So all this is to
say that the pocket numbers you use will be determined by the numbering
scheme used in your tool changer, and the pocket numbers you use must
make sense on your machine.
.Data Offset Numbers (optional)
The 'Data Offset' columns (XYZABCUVW) contain real numbers which
represent tool offsets in each axis. This number will be used if tool
length offsets are being used and this tool is selected.
These numbers can be positive, zero, or negative, and are in fact
completely optional. Although you will probably want to make at least
one entry here, otherwise there would be little point in making an
entry in the tool table to begin with.
In a typical mill, you probably want an entry for Z (tool length
offset). In a typical lathe, you probably want an entry for X
(X tool offset) and Z (Z tool offset). In a typical mill using
cutter diameter compensation (cutter comp), you probably also want
to add an entry for D (cutter diameter). In a typical lathe using
tool nose diameter compensation (tool comp), you probably also want
to add an entry for D (tool nose diameter).
A lathe also requires some additional information to describe the shape and
orientation of the tool. So you probably want to have entries for I (tool
front angle) and J (tool back angle). You probably also want an entry for Q
(tool orientation).
See the <<cha:lathe-user-information,Lathe User Information>> chapter for
more detail.
The 'Diameter' column contains a real number. This number is used only
if cutter compensation is turned on using this tool. If the
programmed path during compensation is the edge of the material being
cut, this should be a positive real number representing the measured
diameter of the tool. If the programmed path during compensation is the
path of a tool whose diameter is nominal, this should be a small number
(positive or negative, but near zero) representing only the difference
between the measured diameter of the tool and the nominal diameter.
If cutter compensation is not used with a tool, it does not
matter what number is in this column.
The 'Comment' column may optionally be used to describe the tool. Any
type of description is OK. This column is for the benefit of human
readers only. The comment must be preceded by a semicolon.
[[sec:tool-changers]]
=== Tool Changers
LinuxCNC supports three types of tool changers: 'manual', 'random location'
and 'fixed location'. Information about configuring a LinuxCNC tool changer
is in the <<sec:emcio-section,EMCIO Section>> of the INI chapter.
.Manual Tool Changer
Manual tool changer (you change the tool by hand) is treated like a
fixed location tool changer and the P number is ignored. Using the
manual tool changer only makes sense if you have tool holders that
remain with the tool (Cat, NMTB, Kwik Switch etc.) when changed thus
preserving the location of the tool to the spindle. Machines with R-8
or router collet type tool holders do not preserve the location of the
tool and the manual tool changer should not be used.
.Fixed Location Tool Changers
Fixed location tool changers always return the tools to a
fixed position in the tool changer. This would also include
designs like lathe turrets. When LinuxCNC is configured for a fixed
location tool changer the 'P' number is ignored (but read, preserved
and rewritten) by LinuxCNC, so you can use P for any bookkeeping number you
want.
.Random Location Tool Changers
Random location tool changers swap the tool in the spindle with the
one in the changer. With this type of tool changer the tool will
always be in a different pocket after a tool change. When a tool is
changed LinuxCNC rewrites the pocket number to keep track of where the tools
are. T can be any number but P must be a number that makes sense for
the machine.
[[sec:cutter-compensation]]
== Cutter Compensation
Cutter Compensation allows the programmer to program the tool
path without knowing the exact tool diameter. The only caveat is the
programmer must program the lead in move to be at least as long as the
largest tool radius that might be used.
There are two possible paths the cutter can take while cutter
compensation is on to the left or right side of a line when facing the
direction of cutter motion from behind the cutter. To visualize this
imagine you were standing on the part walking behind the tool as it
progresses across the part. G41 is your left side of the line and G42
is the right side of the line.
The end point of each move depends on the next move. If the next move
creates an outside corner the move will be to the end point of the
compensated cut line. If the next move creates in an inside corner the
move will stop short so to not gouge the part. The following figure
shows how the compensated move will stop at different points depending
on the next move.
.Compensation End Point
image::images/comp-path.png[align="center", alt="Compensation End Point"]
=== Overview
.Tool Table
Cutter compensation uses the data from the tool table to
determine the offset needed. The data can be set at run time with G10
L1.
.Programming Entry Moves
Any move that is long enough to perform the compensation will work as
the entry move. The minimum length is the cutter radius. This can be a
rapid move above the work piece. If several rapid moves are issued
after a G41/42 only the last one will move the tool to the compensated
position.
In the following figure you can see that the entry move is compensated
to the right of the line. This puts the center of the tool to the right
of X0 in this case. If you were to program a profile and the end is at
X0 the resulting profile would leave a bump due to the offset of the
entry move.
.Entry Move
image::images/comp02.png[alt="Entry Move"]
.Z Motion
Z axis motion may take place while the contour is being followed in
the XY plane. Portions of the contour may be skipped by retracting the
Z axis above the part and by extending the Z-axis at the next start
point.
.Rapid Moves
Rapid moves may be programed while compensation is turned on.
.Good Practices
- Start a program with G40 to make sure compensation is off.
=== Examples
.Outside Profile
.Outside Profile
image::images/outside-comp.png[alt="Outside Profile"]
.Inside Profile
.Inside Profile
image::images/inside-comp.png[alt="Inside Profile"]
Coordinate Systems
==================
Introduction
------------
This chapter introduces you to offsets as they are used by the LinuxCNC.
These include:
* Machine Coordinates (G53)
* Nine Coordinate System Offsets (G54-G59.3)
* Global Offsets (G92) and Local Offsets (G52)
Machine Coordinate System
-------------------------
When LinuxCNC is started the postions of each axis is the machine origin. Once an axis homed the the
machine orgin for that axis is set to the homed position. The machine origin is the machine
coordinate system which all other coordinate systems are based. The `G53 <#gcode:g53>`__ G code can
be used to move in the machine coordinate system.
.. _coordinate-systems-1:
Coordinate Systems
------------------
|Example of Coordinate Systems|
Figure 1. Example of Coordinate Systems
Coordinate System Offsets
* G54 - use coordinate system 1
* G55 - use coordinate system 2
* G56 - use coordinate system 3
* G57 - use coordinate system 4
* G58 - use coordinate system 5
* G59 - use coordinate system 6
* G59.1 - use coordinate system 7
* G59.2 - use coordinate system 8
* G59.3 - use coordinate system 9
Coordinate system offsets are used to shift the coordinate system from the machine coordinate
system. This allows the G code to be programmed for the part without regard to the part location on
the machine. Using coordinate system offsets would allow you to machine parts in multiple locations
with the same G code.
The values for offsets are stored in the VAR file that is requested by the INI file during the
startup of an LinuxCNC.
In the VAR file scheme, the first variable number stores the X offset, the second the Y offset and
so on for all nine axes. There are numbered sets like this for each of the coordinate system
offsets.
Each of the graphical interfaces has a way to set values for these offsets. You can also set these
values by editing the VAR file itself and then restart LinuxCNC so that the LinuxCNC reads the new
values however this is not the recommended way. Using G10, G52, G92, G28.1, etc are better ways to
set the variables.
==== ======== =========
Axis Variable Value
==== ======== =========
X 5241 2.000000
Y 5242 1.000000
Z 5243 -2.000000
A 5244 0.000000
B 5245 0.000000
C 5246 0.000000
U 5247 0.000000
V 5248 0.000000
W 5249 0.000000
==== ======== =========
You should read this as moving the zero positions of G55 to X = 2 units, Y= 1 unit, and Z = -2 units
away from the absolute zero position.
Once there are values assigned, a call to G55 in a program block would shift the zero reference by
the values stored. The following line would then move each axis to the new zero position. Unlike
G53, G54 through G59.3 are modal commands. They will act on all blocks of code after one of them has
been set. The program that might be run using fixture offsets would require only a single coordinate
reference for each of the locations and all of the work to be done there. The following code is
offered as an example of making a square using the G55 offsets that we set above.
::
G55 ; use coordinate system 2
G0 X0 Y0 Z0
G1 F2 Z-0.2000
X1
Y1
X0
Y0
G0 Z0
G54 ; use coordinate system 1
G0 X0 Y0 Z0
M2
In this example the G54 near the end leaves the G54 coordinate system with all zero offsets so that
there is a modal code for the absolute machine based axis positions. This program assumes that we
have done that and use the ending command as a command to machine zero. It would have been possible
to use G53 and arrive at the same place but that command would not have been modal and any commands
issued after it would have returned to using the G55 offsets because that coordinate system would
still be in effect.
Default Coordinate System
~~~~~~~~~~~~~~~~~~~~~~~~~
One other variable in the VAR file becomes important when we think about offset systems. This
variable is named 5220. In the default files its value is set to 1.00000. This means that when the
LinuxCNC starts up it should use the first coordinate system as its default. If you set this to
9.00000 it would use the ninth offset system as its default for start up and reset. Any value other
than an integer (decimal really) between 1 and 9, or a missing 5220 variable will cause the LinuxCNC
to revert to the default value of 1.00000 on start up.
Setting Coordinate System Offsets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The G10 L2x command can be used to set coordinate system offsets:
* 'G10 L2 P(1-9)' - Set offset(s) to a value. Current position irrelevant. (see `G10 L2
<#gcode:g10-l2>`__ for details)
* 'G10 L20 P(1-9)' - Set offset(s) so current position becomes a value. (see `G10 L20
<#gcode:g10-l20>`__ for details)
Local and Global Offsets
------------------------
The G52 command
~~~~~~~~~~~~~~~
'G52' is used in a part program as a temporary "local coordinate system offset" within the workpiece
coordinate system. An example use case is when machining several identical features at different
locations on a part. For each feature, 'G52' programs a local reference point within workpiece
coordinates, and a subprogram is called to machine the feature relative to that point.
'G52' axis offsets are programmed relative to workpiece coordinate offsets 'G54' through 'G59.3'. As
a local offset, 'G52' is applied after the workpiece offset, including rotation. Thus, a part
feature will be machined identically on each part regardless of the part’s orientation on the
pallet.
Programming 'G52 X1 Y2' offsets the current workpiece coordinate system X axis by 1 and Y axis
by 2. Accordingly, on the DRO, the current tool position’s X and Y coordinates will be reduced by 1
and 2, respectively. Axes unset in the command, such as Z in the previous example, will be
unaffected: any previous 'G52' Z offset will remain in effect, and otherwise the Z offset will be
zero.
The temporary local offset may be canceled with 'G52 X0 Y0'. Any axes not explicitly zeroed will
retain the previous offset.
'G52' shares the same offset registers as 'G92', and thus 'G52' is visible on the DRO and preview
labeled with 'G92'.
The G92 commands
~~~~~~~~~~~~~~~~
'G92' is typically used in two conceptually different ways: as a "global coordinate system offset"
or as a "local coordinate system offset". The 'G92' set of commands includes:
* 'G92' - This command, when used with axis names, sets values to offset variables.
* 'G92.1' - This command sets zero values to the G92 variables.
* 'G92.2' - This command suspends but does not zero out the G92 variables.
* 'G92.3' - This command applies offset values that have been suspended.
As a global offset, 'G92' is used to shift all workpiece coordinate systems 'G54' through
'G59.3'. An example use case is when machining several identical parts in fixtures with known
locations on a pallet, but the pallet location may change between runs or between machines. Each
fixture location offset, relative to a reference point on the pallet, is preset in one of the
workpiece coordinate systems, 'G54' through 'G59.3', and 'G92' is used to "touch off" on the pallet
reference point. Then, for each part, the corresponding workpiece coordinate system is selected and
the part program is executed.
As a local coordinate system, 'G92' is used as a temporary offset within the workpiece coordinate
system. An example use case is when machining a part with several identical features at different
locations. For each feature, 'G92' is used to set a local reference point, and a subprogram is
called to machine the feature starting at that point.
Programming 'G92 X0 Y0 Z0' sets the current tool location to the coordinates X0, Y0, and Z0, without
motion. G92 **does not** work from absolute machine coordinates. It works from **current location**.
'G92' also works from current location as modified by any other offsets that are in effect when the
'G92' command is invoked. While testing for differences between work offsets and actual offsets it
was found that a 'G54' offset could cancel out a 'G92' and thus give the appearance that no offsets
were in effect. However, the 'G92' was still in effect for all coordinates and did produce expected
work offsets for the other coordinate systems.
By default, 'G92' offsets are restored after the machine is started. Programmers that wish for
Fanuc behavior, where 'G92' offsets are cleared at machine start and after a reset or program end,
may disable 'G92' persistence by setting 'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section
of the '.ini' file.
Setting G92 Values
~~~~~~~~~~~~~~~~~~
G92 commands work from current axis location and add and subtract correctly to give the current axis
position the value assigned by the G92 command. The effects work even though previous offsets are
in.
So if the X axis is currently showing 2.0000 as its position a 'G92 X0' will set an offset of
-2.0000 so that the current location of X becomes zero. A 'G92 X2' will set an offset of 0.0000 and
the displayed position will not change. A 'G92 X5.0000' will set an offset of 3.0000 so that the
current displayed position becomes 5.0000.
G92 Persistence Cautions
~~~~~~~~~~~~~~~~~~~~~~~~
By default, the values of a 'G92' offset will be saved in the VAR file and be restored after a
machine reset or startup.
The G92 parameters are:
* 5210 - Enable/disable flag (1.0/0.0)
* 5211 - X Axis Offset
* 5212 - Y Axis Offset
* 5213 - Z Axis Offset
* 5214 - A Axis Offset
* 5215 - B Axis Offset
* 5216 - C Axis Offset
* 5217 - U Axis Offset
* 5218 - V Axis Offset
* 5219 - W Axis Offset
where 5210 is the 'G92' enable flag (1 for enabled, 0 for disabled) and 5211 to 5219 are the axis
offsets. If you are seeing unexpected positions as the result of a commanded move, as a result of
storing an offset in a previous program and not clearing them at the end then issue a G92.1 in the
MDI window to clear the stored offsets.
If G92 values exist in the VAR file when LinuxCNC starts up, the G92 values in the var file will be
applied to the values of the current location of each axis. If this is home position and home
position is set as machine zero everything will be correct. Once home has been established using
real machine switches, or by moving each axis to a known home position and issuing an axis home
command, any G92 offsets will be applied. If you have a G92 X1 in effect when you home the X axis
the DRO will read 'X: 1.000' instead of the expected 'X: 0.000' because the G92 was applied to the
machine origin. If you issue a G92.1 and the DRO now reads all zeros then you had a G92 offset in
effect when you last ran LinuxCNC.
Unless your intention is to use the same G92 offsets in the next program, the best practice is to
issue a G92.1 at the end of any G code files where you use G92 offsets.
When a program is aborted during processing that has 'G92' offsets in effect a startup will cause
them to become active again. As a safeguard, always have your preamble to set the environment as you
expect it. Additionally, 'G92' persistence may be disabled by setting 'DISABLE_G92_PERSISTENCE = 1'
in the '[RS274NGC]' section of the '.ini' file.
G92 and G52 Interaction Cautions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'G52' and 'G92' share the same offset registers. Unless 'G92' persistence is disabled in the '.ini'
file (see `G92 Commands <#sec:g92-commands>`__), 'G52' offsets will also persist after machine
reset, 'M02' or 'M30'. Beware that a 'G52' offset in effect during a program abort may result in
unintended offsets when the next program is run. See `G92 Persistence Cautions
<#sec:g92-persistence-cautions>`__ above.
Sample Programs Using Offsets
-----------------------------
Sample Program Using Workpiece Coordinate Offsets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This sample engraving project mills a set of four .1 radius circles in roughly a star shape around a
center circle. We can setup the individual circle pattern like this.
::
G10 L2 P1 X0 Y0 Z0 (ensure that G54 is set to machine zero)
G0 X-0.1 Y0 Z0
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
M2
We can issue a set of commands to create offsets for the four other circles like this.
::
G10 L2 P2 X0.5 (offsets G55 X value by 0.5 inch)
G10 L2 P3 X-0.5 (offsets G56 X value by -0.5 inch)
G10 L2 P4 Y0.5 (offsets G57 Y value by 0.5 inch)
G10 L2 P5 Y-0.5 (offsets G58 Y value by -0.5 inch)
We put these together in the following program:
::
(a program for milling five small circles in a diamond shape)
G10 L2 P1 X0 Y0 Z0 (ensure that G54 is machine zero)
G10 L2 P2 X0.5 (offsets G55 X value by 0.5 inch)
G10 L2 P3 X-0.5 (offsets G56 X value by -0.5 inch)
G10 L2 P4 Y0.5 (offsets G57 Y value by 0.5 inch)
G10 L2 P5 Y-0.5 (offsets G58 Y value by -0.5 inch)
G54 G0 X-0.1 Y0 Z0 (center circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G55 G0 X-0.1 Y0 Z0 (first offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G56 G0 X-0.1 Y0 Z0 (second offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G57 G0 X-0.1 Y0 Z0 (third offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G0 Z0
G58 G0 X-0.1 Y0 Z0 (fourth offset circle)
G1 F1 Z-0.25
G3 X-0.1 Y0 I0.1 J0
G54 G0 X0 Y0 Z0
M2
Now comes the time when we might apply a set of G92 offsets to this program. You’ll see that it is
running in each case at Z0. If the mill were at the zero position, a G92 Z1.0000 issued at the head
of the program would shift everything an inch. You might also shift the whole pattern around in the
XY plane by adding some X and Y offsets with G92. If you do this you should add a G92.1 command
just before the M2 that ends the program. If you do not, other programs that you might run after
this one will also use that G92 offset. Furthermore it would save the G92 values when you shut down
the LinuxCNC and they will be recalled when you start up again.
Sample Program Using G52 Offsets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(To be written)
.. |Example of Coordinate Systems| image:: images/offsets.png
G Codes
=======
Conventions
-----------
Conventions used in this section
In the G code prototypes the hyphen (``-``) stands for a real value and (``<>``) denotes an optional
item.
If ``L-`` is written in a prototype the ``-`` will often be referred to as the ``L number``, and so on for
any other letter.
In the G code prototypes the word ``axes`` stands for any axis as defined in your configuration.
An optional value will be written like this ``<L→``.
A real value may be:
* An explicit number, ``4``
* An expression, ``[2+2]``
* A parameter value, ``#88``
* A unary function value, ``acos[0]``
In most cases, if ``axis`` words are given (any or all of ``X Y Z A B C U V W``), they specify a
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
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.
If ``L-`` is written in a prototype the ``-`` will often be referred to as the ``L number``, and so on for
any other letter.
G Code Quick Reference Table
----------------------------
==================================== ===========================================
Code Description
==================================== ===========================================
`G0 <gcode_g0>`_ Coordinated Motion at Rapid Rate
`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
-------------
.. code:: text
G0 axes
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.
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
.. code:: text
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.
If ``G53`` is programmed on the same line, the motion will also differ; see the `G53 <#gcode:g53>`__
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.
**It is an error if:**
* An axis letter is without a real value.
* An axis letter is used that is not configured
G1 Linear Move
--------------
.. code:: text
G1 axes
For linear (straight line) motion at programed `feed rate <#sec:set-feed-rate>`__ (for cutting or
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
current feed rate (or slower).
G1 Example
.. code:: text
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)
* See `G90 <#gcode:g90-g91>`__ & `F <#sec:set-feed-rate>`__ & `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.
If ``G53`` is programmed on the same line, the motion will also differ; see the `G53 <#gcode:g53>`__
Section for more information.
**It is an error if:**
* 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
---------------
.. code:: text
G2 or G3 axes offsets (center format)
G2 or G3 axes R- (radius format)
G2 or G3 offsets|R- <P-> (full circles)
A circular or helical arc is specified using either ``G2`` (clockwise arc) or ``G3`` (counterclockwise
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
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
selected plane.
To program a helix, include the axis word perpendicular to the arc plane: for example, if in the
``G17`` plane, include a ``Z`` word. This will cause the ``Z`` axis to move to the programmed value during
the circular ``XY`` motion.
To program an arc that gives more than one full turn, use the ``P`` word specifying the number of full
turns plus the programmed arc. The ``P`` word must be an integer. If ``P`` is unspecified, the behavior
is as if ``P1`` was given: that is, only one full or partial turn will result. For example, if a 180
degree arc is programmed with a P2, the resulting motion will be 1 1/2 rotations. For each P
increment above 1 an extra full circle is added to the programmed arc. Multi turn helical arcs are
supported and give motion useful for milling holes or threads.
If a line of code makes an arc and includes rotary axis motion, the rotary axes turn at a constant
rate so that the rotary motion starts and finishes when the XYZ motion starts and finishes. Lines of
this sort are hardly ever programmed.
If cutter compensation is active, the motion will differ from the above; see the `Cutter
Compensation <#sec:cutter-compensation>`__ Section.
The arc center is absolute or relative as set by `G90.1 or G91.1 <#gcode:g90.1-g91.1>`__
respectively.
Two formats are allowed for specifying an arc: Center Format and Radius Format.
**It is an error if:**
* No feed rate has been set.
* The P word is not an integer.
Center Format Arcs
~~~~~~~~~~~~~~~~~~
Center format arcs are more accurate than radius format arcs and are the preferred format to use.
The end point of the arc along with the offset to the center of the arc from the current location
are used to program arcs that are less than a full circle. It is OK if the end point of the arc is
the same as the current location.
The offset to the center of the arc from the current location and optionally the number of turns are
used to program full circles.
When programming arcs an error due to rounding can result from using a precision of less than 4
decimal places (0.0000) for inch and less than 3 decimal places (0.000) for millimeters.
Incremental Arc Distance Mode
Arc center offsets are a relative distance from the start location of the arc. Incremental Arc
Distance Mode is default.
One or more axis words and one or more offsets must be programmed for an arc that is less than 360
degrees.
No axis words and one or more offsets must be programmed for full circles. The ``P`` word defaults to
1 and is optional.
For more information on Incremental Arc Distance Mode see the `G91.1 <#gcode:g90.1-g91.1>`__
section.
Absolute Arc Distance Mode
Arc center offsets are the absolute distance from the current 0 position of the axis.
One or more axis words and ``both`` offsets must be programmed for arcs
less than 360 degrees.
No axis words and both offsets must be programmed for full circles. The ``P`` word defaults to 1 and
is optional.
For more information on Absolute Arc Distance Mode see the `G90.1 <#gcode:g90.1-g91.1>`__ section.
XY-plane (G17)
.. code:: text
G2 or G3 <X- Y- Z- I- J- P->
* ``Z`` - helix
* ``I`` - X offset
* ``J`` - Y offset
* ``P`` - number of turns
XZ-plane (G18)
.. code:: text
G2 or G3 <X- Z- Y- I- K- P->
* ``Y`` - helix
* ``I`` - X offset
* ``K`` - Z offset
* ``P`` - number of turns
YZ-plane (G19)
.. code:: text
G2 or G3 <Y- Z- X- J- K- P->
* ``X`` - helix
* ``J`` - Y offset
* ``K`` - Z offset
* ``P`` - number of turns
**It is an error if:**
* No feed rate is set with the `F <#sec:set-feed-rate>`__ word.
* No offsets are programmed.
* When the arc is projected on the selected plane, the distance from the current point to the center
differs from the distance from the end point to the center by more than (.05 inch/.5 mm) OR
((.0005 inch/.005mm) AND .1% of radius).
Deciphering the Error message ``Radius to end of arc differs from radius to start:``
* ``start`` - the current position
* ``center`` - the center position as calculated using the i, j, or k words
* ``end`` - the programmed end point
* ``r1`` - radius from the start position to the center
* ``r2`` - radius from the end position to the center
Center Format Examples
~~~~~~~~~~~~~~~~~~~~~~
Calculating arcs by hand can be difficult at times. One option is to draw the arc with a cad program
to get the coordinates and offsets. Keep in mind the tolerance mentioned above, you may have to
change the precision of your cad program to get the desired results. Another option is to calculate
the coordinates and offset using formulas. As you can see in the following figures a triangle can be
formed from the current position the end position and the arc center.
In the following figure you can see the start position is X0 Y0, the end position is X1 Y1. The arc
center position is at X1 Y0. This gives us an offset from the start position of 1 in the X axis and
0 in the Y axis. In this case only an I offset is needed.
G2 Example Line
.. code:: text
G0 X0 Y0
G2 X1 Y1 I1 F10 (clockwise arc in the XY plane)
|G2 Example|
Figure 1. G2 Example
In the next example we see the difference between the offsets for Y if we are doing a G2 or a G3
move. For the G2 move the start position is X0 Y0, for the G3 move it is X0 Y1. The arc center is at
X1 Y0.5 for both moves. The G2 move the J offset is 0.5 and the G3 move the J offset is -0.5.
G2-G3 Example Line
.. code:: text
G0 X0 Y0
G2 X0 Y1 I1 J0.5 F25 (clockwise arc in the XY plane)
G3 X0 Y0 I1 J-0.5 F25 (counterclockwise arc in the XY plane)
|G2-G3 Example|
Figure 2. G2-G3 Example
In the next example we show how the arc can make a helix in the Z axis by adding the Z word.
G2 Example Helix
.. code:: text
G0 X0 Y0 Z0
G17 G2 X10 Y16 I3 J4 Z-1 (helix arc with Z added)
In the next example we show how to make more than one turn using the P word.
P word Example
.. code:: text
G0 X0 Y0 Z0
G2 X0 Y1 Z-1 I1 J0.5 P2 F25
In the center format, the radius of the arc is not specified, but it may be found easily as the
distance from the center of the circle to either the current point or the end point of the arc.
Radius Format Arcs
~~~~~~~~~~~~~~~~~~
.. code:: text
G2 or G3 axes R- <P->
* ``R`` - radius from current position
It is not good practice to program radius format arcs that are nearly full circles or nearly
semicircles because a small change in the location of the end point will produce a much larger
change in the location of the center of the circle (and, hence, the middle of the arc). The
magnification effect is large enough that rounding error in a number can produce out-of-tolerance
cuts. For instance, a 1% displacement of the endpoint of a 180 degree arc produced a 7% displacement
of the point 90 degrees along the arc. Nearly full circles are even worse. Other size arcs (in the
range tiny to 165 degrees or 195 to 345 degrees) are OK.
In the radius format, the coordinates of the end point of the arc in the selected plane are
specified along with the radius of the arc. Program ``G2`` ``axes`` ``R-`` (or use ``G3`` instead of ``G2``
). R is the radius. The axis words are all optional except that at least one of the two words for
the axes in the selected plane must be used. The R number is the radius. A positive radius indicates
that the arc turns through less than 180 degrees, while a negative radius indicates a turn of more
than 180 degrees. If the arc is helical, the value of the end point of the arc on the coordinate
axis parallel to the axis of the helix is also specified.
**It is an error if:**
* both of the axis words for the axes of the selected plane are omitted
* the end point of the arc is the same as the current point.
G2 Example Line
.. code:: text
G17 G2 X10 Y15 R20 Z5 (radius format with arc)
The above example makes a clockwise (as viewed from the positive Z-axis) circular or helical arc
whose axis is parallel to the Z-axis, ending where X=10, Y=15, and Z=5, with a radius of 20. If the
starting value of Z is 5, this is an arc of a circle parallel to the XY-plane; otherwise it is a
helical arc.
G4 Dwell
--------
.. code:: text
G4 P-
* ``P`` - seconds to dwell (floating point)
The P number is the time in seconds that all axes will remain unmoving.
The P number is a floating point number so fractions of a second may be
used. G4 does not affect spindle, coolant and any I/O.
G4 Example Line
.. code:: text
G4 P0.5 (wait for 0.5 seconds before proceeding)
**It is an error if:**
* the P number is negative or not specified.
G5 Cubic Spline
---------------
.. code:: text
G5 X- Y- <I- J-> P- Q-
* ``I`` - X incremental offset from start point to first control point
* ``J`` - Y incremental offset from start point to first control point
* ``P`` - X incremental offset from end point to second control point
* ``Q`` - Y incremental offset from end point to second control point
G5 creates a cubic B-spline in the XY plane with the X and Y axes only. P and Q must both be
specified for every G5 command.
For the first G5 command in a series of G5 commands, I and J must both be specified. For subsequent
G5 commands, either both I and J must be specified, or neither. If I and J are unspecified, the
starting direction of this cubic will automatically match the ending direction of the previous cubic
(as if I and J are the negation of the previous P and Q).
For example, to program a curvy N shape:
G5 Sample initial cubic spline
.. code:: text
G90 G17
G0 X0 Y0
G5 I0 J3 P0 Q-3 X1 Y1
A second curvy N that attaches smoothly to this one can now be made without specifying I and J:
G5 Sample subsequent cubic spline
.. code:: text
G5 P0 Q-3 X2 Y2
**It is an error if:**
* P and Q are not both specified
* Just one of I or J are specified
* I or J are unspecified in the first of a series of G5 commands
* An axis other than X or Y is specified
* The active plane is not G17
.. _g51-quadratic-spline:
G5.1 Quadratic Spline
---------------------
.. code:: text
G5.1 X- Y- I- J-
* ``I`` - X incremental offset from start point to control point
* ``J`` - Y incremental offset from start point to control point
G5.1 creates a quadratic B-spline in the XY plane with the X and Y axis only. Not specifying I or J
gives zero offset for the unspecified axis, so one or both must be given.
For example, to program a parabola, through the origin, from X-2 Y4 to X2 Y4:
G5.1 Sample quadratic spline
.. code:: text
G90 G17
G0 X-2 Y4
G5.1 X2 I2 J-8
**It is an error if:**
* both I and J offset are unspecified or zero
* An axis other than X or Y is specified
* The active plane is not G17
.. _g52-g53-nurbs-block:
G5.2 G5.3 NURBS Block
---------------------
.. code:: text
G5.2 <P-> <X- Y-> <L->
X- Y- <P->
...
G5.3
Warning: G5.2, G5.3 is experimental and not fully tested.
G5.2 is for opening the data block defining a NURBS and G5.3 for closing the data block. In the
lines between these two codes the curve control points are defined with both their related
``weights`` (P) and the parameter (L) which determines the order of the curve.
The current coordinate, before the first G5.2 command, is always taken as the first NURBS control
point. To set the weight for this first control point, first program G5.2 P- without giving any X Y.
The default weight if P is unspecified is 1. The default order if L is unspecified is 3.
G5.2 Example
.. code:: text
G0 X0 Y0 (rapid move)
F10 (set feed rate)
G5.2 P1 L3
X0 Y1 P1
X2 Y2 P1
X2 Y0 P1
X0 Y0 P2
G5.3
; The rapid moves show the same path without the NURBS Block
G0 X0 Y1
X2 Y2
X2 Y0
X0 Y0
M2
Sample NURBS Output
|Sample NURBS Output|
More information on NURBS can be found here: http://wiki.linuxcnc.org/cgi-bin/wiki.pl?NURBS
G7 Lathe Diameter Mode
----------------------
.. code:: text
G7
Program G7 to enter the diameter mode for axis X on a lathe. When in the diameter mode the X axis
moves on a lathe will be 1/2 the distance to the center of the lathe. For example X1 would move the
cutter to 0.500” from the center of the lathe thus giving a 1” diameter part.
G8 Lathe Radius Mode
--------------------
.. code:: text
G8
Program G8 to enter the radius mode for axis X on a lathe. When in Radius mode the X axis moves on a
lathe will be the distance from the center. Thus a cut at X1 would result in a part that is 2" in
diameter. G8 is default at power up.
G10 L1 Set Tool Table
---------------------
.. code:: text
G10 L1 P- axes <R- I- J- Q->
* ``P`` - tool number
* ``R`` - radius of tool
* ``I`` - front angle (lathe)
* ``J`` - back angle (lathe)
* ``Q`` - orientation (lathe)
G10 L1 sets the tool table for the ``P`` tool number to the values of the words.
A valid G10 L1 rewrites and reloads the tool table.
G10 L1 Example Line
.. code:: text
G10 L1 P1 Z1.5 (set tool 1 Z offset from the machine origin to 1.5)
G10 L1 P2 R0.015 Q3 (lathe example setting tool 2 radius to 0.015 and orientation to 3)
**It is an error if:**
* Cutter Compensation is on
* The P number is unspecified
* The P number is not a valid tool number from the tool table
* The P number is 0
For more information on cutter orientation used by the ``Q`` word, see the `Lathe Tool Orientation
<#lathe-tool-orientation>`__ diagram.
G10 L2 Set Coordinate System
----------------------------
.. code:: text
G10 L2 P- <axes R->
* ``P`` - coordinate system (0-9)
* ``R`` - rotation about the Z axis
G10 L2 offsets the origin of the axes in the coordinate system specified to the value of the axis
word. The offset is from the machine origin established during homing. The offset value will replace
any current offsets in effect for the coordinate system specified. Axis words not used will not be
changed.
Program P0 to P9 to specify which coordinate system to change.
======= ================= ======
P Value Coordinate System G code
======= ================= ======
0 Active n/a
1 1 G54
2 2 G55
3 3 G56
4 4 G57
5 5 G58
6 6 G59
7 7 G59.1
8 8 G59.2
9 9 G59.3
======= ================= ======
Optionally program R to indicate the rotation of the XY axis around the Z axis. The direction of
rotation is CCW as viewed from the positive end of the Z axis.
All axis words are optional.
Being in incremental distance mode (```G91`` <#gcode:g90-g91>`__) has no effect on ``G10 L2``.
Important Concepts:
* G10 L2 Pn does not change from the current coordinate system to the one specified by P, you have
to use G54-59.3 to select a coordinate system.
* When a rotation is in effect jogging an axis will only move that axis in a positive or negative
direction and not along the rotated axis.
* If a ``G52`` local offset or ``G92`` origin offset was in effect before ``G10 L2``, it will continue to
be in effect afterwards.
* When programming a coordinate system with R, any ``G52`` or ``G92`` will be applied **after** the
rotation.
* The coordinate system whose origin is set by a ``G10`` command may be active or inactive at the time
the ``G10`` is executed. If it is currently active, the new coordinates take effect immediately.
**It is an error if:**
* The P number does not evaluate to an integer in the range 0 to 9.
* An axis is programmed that is not defined in the configuration.
G10 L2 Example Line
.. code:: text
G10 L2 P1 X3.5 Y17.2
In the above example the origin of the first coordinate system (the one selected by ``G54``) is set to
be X=3.5 and Y=17.2. Because only X and Y are specified, the origin point is only moved in X and Y;
the other coordinates are not changed.
G10 L2 Example Line
.. code:: text
G10 L2 P1 X0 Y0 Z0 (clear offsets for X,Y & Z axes in coordinate system 1)
The above example sets the XYZ coordinates of the coordinate system 1 to the machine origin.
The coordinate system is described in the `Coordinate System <#cha:coordinate-system>`__ Section.
G10 L10 Set Tool Table
----------------------
.. code:: text
G10 L10 P- axes <R- I- J- Q->
* ``P`` - tool number
* ``R`` - radius of tool
* ``I`` - front angle (lathe)
* ``J`` - back angle (lathe)
* ``Q`` - orientation (lathe)
G10 L10 changes the tool table entry for tool P so that if the tool offset is reloaded, with the
machine in its current position and with the current G5x and G52/G92 offsets active, the current
coordinates for the given axes will become the given values. The axes that are not specified in the
G10 L10 command will not be changed. This could be useful with a probe move as described in the `G38
<#gcode:g38>`__ section.
G10 L10 Example
.. code:: text
T1 M6 G43 (load tool 1 and tool length offsets)
G10 L10 P1 Z1.5 (set the current position for Z to be 1.5)
G43 (reload the tool length offsets from the changed tool table)
M2 (end program)
* See `T <#sec:select-tool>`__ & `M6 <#mcode:m6>`__, and `G43 <#gcode:g43>`__ / `G43.1
<#gcode:g43.1>`__ sections for more information.
**It is an error if:**
* Cutter Compensation is on
* The P number is unspecified
* The P number is not a valid tool number from the tool table
* The P number is 0
G10 L11 Set Tool Table
----------------------
.. code:: text
G10 L11 P- axes <R- I- J- Q->
* ``P`` - tool number
* ``R`` - radius of tool
* ``I`` - front angle (lathe)
* ``J`` - back angle (lathe)
* ``Q`` - orientation (lathe)
G10 L11 is just like G10 L10 except that instead of setting the entry according to the current
offsets, it is set so that the current coordinates would become the given value if the new tool
offset is reloaded and the machine is placed in the G59.3 coordinate system without any G52/G92
offset active.
This allows the user to set the G59.3 coordinate system according to a fixed point on the machine,
and then use that fixture to measure tools without regard to other currently-active offsets.
**It is an error if:**
* Cutter Compensation is on
* The P number is unspecified
* The P number is not a valid tool number from the tool table
* The P number is 0
G10 L20 Set Coordinate System
-----------------------------
.. code:: text
G10 L20 P- axes
* ``P`` - coordinate system (0-9)
G10 L20 is similar to G10 L2 except that instead of setting the offset/entry to the given value, it
is set to a calculated value that makes the current coordinates become the given value.
G10 L20 Example Line
.. code:: text
G10 L20 P1 X1.5 (set the X axis current location in coordinate system 1 to 1.5)
**It is an error if:**
* The P number does not evaluate to an integer in the range 0 to 9.
* An axis is programmed that is not defined in the configuration.
.. _g17---g191-plane-select:
G17 - G19.1 Plane Select
------------------------
These codes set the current plane as follows:
* ``G17`` - XY (default)
* ``G18`` - ZX
* ``G19`` - YZ
* ``G17.1`` - UV
* ``G18.1`` - WU
* ``G19.1`` - VW
The UV, WU and VW planes do not support arcs.
It is a good idea to include a plane selection in the preamble of each G code file.
The effects of having a plane selected are discussed in Section `G2 G3 Arcs <#gcode:g2-g3>`__ and
Section `G81 G89 <#gcode:g80-g89>`__
G20, G21 Units
--------------
* ``G20`` - to use inches for length units.
* ``G21`` - to use millimeters for length units.
It is a good idea to include units in the preamble of each G code file.
.. _g28-g281-goset-predefined-position:
G28, G28.1 Go/Set Predefined Position
-------------------------------------
G28 uses the values stored in `parameters <#sub:numbered-parameters>`__ 5161-5169 as the X Y Z A B C
U V W final point to move to. The parameter values are ``absolute`` machine coordinates in the native
machine ``units`` as specified in the ini file. All axes defined in the ini file will be moved when a
G28 is issued. If no positions are stored with G28.1 then all axes will go to the `machine origin
<#sec.machine-corrdinate-system>`__.
* ``G28`` - makes a `rapid move <#gcode:g0>`__ from the current position to the ``absolute``
position of the values in parameters 5161-5166.
* ``G28 axes`` - makes a rapid move to the position specified by ``axes`` including any offsets,
then will make a rapid move to the ``absolute`` position of the values in parameters 5161-5166 for
all ``axes`` specified. Any ``axis`` not specified will not move.
* ``G28.1`` - stores the current ``absolute`` position into parameters 5161-5166.
G28 Example Line
.. code:: text
G28 Z2.5 (rapid to Z2.5 then to Z location specified in #5163)
It is an error if :
* Cutter Compensation is turned on
.. _g30-g301-goset-predefined-position:
G30, G30.1 Go/Set Predefined Position
-------------------------------------
G30 functions the same as G28 but uses the values stored in `parameters
<#sub:numbered-parameters>`__ 5181-5189 as the X Y Z A B C U V W final point to move to. The
parameter values are ``absolute`` machine coordinates in the native machine ``units`` as specified in
the ini file. All axes defined in the ini file will be moved when a G30 is issued. If no positions
are stored with G30.1 then all axes will go to the `machine origin
<#sec.machine-corrdinate-system>`__.
* ``G30`` - makes a `rapid move <#gcode:g0>`__ from the current position to the ``absolute``
position of the values in parameters 5181-5186.
* ``G30 axes`` - makes a rapid move to the position specified by ``axes`` including any offsets,
then will make a rapid move to the ``absolute`` position of the values in parameters 5181-5186 for
all ``axes`` specified. Any ``axis`` not specified will not move.
* ``G30.1`` - stores the current absolute position into parameters 5181-5186.
G30 Example Line
.. code:: text
G30 Z2.5 (rapid to Z2.5 then to the Z location specified in #5i83)
It is an error if :
* Cutter Compensation is turned on
G33 Spindle Synchronized Motion
-------------------------------
.. code:: text
G33 X- Y- Z- K- $-
* ``K`` - distance per revolution
For spindle-synchronized motion in one direction, code ``G33 X- Y- Z- K-`` where K gives the distance
moved in XYZ for each revolution of the spindle. For instance, if starting at ``Z=0``, ``G33 Z-1
K.0625`` produces a 1 inch motion in Z over 16 revolutions of the spindle. This command might be part
of a program to produce a 16TPI thread. Another example in metric, ``G33 Z-15 K1.5`` produces a
movement of 15mm while the spindle rotates 10 times for a thread of 1.5mm.
The (optional) $ argument sets which spindle the motion is synchronised to (default is zero). For
example G33 Z10 K1 $1 will move the spindle in synchrony with the spindle.N.revs HAL pin value.
Spindle-synchronized motion waits for the spindle index and spindle at speed pins, so multiple
passes line up. ``G33`` moves end at the programmed endpoint. G33 could be used to cut tapered threads
or a fusee.
All the axis words are optional, except that at least one must be used.
Technical Info
At the beginning of each G33 pass, LinuxCNC uses the spindle speed and the machine acceleration
limits to calculate how long it will take Z to accelerate after the index pulse, and determines how
many degrees the spindle will rotate during that time. It then adds that angle to the index position
and computes the Z position using the corrected spindle angle. That means that Z will reach the
correct position just as it finishes accelerating to the proper speed, and can immediately begin
cutting a good thread.
HAL Connections
The pin ``spindle.N.at-speed`` must be set or driven true for the motion to start. Additionally
spindle.N.revs must increase by 1 for each revolution of the spindle and the spindle.N.index-enable
pin must be connected to an encoder (or resolver) counter which resets index-enable once per rev.
See the Integrators Manual for more information on spindle synchronized motion.
G33 Example
.. code:: text
G90 (absolute distance mode)
G0 X1 Z0.1 (rapid to position)
S100 M3 (start spindle turning)
G33 Z-2 K0.125 (move Z axis to -2 at a rate to equal 0.125 per revolution)
G0 X1.25 (rapid move tool away from work)
Z0.1 (rapid move to starting Z position)
M2 (end program)
* See `G90 <#gcode:g90-g91>`__ & `G0 <#gcode:g0>`__ & `M2 <#mcode:m2-m30>`__ sections for more
information.
**It is an error if:**
* All axis words are omitted.
* The spindle is not turning when this command is executed
* The requested linear motion exceeds machine velocity limits due to the spindle speed
.. _g331-rigid-tapping:
G33.1 Rigid Tapping
-------------------
.. code:: text
G33.1 X- Y- Z- K- I- $-
* ``K`` - distance per revolution
* ``I`` - optional spindle speed multiplier for faster return move
* ``$`` - optional spindle selector
For rigid tapping (spindle synchronized motion with return), code ``G33.1 X- Y- Z- K-`` where ``K-``
gives the distance moved for each revolution of the spindle.
A rigid tapping move consists of the following sequence:
#. A move from the current coordinate to the specified coordinate, synchronized with the selected
spindle at the given ratio and starting from the current coordinate with a spindle index pulse.
#. When reaching the endpoint, a command to reverse the spindle, and speed up by a factor set by the
multiplier (e.g., from clockwise to counterclockwise).
#. Continued synchronized motion beyond the specified end coordinate until the spindle actually
stops and reverses.
#. Continued synchronized motion back to the original coordinate.
#. When reaching the original coordinate, a command to reverse the spindle a second time (e.g., from
counterclockwise to clockwise).
#. Continued synchronized motion beyond the original coordinate until the spindle actually stops and
reverses.
#. An **unsynchronized** move back to the original coordinate.
Spindle-synchronized motions wait for spindle index, so multiple passes line up.``G33.1`` moves end at
the original coordinate.
All the axis words are optional, except that at least one must be used.
G33.1 Example
.. code:: text
G90 (set absolute mode)
G0 X1.000 Y1.000 Z0.100 (rapid move to starting position)
S100 M3 (turn on the spindle, 100 RPM)
G33.1 Z-0.750 K0.05 (rigid tap a 20 TPI thread 0.750 deep)
M2 (end program)
* See `G90 <#gcode:g90-g91>`__ & `G0 <#gcode:g0>`__ & `M2 <#mcode:m2-m30>`__ sections for more
information.
**It is an error if:**
* All axis words are omitted.
* The spindle is not turning when this command is executed
* The requested linear motion exceeds machine velocity limits due to the spindle speed
.. _g38n-straight-probe:
G38.n Straight Probe
--------------------
.. code:: text
G38.n axes
* ``G38.2`` - probe toward workpiece, stop on contact, signal error if failure
* ``G38.3`` - probe toward workpiece, stop on contact
* ``G38.4`` - probe away from workpiece, stop on loss of contact, signal error if failure
* ``G38.5`` - probe away from workpiece, stop on loss of contact
Program ``G38.n axes`` to perform a straight probe operation. The axis words are optional, except that
at least one of them must be used. The axis words together define the destination point that the
probe will move towards, starting from the current location. If the probe is not tripped before the
destination is reached G38.2 and G38.4 will signal an error.
The tool in the spindle must be a probe or contact a probe switch.
In response to this command, the machine moves the controlled point (which should be at the center
of the probe ball) in a straight line at the current `feed rate <#sec:set-feed-rate>`__ toward the
programmed point. In inverse time feed mode, the feed rate is such that the whole motion from the
current point to the programmed point would take the specified time. The move stops (within machine
acceleration limits) when the programmed point is reached, or when the requested change in the probe
input takes place, whichever occurs first.
After successful probing, parameters #5061 to #5069 will be set to the X, Y, Z, A, B, C, U, V, W
coordinates of the location of the controlled point at the time the probe changed state (in the
current work coordinate system). After unsuccessful probing, they are set to the coordinates of the
programmed point. Parameter 5070 is set to 1 if the probe succeeded and 0 if the probe failed. If
the probing operation failed, G38.2 and G38.4 will signal an error by posting an message on screen
if the selected GUI supports that. And by halting program execution.
A comment of the form ``(PROBEOPEN filename.txt)`` will open ``filename.txt`` and store the 9-number
coordinate consisting of XYZABCUVW of each successful straight probe in it. The file must be closed
with ``(PROBECLOSE)``. For more information see the `Comments <#gcode:comments>`__ Section.
An example file ``smartprobe.ngc`` is included (in the examples directory) to demonstrate using probe
moves to log to a file the coordinates of a part. The program ``smartprobe.ngc`` could be used with
``ngcgui`` with minimal changes.
**It is an error if:**
* the current point is the same as the programmed point.
* no axis word is used
* cutter compensation is enabled
* the feed rate is zero
* the probe is already in the target state
G40 Compensation Off
--------------------
* ``G40`` - turn cutter compensation off. If tool compensation was on the next move must be a linear
move and longer than the tool diameter. It is OK to turn compensation off when it is already off.
G40 Example
.. code:: text
; current location is X1 after finishing cutter compensated move
G40 (turn compensation off)
G0 X1.6 (linear move longer than current cutter diameter)
M2 (end program)
See `G0 <#gcode:g0>`__ & `M2 <#mcode:m2-m30>`__ sections for more information.
**It is an error if:**
* A G2/G3 arc move is programmed next after a G40.
* The linear move after turning compensation off is less than the tool diameter.
G41, G42 Cutter Compensation
----------------------------
.. code:: text
G41 <D-> (left of programmed path)
G42 <D-> (right of programmed path)
* ``D`` - tool number
The D word is optional; if there is no D word the radius of the currently loaded tool will be used
(if no tool is loaded and no D word is given, a radius of 0 will be used).
If supplied, the D word is the tool number to use. This would normally be the number of the tool in
the spindle (in which case the D word is redundant and need not be supplied), but it may be any
valid tool number.
To start cutter compensation to the left of the part profile, use G41. G41 starts cutter
compensation to the left of the programmed line as viewed from the positive end of the axis
perpendicular to the plane.
To start cutter compensation to the right of the part profile, use G42. G42 starts cutter
compensation to the right of the programmed line as viewed from the positive end of the axis
perpendicular to the plane.
The lead in move must be at least as long as the tool radius. The lead in move can be a rapid move.
Cutter compensation may be performed if the XY-plane or XZ-plane is active.
User M100-M199 commands are allowed when Cutter Compensation is on.
The behavior of the machining center when cutter compensation is on is described in the `Cutter
Compensation <#sec:cutter-compensation>`__ Section along with code examples.
**It is an error if:**
* The D number is not a valid tool number or 0.
* The YZ plane is active.
* Cutter compensation is commanded to turn on when it is already on.
.. _g411-g421-dynamic-cutter-compensation:
G41.1, G42.1 Dynamic Cutter Compensation
----------------------------------------
.. code:: text
G41.1 D- <L-> (left of programmed path)
G42.1 D- <L-> (right of programmed path)
* ``D`` - cutter diameter
* ``L`` - tool orientation (see `lathe tool orientation <#lathe-tool-orientation>`__)
G41.1 & G42.1 function the same as G41 & G42 with the added scope of being able to program the tool
diameter. The L word defaults to 0 if unspecified.
**It is an error if:**
* The YZ plane is active.
* The L number is not in the range from 0 to 9 inclusive.
* The L number is used when the XZ plane is not active.
* Cutter compensation is commanded to turn on when it is already on.
G43 Tool Length Offset
----------------------
.. code:: text
G43 <H->
* ``H`` - tool number (optional)
G43 enables tool length compensation. G43 changes subsequent motions by offsetting the axis
coordinates by the length of the offset. G43 does not cause any motion. The next time a compensated
axis is moved, that axis’s endpoint is the compensated location.
``G43`` without an H word uses the currently loaded tool from the last ``Tn M6``.
``G43 Hn`` uses the offset for tool n.
G43 H- Example Line
.. code:: text
G43 H1 (set tool offsets using the values from tool 1 in the tool table)
**It is an error if:**
* the H number is not an integer, or
* the H number is negative, or
* the H number is not a valid tool number (though note that 0 is a valid tool number on nonrandom
tool changer machines, it means "the tool currently in the spindle")
.. _g431-dynamic-tool-length-offset:
G43.1: Dynamic Tool Length Offset
---------------------------------
.. code:: text
G43.1 axes
* ``G43.1 axes`` - change subsequent motions by replacing the current offset(s) of axes. G43.1 does
not cause any motion. The next time a compensated axis is moved, that axis’s endpoint is the
compensated location.
G43.1 Example
.. code:: text
G90 (set absolute mode)
T1 M6 G43 (load tool 1 and tool length offsets, Z is at machine 0 and DRO shows Z1.500)
G43.1 Z0.250 (offset current tool offset by 0.250, DRO now shows Z1.250)
M2 (end program)
* See `G90 <#gcode:g90-g91>`__ & `T <#sec:select-tool>`__ & `M6 <#mcode:m6>`__ sections for more
information.
**It is an error if:**
* motion is commanded on the same line as ``G43.1``
.. _g432-apply-additional-tool-length-offset:
G43.2: Apply additional Tool Length Offset
------------------------------------------
.. code:: text
G43.2 H-
* ``H`` - tool number
G43.2 applies an additional simultaneous tool offset.
G43.2 Example
.. code:: text
G90 (set absolute mode)
T1 M6 (load tool 1)
G43 (or G43 H1 - replace all tool offsets with T1``s offset)
G43.2 H10 (also add in T10``s tool offset)
M2 (end program)
You can sum together an arbitrary number of offsets by calling G43.2 more times. There are no
built-in assumptions about which numbers are geometry offsets and which are wear offsets, or that
you should have only one of each.
Like the other G43 commands, G43.2 does not cause any motion. The next time a compensated axis is
moved, that axis’s endpoint is the compensated location.
**It is an error if:**
* ``H`` is unspecified, or
* the given tool number does not exist in the tool table
G49: Cancel Tool Length Compensation
------------------------------------
* ``G49`` - cancels tool length compensation
It is OK to program using the same offset already in use. It is also OK to program using no tool
length offset if none is currently being used.
G53 Move in Machine Coordinates
-------------------------------
.. code:: text
G53 axes
To move in the `machine coordinate system <#sec.machine-corrdinate-system>`__, program ``G53`` on the
same line as a linear move. ``G53`` is not modal and must be programmed on each line. ``G0`` or ``G1``
does not have to be programmed on the same line if one is currently active.
For example ``G53 G0 X0 Y0 Z0`` will move the axes to the home position even if the currently selected
coordinate system has offsets in effect.
G53 Example
.. code:: text
G53 G0 X0 Y0 Z0 (rapid linear move to the machine origin)
G53 X2 (rapid linear move to absolute coordinate X2)
* See `G0 <#gcode:g0>`__ section for more information.
**It is an error if:**
* G53 is used without G0 or G1 being active,
* or G53 is used while cutter compensation is on.
.. _g54-g593-select-coordinate-system:
G54-G59.3 Select Coordinate System
----------------------------------
* ``G54`` - select coordinate system 1
* ``G55`` - select coordinate system 2
* ``G56`` - select coordinate system 3
* ``G57`` - select coordinate system 4
* ``G58`` - select coordinate system 5
* ``G59`` - select coordinate system 6
* ``G59.1`` - select coordinate system 7
* ``G59.2`` - select coordinate system 8
* ``G59.3`` - select coordinate system 9
The coordinate systems store the axis values and the XY rotation angle
around the Z axis in the parameters shown in the following table.
====== == ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
Select CS X Y Z A B C U V W R
====== == ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
G54 1 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230
G55 2 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250
G56 3 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270
G57 4 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290
G58 5 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310
G59 6 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330
G59.1 7 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350
G59.2 8 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370
G59.3 9 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390
====== == ==== ==== ==== ==== ==== ==== ==== ==== ==== ====
**It is an error if:**
* selecting a coordinate system is used while cutter compensation is on.
See the `Coordinate System <#cha:coordinate-system>`__ Section for an overview of coordinate
systems.
.. _g61-g611-exact-path-mode:
G61, G61.1 Exact Path Mode
--------------------------
* ``G61`` - Exact path mode, movement exactly as programed. Moves will slow or stop as needed to
reach every programed point. If two sequential moves are exactly co-linear movement will not stop.
* ``G61.1`` - Exact stop mode, movement will stop at the end of each programed segment.
G64 Path Blending
-----------------
.. code:: text
G64 <P- <Q->>
* ``P`` - motion blending tolerance
* ``Q`` - naive cam tolerance
* ``G64`` - best possible speed.
* ``G64 P- <Q- >`` blending with tolerance.
* ``G64`` - without P means to keep the best speed possible, no matter how far away from the
programmed point you end up.
* ``G64 P- Q-`` - is a way to fine tune your system for best compromise between speed and
accuracy. The P- tolerance means that the actual path will be no more than P- away from the
programmed endpoint. The velocity will be reduced if needed to maintain the path. In addition,
when you activate G64 P- Q- it turns on the ``naive cam detector``; when there are a series of
linear XYZ feed moves at the same `feed rate <#sec:set-feed-rate>`__ that are less than Q- away
from being collinear, they are collapsed into a single linear move. On G2/G3 moves in the G17 (XY)
plane when the maximum deviation of an arc from a straight line is less than the G64 P- tolerance
the arc is broken into two lines (from start of arc to midpoint, and from midpoint to end). those
lines are then subject to the naive cam algorithm for lines. Thus, line-arc, arc-arc, and arc-line
cases as well as line-line benefit from the ``naive cam detector``. This improves contouring
performance by simplifying the path. It is OK to program for the mode that is already active. See
also the `Trajectory Control <#sec:trajectory-control>`__ Section for more information on these
modes. If Q is not specified then it will have the same behavior as before and use the value of
P-.
G64 P- Example Line
.. code:: text
G64 P0.015 (set path following to be within 0.015 of the actual path)
It is a good idea to include a path control specification in the preamble of each G code file.
G73 Drilling Cycle with Chip Breaking
-------------------------------------
.. code:: text
G73 X- Y- Z- R- Q- <L->
* ``R`` - retract position along the Z axis.
* ``Q`` - delta increment along the Z axis.
* ``L`` - repeat
The ``G73`` cycle is drilling or milling with chip breaking. This cycle takes a Q number which
represents a ``delta`` increment along the Z axis.
#. Preliminary motion.
* If the current Z position is below the R position, The Z axis does a `rapid move <#gcode:g0>`__
to the R position.
* Move to the X Y coordinates
#. Move the Z-axis only at the current `feed rate <#sec:set-feed-rate>`__ downward by delta or to
the Z position, whichever is less deep.
#. Rapid up a bit.
#. Repeat steps 2 and 3 until the Z position is reached at step 2.
#. The Z axis does a rapid move to the R position.
**It is an error if:**
* the Q number is negative or zero.
* the R number is not specified
G74 Left-hand Tapping Cycle, Dwell
----------------------------------
.. code:: text
G74 (X- Y- Z-) or (U- V- W-) R- L- P- $-
The ``G74`` cycle is intended for tapping with floating chuck and dwell at the bottom of the hole.
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Disable Feed and Speed Overrides.
#. Move the Z-axis at the current feed rate to the Z position.
#. Stop the selected spindle (chosen by the $ parameter)
#. Start spindle rotation clockwise.
#. Dwell for the P number of seconds.
#. Move the Z-axis at the current feed rate to clear Z
#. Restore Feed and Speed override enables to previous state
The length of the dwell is specified by a ``P-`` word in the G84 block. Thread pitch is F divided
by S. In example S100 F125 gives pitch of 1.25MM per revolution.
G76 Threading Cycle
-------------------
.. code:: text
G76 P- Z- I- J- R- K- Q- H- E- L- $-
|G76 Threading|
Figure 3. G76 Threading
* ``Drive Line`` - A line through the initial X position parallel to the Z.
* ``P-`` - The ``thread pitch`` in distance per revolution.
* ``Z-`` - The final position of threads. At the end of the cycle the tool will be at this Z
position.
* ``I-`` - The ``thread peak`` offset from the ``drive line``. Negative ``I`` values are external
threads, and positive ``I`` values are internal threads. Generally the material has been turned to
this size before the ``G76`` cycle.
* ``J-`` - A positive value specifying the ``initial cut depth``. The first threading cut will be
``J`` beyond the ``thread peak`` position.
* ``K-`` - A positive value specifying the ``full thread depth``. The final threading cut will be
``K`` beyond the ``thread peak`` position.
Optional settings
* ``$-`` - The spindle number to which the motion will be synchronised (default 0). For example is
$1 is programmed then the motion will begin on the reset od spindle.1.index-enable and proceed in
synchrony with the value of spindle.1.revs
* ``R-`` - The ``depth degression``. ``R1.0`` selects constant depth on successive threading
passes. ``R2.0`` selects constant area. Values between 1.0 and 2.0 select decreasing depth but
increasing area. Values above 2.0 select decreasing area. Beware that unnecessarily high
degression values will cause a large number of passes to be used. (degression = a descent by
stages or steps.)
* ``Q-`` - The ``compound slide angle`` is the angle (in degrees) describing to what extent
successive passes should be offset along the drive line. This is used to cause one side of the
tool to remove more material than the other. A positive ``Q`` value causes the leading edge of the
tool to cut more heavily. Typical values are 29, 29.5 or 30.
* ``H-`` - The number of ``spring passes``. Spring passes are additional passes at full thread
depth. If no additional passes are desired, program ``H0``.
* ``E-`` - Specifies the distance along the drive line used for the taper. The angle of the taper
will be so the last pass tapers to the thread crest over the distance specified with E.`` E0.2``
will give a taper for the first/last 0.2 length units along the thread. For a 45 degree taper
program E the same as K
* ``L-`` - Specifies which ends of the thread get the taper. Program ``L0`` for no taper (the
default), ``L1`` for entry taper, ``L2`` for exit taper, or ``L3`` for both entry and exit
tapers. Entry tapers will pause at the drive line to synchronize with the index pulse then move at
the `feed rate <#sec:set-feed-rate>`__ in to the beginning of the taper. No entry taper and the
tool will rapid to the cut depth then synchronize and begin the cut.
The tool is moved to the initial X and Z positions prior to issuing the G76. The X position is the
``drive line`` and the Z position is the start of the threads.
The tool will pause briefly for synchronization before each threading pass, so a relief groove will
be required at the entry unless the beginning of the thread is past the end of the material or an
entry taper is used.
Unless using an exit taper, the exit move is not synchronized to the spindle speed and will be a
`rapid move <#gcode:g0>`__. With a slow spindle, the exit move might take only a small fraction of a
revolution. If the spindle speed is increased after several passes are complete, subsequent exit
moves will require a larger portion of a revolution, resulting in a very heavy cut during the exit
move. This can be avoided by providing a relief groove at the exit, or by not changing the spindle
speed while threading.
The final position of the tool will be at the end of the ``drive line``. A safe Z move will be needed
with an internal thread to remove the tool from the hole.
**It is an error if:**
* The active plane is not the ZX plane
* Other axis words, such as X- or Y-, are specified
* The ``R-`` degression value is less than 1.0.
* All the required words are not specified
* ``P-``, ``J-``, ``K-`` or ``H-`` is negative
* ``E-`` is greater than half the drive line length
HAL Connections
The pins ``spindle.N.at-speed`` and the ``encoder.n.phase-Z`` for the spindle must be connected in your
HAL file before G76 will work. See the `spindle <#sec:motion-pins>`__ pins in the Motion section for
more information.
Technical Info
The G76 canned cycle is based on the G33 Spindle Synchronized Motion. For more information see the
G33 `Technical Info <#gcode:g33-tech-info>`__.
The sample program ``g76.ngc`` shows the use of the G76 canned cycle, and can be previewed and
executed on any machine using the ``sim/lathe.ini`` configuration.
G76 Example
.. code:: text
G0 Z-0.5 X0.2
G76 P0.05 Z-1 I-.075 J0.008 K0.045 Q29.5 L2 E0.045
In the figure the tool is in the final position after the G76 cycle is completed. You can see the
entry path on the right from the Q29.5 and the exit path on the left from the L2 E0.045. The white
lines are the cutting moves.
|G76 Example|
Figure 4. G76 Example
Canned Cycles
-------------
The canned cycles ``G81`` through ``G89`` and the canned cycle stop ``G80``
are described in this section.
All canned cycles are performed with respect to the currently-selected plane. Any of the nine planes
may be selected. Throughout this section, most of the descriptions assume the XY-plane has been
selected. The behavior is analogous if another plane is selected, and the correct words must be
used. For instance, in the ``G17.1`` plane, the action of the canned cycle is along W, and the
locations or increments are given with U and V. In this case substitute U,V,W for X,Y,Z in the
instructions below.
Rotary axis words are not allowed in canned cycles. When the active plane is one of the XYZ family,
the UVW axis words are not allowed. Likewise, when the active plane is one of the UVW family, the
XYZ axis words are not allowed.
Common Words
~~~~~~~~~~~~
All canned cycles use X, Y, Z, or U, V, W groups depending on the plane selected and R words. The R
(usually meaning retract) position is along the axis perpendicular to the currently selected plane
(Z-axis for XY-plane, etc.) Some canned cycles use additional arguments.
Sticky Words
~~~~~~~~~~~~
For canned cycles, we will call a number ``sticky`` if, when the same cycle is used on several lines
of code in a row, the number must be used the first time, but is optional on the rest of the
lines. Sticky numbers keep their value on the rest of the lines if they are not explicitly
programmed to be different. The R number is always sticky.
In incremental distance mode X, Y, and R numbers are treated as increments from the current position
and Z as an increment from the Z-axis position before the move involving Z takes place. In absolute
distance mode, the X, Y, R, and Z numbers are absolute positions in the current coordinate system.
Repeat Cycle
~~~~~~~~~~~~
The L number is optional and represents the number of repeats. L=0 is not allowed. If the repeat
feature is used, it is normally used in incremental distance mode, so that the same sequence of
motions is repeated in several equally spaced places along a straight line. When L- is greater than
1 in incremental mode with the XY-plane selected, the X and Y positions are determined by adding the
given X and Y numbers either to the current X and Y positions (on the first go-around) or to the X
and Y positions at the end of the previous go-around (on the repetitions). Thus, if you program
``L10`` , you will get 10 cycles. The first cycle will be distance X,Y from the original location. The
R and Z positions do not change during the repeats. The L number is not sticky. In absolute
distance mode, L>1 means ``do the same cycle in the same place several times``, Omitting the L word is
equivalent to specifying L=1.
Retract Mode
~~~~~~~~~~~~
The height of the retract move at the end of each repeat (called ``clear Z`` in the descriptions
below) is determined by the setting of the retract mode: either to the original Z position (if that
is above the R position and the retract mode is ``G98``, OLD_Z), or otherwise to the R position. See
the `G98 G99 <#gcode:g98-g99>`__ Section.
Canned Cycle Errors
~~~~~~~~~~~~~~~~~~~
**It is an error if:**
* axis words are all missing during a canned cycle,
* axis words from different groups (XYZ) (UVW) are used together,
* a P number is required and a negative P number is used,
* an L number is used that does not evaluate to a positive integer,
* rotary axis motion is used during a canned cycle,
* inverse time feed rate is active during a canned cycle,
* or cutter compensation is active during a canned cycle.
If the XY plane is active, the Z number is sticky, and it is an error if:
* the Z number is missing and the same canned cycle was not already active,
* or the R number is less than the Z number.
If other planes are active, the error conditions are analogous to the XY conditions above.
Preliminary and In-Between Motion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Preliminary motion is a set of motions that is common to all of the milling canned cycles. If the
current Z position is below the R position, the Z axis does a `rapid move <#gcode:g0>`__ to the R
position. This happens only once, regardless of the value of L.
In addition, at the beginning of the first cycle and each repeat, the following one or two moves are
made
#. A `rapid move <#gcode:g0>`__ parallel to the XY-plane to the given XY-position,
#. The Z-axis make a rapid move to the R position, if it is not already at the R position.
If another plane is active, the preliminary and in-between motions are analogous.
Why use a canned cycle?
~~~~~~~~~~~~~~~~~~~~~~~
There are at least two reasons for using canned cycles. The first is the economy of code. A single
bore would take several lines of code to execute.
The G81 `Example 1 <#gcode:g81-example>`__ demonstrates how a canned cycle could be used to produce
8 holes with ten lines of G code within the canned cycle mode. The program below will produce the
same set of 8 holes using five lines for the canned cycle. It does not follow exactly the same path
nor does it drill in the same order as the earlier example. But the program writing economy of a
good canned cycle should be obvious.
Eight Holes
.. code:: text
N100 G90 G0 X0 Y0 Z0 (move coordinate home)
N110 G1 F10 X0 G4 P0.1
N120 G91 G81 X1 Y0 Z-1 R1 L4(canned drill cycle)
N130 G90 G0 X0 Y1
N140 Z0
N150 G91 G81 X1 Y0 Z-0.5 R1 L4(canned drill cycle)
N160 G80 (turn off canned cycle)
N170 M2 (program end)
The G98 to the second line above means that the return move will be to the value of Z in the first
line since it is higher that the R value specified.
|eight|
Twelve Holes in a Square
This example demonstrates the use of the L word to repeat a set of incremental drill cycles for
successive blocks of code within the same G81 motion mode. Here we produce 12 holes using five lines
of code in the canned motion mode.
.. code:: text
N1000 G90 G0 X0 Y0 Z0 (move coordinate home)
N1010 G1 F50 X0 G4 P0.1
N1020 G91 G81 X1 Y0 Z-0.5 R1 L4 (canned drill cycle)
N1030 X0 Y1 R0 L3 (repeat)
N1040 X-1 Y0 L3 (repeat)
N1050 X0 Y-1 L2 (repeat)
N1060 G80 (turn off canned cycle)
N1070 G90 G0 X0 (rapid move home)
N1080 Y0
N1090 Z0
N1100 M2 (program end)
|twelve|
The second reason to use a canned cycle is that they all produce
preliminary moves and returns that you can anticipate and control
regardless of the start point of the canned cycle.
G80 Cancel Canned Cycle
-----------------------
* ``G80`` - cancel canned cycle modal motion. ``G80`` is part of modal group 1, so programming any other
G code from modal group 1 will also cancel the canned cycle.
**It is an error if:**
* Axis words are programmed when G80 is active.
G80 Example
.. code:: text
G90 G81 X1 Y1 Z1.5 R2.8 (absolute distance canned cycle)
G80 (turn off canned cycle motion)
G0 X0 Y0 Z0 (rapid move to coordinate home)
The following code produces the same final position and machine state as the previous code.
G0 Example
.. code:: text
G90 G81 X1 Y1 Z1.5 R2.8 (absolute distance canned cycle)
G0 X0 Y0 Z0 (rapid move to coordinate home)
The advantage of the first set is that, the G80 line clearly turns off the G81 canned cycle. With
the first set of blocks, the programmer must turn motion back on with G0, as is done in the next
line, or any other motion mode G word.
If a canned cycle is not turned off with G80 or another motion word, the canned cycle will attempt
to repeat itself using the next block of code that contains an X, Y, or Z word. The following file
drills (G81) a set of eight holes as shown in the following caption.
G80 Example 1
.. code:: text
N100 G90 G0 X0 Y0 Z0 (coordinate home)
N110 G1 X0 G4 P0.1
N120 G81 X1 Y0 Z0 R1 (canned drill cycle)
N130 X2
N140 X3
N150 X4
N160 Y1 Z0.5
N170 X3
N180 X2
N190 X1
N200 G80 (turn off canned cycle)
N210 G0 X0 (rapid move home)
N220 Y0
N230 Z0
N240 M2 (program end)
|G80 Cycle|
Figure 5. G80 Cycle
The use of G80 in line N200 is optional because the G0 on the next line will turn off the G81
cycle. But using the G80 as shown in Example 1, will provide for easier to read canned
cycle. Without it, it is not so obvious that all of the blocks between N120 and N200 belong to the
canned cycle.
G81 Drilling Cycle
------------------
.. code:: text
G81 (X- Y- Z-) or (U- V- W-) R- L-
The ``G81`` cycle is intended for drilling.
The cycle functions as follows:
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Move the Z-axis at the current `feed rate <#sec:set-feed-rate>`__ to the Z position.
#. The Z-axis does a `rapid move <#gcode:g0>`__ to clear Z.
Example 1 - Absolute Position G81
Suppose the current position is (X1, Y2, Z3) and the following line of NC code is interpreted.
.. code:: text
G90 G98 G81 X4 Y5 Z1.5 R2.8
This calls for absolute distance mode (G90) and OLD_Z retract mode (G98)
and calls for the G81 drilling cycle to be performed once.
The X value and X position are 4.
The Y value and Y position are 5.
The Z value and Z position are 1.5.
The R value and clear Z are 2.8. OLD_Z is 3.
The following moves take place:
#. a `rapid move <#gcode:g0>`__ parallel to the XY plane to (X4, Y5)
#. a rapid move move parallel to the Z-axis to (Z2.8).
#. move parallel to the Z-axis at the `feed rate <#sec:set-feed-rate>`__ to (Z1.5)
#. a rapid move parallel to the Z-axis to (Z3)
|G81ex1|
Example 2 - Relative Position G81
Suppose the current position is (X1, Y2, Z3) and the following line of NC code is interpreted.
.. code:: text
G91 G98 G81 X4 Y5 Z-0.6 R1.8 L3
This calls for incremental distance mode (G91) and OLD_Z retract mode (G98). It also calls for the
G81 drilling cycle to be repeated three times. The X value is 4, the Y value is 5, the Z value is
-0.6 and the R value is 1.8. The initial X position is 5 (=1+4), the initial Y position is 7 (=2+5),
the clear Z position is 4.8 (=1.8+3), and the Z position is 4.2 (=4.8-0.6). OLD_Z is 3.
The first preliminary move is a maximum rapid move along the Z axis to (X1,Y2,Z4.8), since OLD_Z <
clear Z.
The first repeat consists of 3 moves.
#. a `rapid move <#gcode:g0>`__ parallel to the XY-plane to (X5, Y7)
#. move parallel to the Z-axis at the `feed rate <#sec:set-feed-rate>`__ to (Z4.2)
#. a rapid move parallel to the Z-axis to (X5, Y7, Z4.8)
The second repeat consists of 3 moves. The X position is reset to 9 (=5+4) and the Y position to 12
(=7+5).
#. a `rapid move <#gcode:g0>`__ parallel to the XY-plane to (X9, Y12, Z4.8)
#. move parallel to the Z-axis at the feed rate to (X9, Y12, Z4.2)
#. a rapid move parallel to the Z-axis to (X9, Y12, Z4.8)
The third repeat consists of 3 moves. The X position is reset to 13 (=9+4) and the Y position to 17
(=12+5).
#. a `rapid move <#gcode:g0>`__ parallel to the XY-plane to (X13, Y17, Z4.8)
#. move parallel to the Z-axis at the feed rate to (X13, Y17, Z4.2)
#. a rapid move parallel to the Z-axis to (X13, Y17, Z4.8)
|G81ex2|
Example 3 - Relative Position G81
Now suppose that you execute the first G81 block of code but from (X0, Y0, Z0) rather than from (X1,
Y2, Z3).
.. code:: text
G90 G98 G81 X4 Y5 Z1.5 R2.8
Since OLD_Z is below the R value, it adds nothing for the motion but since the initial value of Z is
less than the value specified in R, there will be an initial Z move during the preliminary moves.
|G81|
Example 4 - Absolute G81 R > Z
This is a plot of the path of motion for the second g81 block of code.
.. code:: text
G91 G98 G81 X4 Y5 Z-0.6 R1.8 L3
Since this plot starts with (X0, Y0, Z0), the interpreter adds the initial Z0 and R1.8 and rapid
moves to that location. After that initial Z move, the repeat feature works the same as it did in
example 3 with the final Z depth being 0.6 below the R value.
|G81a|
Example 5 - Relative position R > Z
.. code:: text
G90 G98 G81 X4 Y5 Z-0.6 R1.8
Since this plot starts with (X0, Y0, Z0), the interpreter adds the initial Z0 and R1.8 and rapid
moves to that location as in ``Example 4``. After that initial Z move, the `rapid move <#gcode:g0>`__
to X4 Y5 is done. Then the final Z depth being 0.6 below the R value. The repeat function would make
the Z move in the same location again.
G82 Drilling Cycle, Dwell
-------------------------
.. code:: text
G82 (X- Y- Z-) or (U- V- W-) R- L- P-
The ``G82`` cycle is intended for drilling with a dwell at the bottom of the hole.
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Move the Z-axis at the current `feed rate <#sec:set-feed-rate>`__ to the Z position.
#. Dwell for the P number of seconds.
#. The Z-axis does a `rapid move <#gcode:g0>`__ to clear Z.
The motion of a G82 canned cycle looks just like G81 with the addition of a dwell at the bottom of
the Z move. The length of the dwell is specified by a ``P-`` word in the G82 block.
G83 Peck Drilling Cycle
-----------------------
.. code:: text
G83 (X- Y- Z-) or (U- V- W-) R- L- Q-
The ``G83`` cycle (often called peck drilling) is intended for deep drilling or milling with chip
breaking. The retracts in this cycle clear the hole of chips and cut off any long stringers (which
are common when drilling in aluminum). This cycle takes a Q number which represents a ``delta``
increment along the Z-axis. The retract before final depth will always be to the ``retract`` plane
even if G98 is in effect. The final retract will honor the G98/99 in effect. G83 functions the same
as G81 with the addition of retracts during the drilling operation.
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Move the Z-axis at the current `feed rate <#sec:set-feed-rate>`__ downward by delta or to the Z
position, whichever is less deep.
#. Rapid move back out to the retract plane specified by the R word.
#. Rapid move back down to the current hole bottom, backed off a bit.
#. Repeat steps 2, 3, and 4 until the Z position is reached at step 2.
#. The Z-axis does a `rapid move <#gcode:g0>`__ to clear Z.
**It is an error if:**
* the Q number is negative or zero.
G84 Right-hand Tapping Cycle, Dwell
-----------------------------------
.. code:: text
G84 (X- Y- Z-) or (U- V- W-) R- L- P- $-
The ``G84`` cycle is intended for tapping with floating chuck and dwell at the bottom of the hole.
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Disable Feed and Speed Overrides.
#. Move the Z-axis at the current feed rate to the Z position.
#. Stop the seleted spindle (chosen by the $ parameter)
#. Start spindle rotation counterclockwise.
#. Dwell for the P number of seconds.
#. Move the Z-axis at the current feed rate to clear Z
#. Restore Feed and Speed override enables to previous state
The length of the dwell is specified by a ``P-`` word in the G84 block. Thread pitch is F divided
by S. In example S100 F125 gives pitch of 1.25MM per revolution.
G85 Boring Cycle, Feed Out
--------------------------
.. code:: text
G85 (X- Y- Z-) or (U- V- W-) R- L-
The ``G85`` cycle is intended for boring or reaming, but could be used for drilling or milling.
#. Preliminary motion, as described in the `Preliminary and In-Between
Motion <#gcode:preliminary-motion>`__ section.
#. Move the Z-axis only at the current `feed rate <#sec:set-feed-rate>`__ to the Z position.
#. Retract the Z-axis at the current feed rate to the R plane if it is lower than the initial Z.
#. Retract at the traverse rate to clear Z.
G86 Boring Cycle, Spindle Stop, Rapid Move Out
----------------------------------------------
.. code:: text
G86 (X- Y- Z-) or (U- V- W-) R- L- P- $-
The ``G86`` cycle is intended for boring. This cycle uses a P number for the number of seconds to
dwell.
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Move the Z-axis only at the current `feed rate <#sec:set-feed-rate>`__ to the Z position.
#. Dwell for the P number of seconds.
#. Stop the selected spindle turning. (Chosen by the $ parameter)
#. The Z-axis does a `rapid move <#gcode:g0>`__ to clear Z.
#. Restart the spindle in the direction it was going.
**It is an error if:**
* the spindle is not turning before this cycle is executed.
G87 Back Boring Cycle
---------------------
This code is currently unimplemented in LinuxCNC. It is accepted, but the behavior is undefined.
G88 Boring Cycle, Spindle Stop, Manual Out
------------------------------------------
This code is currently unimplemented in LinuxCNC. It is accepted, but the behavior is undefined.
G89 Boring Cycle, Dwell, Feed Out
---------------------------------
.. code:: text
G89 (X- Y- Z-) or (U- V- W-) R- L- P-
The ``G89`` cycle is intended for boring. This cycle uses a P number, where P specifies the number of
seconds to dwell.
#. Preliminary motion, as described in the `Preliminary and In-Between Motion
<#gcode:preliminary-motion>`__ section.
#. Move the Z-axis only at the current `feed rate <#sec:set-feed-rate>`__ to the Z position.
#. Dwell for the P number of seconds.
#. Retract the Z-axis at the current feed rate to clear Z.
G90, G91 Distance Mode
----------------------
* ``G90`` - absolute distance mode In absolute distance mode, axis numbers (X, Y, Z, A, B, C, U,
V, W) usually represent positions in terms of the currently active coordinate system. Any
exceptions to that rule are described explicitly in the `G80 G89 <#gcode:g80-g89>`__ Section.
* ``G91`` - incremental distance mode In incremental distance mode, axis numbers usually represent
increments from the current coordinate.
G90 Example
.. code:: text
G90 (set absolute distance mode)
G0 X2.5 (rapid move to coordinate X2.5 including any offsets in effect)
G91 Example
.. code:: text
G91 (set incremental distance mode)
G0 X2.5 (rapid move 2.5 from current position along the X axis)
* See `G0 <#gcode:g0>`__ section for more information.
.. _g901-g911-arc-distance-mode:
G90.1, G91.1 Arc Distance Mode
------------------------------
* ``G90.1`` - absolute distance mode for I, J & K offsets. When G90.1 is in effect I and J both must
be specified with G2/3 for the XY plane or J and K for the XZ plane or it is an error.
* ``G91.1`` - incremental distance mode for I, J & K offsets. G91.1 Returns I, J & K to their
default behavior.
G92 Coordinate System Offset
----------------------------
.. code:: text
G92 axes
``G92`` makes the current point have the coordinates you want (without motion), where the axis words
contain the axis numbers you want. All axis words are optional, except that at least one must be
used. If an axis word is not used for a given axis, the offset for that axis will be zero.
When ``G92`` is executed, the `origins <#sec.machine-corrdinate-system>`__ of all coordinate systems
move. They move such that the value of the current controlled point, in the currently active
coordinate system, becomes the specified value. All of the coordinate system`s origins (G53-G59.3)
are offset this same distance.
``G92`` uses the values stored in `parameters <#sub:numbered-parameters>`__ 5211-5219 as the X Y Z A B
C U V W offset values for each axis. The parameter values are ``absolute`` machine coordinates in the
native machine ``units`` as specified in the ini file. All axes defined in the ini file will be offset
when G92 is active. If an axis was not entered following the G92, that axis`` offset will be zero.
For example, suppose the current point is at X=4 and there is currently no ``G92`` offset active. Then
``G92 X7`` is programmed. This moves all origins -3 in X, which causes the current point to become
X=7. This -3 is saved in parameter 5211.
Being in incremental distance mode (G91 instead of G90) has no effect on the action of ``G92``.
``G92`` offsets may be already be in effect when the ``G92`` is called. If this is the case, the offset
is replaced with a new offset that makes the current point become the specified value.
**It is an error if:**
* all axis words are omitted.
LinuxCNC stores the G92 offsets and reuses them on the next run of a program. To prevent this, one
can program a G92.1 (to erase them), or program a G92.2 (to remove them - they are still stored).
See the `Coordinate System <#cha:coordinate-system>`__ Section for an overview of coordinate
systems.
See the `Parameters <#gcode:parameters>`__ Section for more information.
.. _g921-g922-reset-g92-offsets:
G92.1, G92.2 Reset G92 Offsets
------------------------------
* ``G92.1`` - turn off G92 offsets and reset
`parameters <#sub:numbered-parameters>`__ 5211 - 5219 to zero.
* ``G92.2`` - turn off G92 offsets but keep
`parameters <#sub:numbered-parameters>`__ 5211 - 5219 available.
.. _g923-restore-g92-offsets:
G92.3 Restore G92 Offsets
-------------------------
* ``G92.3`` - set the G92 offset to the values saved in parameters 5211 to 5219
You can set axis offsets in one program and use the same offsets in another program. Program ``G92``
in the first program. This will set parameters 5211 to 5219. Do not use ``G92.1`` in the remainder of
the first program. The parameter values will be saved when the first program exits and restored when
the second one starts up. Use ``G92.3`` near the beginning of the second program. That will restore
the offsets saved in the first program.
G93, G94, G95: Feed Rate Mode
-----------------------------
* ``G93`` - is Inverse Time Mode. In inverse time feed rate mode, an F word means the move should be
completed in [one divided by the F number] minutes. For example, if the F number is 2.0, the move
should be completed in half a minute.
When the inverse time feed rate mode is active, an F word must appear on every line which has a
G1, G2, or G3 motion, and an F word on a line that does not have G1, G2, or G3 is ignored. Being
in inverse time feed rate mode does not affect G0 (`rapid move <#gcode:g0>`__) motions.
* ``G94`` - is Units per Minute Mode. In units per minute feed mode, an F word is interpreted to
mean the controlled point should move at a certain number of inches per minute, millimeters per
minute, or degrees per minute, depending upon what length units are being used and which axis or
axes are moving.
* ``G95`` - is Units per Revolution Mode In units per revolution mode, an F word is interpreted to
mean the controlled point should move a certain number of inches per revolution of the spindle,
depending on what length units are being used and which axis or axes are moving. G95 is not
suitable for threading, for threading use G33 or G76. G95 requires that spindle.N.speed-in to be
connected. The actual spindle to which the feed is synchronised is chosen by the $ parameter
**It is an error if:**
* Inverse time feed mode is active and a line with G1, G2, or G3 (explicitly or implicitly) does not
have an F word.
* A new feed rate is not specified after switching to G94 or G95
G96, G97 Spindle Control Mode
-----------------------------
.. code:: text
G96 <D-> S- <$-> (Constant Surface Speed Mode)
G97 S- <$-> (RPM Mode)
* ``D`` - maximum spindle RPM
* ``S`` - surface speed
* ``$`` - the spindle of which the speed will be varied.
* ``G96 D- S-`` - selects constant surface speed of ``S`` feet per minute (if G20 is in effect) or
meters per minute (if G21 is in effect). D- is optional.
When using G96, ensure that X0 in the current coordinate system (including offsets and tool
lengths) is the center of rotation or LinuxCNC will not give the desired ssurface speed. G96 is
not affected by radius or diameter mode.
To achieve CSS mode on selected spindles programme successive G96 commands for each spindle prior to
issuing M3.
* ``G97`` selects RPM mode.
G96 Example Line
.. code:: text
G96 D2500 S250 (set CSS with a max rpm of 2500 and a surface speed of 250)
**It is an error if:**
* S is not specified with G96
* A feed move is specified in G96 mode while the spindle is not turning
G98, G99 Canned Cycle Return Level
----------------------------------
* ``G98`` - retract to the position that axis was in just before this series of one or more contiguous
canned cycles was started.
* ``G99`` - retract to the position specified by the R word of the canned cycle.
Program a ``G98`` and the canned cycle will use the Z position prior to the canned cycle as the Z
return position if it is higher than the R value specified in the cycle. If it is lower, the R value
will be used. The R word has different meanings in absolute distance mode and incremental distance
mode.
G98 Retract to Origin
.. code:: text
G0 X1 Y2 Z3
G90 G98 G81 X4 Y5 Z-0.6 R1.8 F10
The G98 to the second line above means that the return move will be to the value of Z in the first
line since it is higher that the R value specified.
The ``initial`` (G98) plane is reset any time cycle motion mode is abandoned, whether explicitly
(G80) or implicitly (any motion code that is not a cycle). Switching among cycle modes (say G81 to
G83) does NOT reset the ``initial`` plane. It is possible to switch between G98 and G99 during a
series of cycles.
.. |G2 Example| image:: images/g2.png
.. |G2-G3 Example| image:: images/g2-3.png
.. |Sample NURBS Output| image:: images/nurbs01.png
.. |G76 Threading| image:: images/g76-threads.png
.. |G76 Example| image:: images/g76-01.png
.. |eight| image:: images/eight.png
.. |twelve| image:: images/twelve.png
.. |G80 Cycle| image:: images/G81mult.png
.. |G81ex1| image:: images/G81ex1.png
.. |G81ex2| image:: images/G81ex2.png
.. |G81| image:: images/G81.png
.. |G81a| image:: images/G81a.png