/ docs / src / gcode / coordinates.txt
coordinates.txt
  1  = Coordinate Systems
  2  
  3  [[cha:coordinate-system]]
  4  
  5  == Introduction
  6  
  7  This chapter introduces you to offsets as they are used by the LinuxCNC.
  8  These include:
  9  
 10  * Machine Coordinates (G53)
 11  * Nine Coordinate System Offsets (G54-G59.3)
 12  * Global Offsets (G92) and Local Offsets (G52)
 13  
 14  [[sec.machine-corrdinate-system]]
 15  
 16  == Machine Coordinate System
 17  
 18  When LinuxCNC is started the postions of each axis is the machine origin. Once
 19  an axis homed the the machine orgin for that axis is set to the homed position.
 20  The machine origin is the machine coordinate system which all other coordinate
 21  systems are based. The <<gcode:g53,G53>> G code can be used to move in the
 22  machine coordinate system.
 23  
 24  == Coordinate Systems
 25  
 26  .Example of Coordinate Systems
 27  image::images/offsets.png[align="center", alt="Example of Coordinate Systems"]
 28  
 29  .Coordinate System Offsets
 30  
 31  * G54 - use coordinate system 1
 32  * G55 - use coordinate system 2
 33  * G56 - use coordinate system 3
 34  * G57 - use coordinate system 4
 35  * G58 - use coordinate system 5
 36  * G59 - use coordinate system 6
 37  * G59.1 - use coordinate system 7
 38  * G59.2 - use coordinate system 8
 39  * G59.3 - use coordinate system 9
 40  
 41  Coordinate system offsets are used to shift the coordinate system from the
 42  machine coordinate system. This allows the G code to be programmed for the
 43  part without regard to the part location on the machine. Using coordinate
 44  system offsets would allow you to machine parts in multiple locations with the
 45  same G code.
 46  
 47  The values for offsets are stored in the VAR file that is requested by the INI
 48  file during the startup of an LinuxCNC.
 49  
 50  In the VAR file scheme, the first variable number stores the X offset,
 51  the second the Y offset and so on for all nine axes. There are numbered
 52  sets like this for each of the coordinate system offsets.
 53  
 54  Each of the graphical interfaces has a way to set values for these
 55  offsets.  You can also set these values by editing the VAR file itself
 56  and then restart LinuxCNC so that the LinuxCNC reads the new values
 57  however this is not the recommended way. Using G10, G52, G92, G28.1,
 58  etc are better ways to set the variables.
 59  
 60  .Example of G55 parameters
 61  [width="40%",cols="^,^,^",options="header"]
 62  |====
 63  |Axis | Variable | Value
 64  | X |5241 |2.000000
 65  | Y |5242 |1.000000
 66  | Z |5243 |-2.000000
 67  | A |5244 |0.000000
 68  | B |5245 |0.000000
 69  | C |5246 |0.000000
 70  | U |5247 |0.000000
 71  | V |5248 |0.000000
 72  | W |5249 |0.000000
 73  |====
 74  
 75  You should read this as moving the zero positions of G55 to X = 2
 76  units, Y= 1 unit, and Z = -2 units away from the absolute zero position.
 77  
 78  Once there are values assigned, a call to G55 in a program block would
 79  shift the zero reference by the values stored. The following line would
 80  then move each axis to the new zero position. Unlike G53, G54 through
 81  G59.3 are modal commands. They will act on all blocks of code after one
 82  of them has been set. The program that might be run using
 83  fixture offsets would require only a single coordinate
 84  reference for each of the locations and all of the work to be done
 85  there. The following code is offered as an example of making a square
 86  using the G55 offsets that we set above.
 87  
 88  ----
 89  G55 ; use coordinate system 2
 90  G0 X0 Y0 Z0
 91  G1 F2 Z-0.2000
 92  X1
 93  Y1
 94  X0
 95  Y0
 96  G0 Z0
 97  G54 ; use coordinate system 1
 98  G0 X0 Y0 Z0
 99  M2
100  ----
101  
102  In this example the G54 near the end leaves the G54 coordinate system with all
103  zero offsets so that there is a modal code for the absolute machine based axis
104  positions. This program assumes that we have done that and use the ending
105  command as a command to machine zero. It would have been possible to use G53
106  and arrive at the same place but that command would not have been modal and
107  any commands issued after it would have returned to using the G55 offsets
108  because that coordinate system would still be in effect.
109  
110  === Default Coordinate System
111  
112  One other variable in the VAR file becomes important when we think
113  about offset systems. This variable is named 5220. In the default files
114  its value is set to 1.00000. This means that when the LinuxCNC starts up it
115  should use the first coordinate system as its default. If you set this
116  to 9.00000 it would use the ninth offset system as its default for
117  start up and reset. Any value other than an integer (decimal really)
118  between 1 and 9, or a missing 5220 variable will cause the LinuxCNC to
119  revert to the default value of 1.00000 on start up.
120  
121  === Setting Coordinate System Offsets
122  
123  The G10 L2x command can be used to set coordinate system offsets:
124  
125  * 'G10 L2  P(1-9)' - Set offset(s) to a value. Current position irrelevant.
126                           (see <<gcode:g10-l2,G10 L2>> for details)
127  
128  * 'G10 L20 P(1-9)' - Set offset(s) so current position becomes a value.
129                           (see <<gcode:g10-l20,G10 L20>> for details)
130  
131  == Local and Global Offsets[[sec:g52-and-g92-offsets]]
132  
133  === The G52 command[[sec:g52]]
134  
135  'G52' is used in a part program as a temporary "local coordinate
136  system offset" within the workpiece coordinate system.  An example use
137  case is when machining several identical features at different
138  locations on a part.  For each feature, 'G52' programs a local
139  reference point within workpiece coordinates, and a subprogram is
140  called to machine the feature relative to that point.
141  
142  'G52' axis offsets are programmed relative to workpiece coordinate
143  offsets 'G54' through 'G59.3'.  As a local offset, 'G52' is applied
144  after the workpiece offset, including rotation.  Thus, a part feature
145  will be machined identically on each part regardless of the part's
146  orientation on the pallet.
147  
148  [CAUTION]
149  
150  As a temporary offset, set and unset within the localized scope of a
151  part program, in other g-code interpreters 'G52' does not persist
152  after machine reset, 'M02' or 'M30'.  In LinuxCNC, 'G52' shares
153  parameters with 'G92', which, for historical reasons, *does* persist
154  these parameters.  See <<sec:g92-persistence-cautions,G92 Persistence
155  Cautions>> below.
156  
157  [CAUTION]
158  
159  'G52' and 'G92' share the same offset registers.  Therefore, setting
160  'G52' will override any earlier 'G92' setting, and 'G52' will persist
161  across machine reset when 'G92' persistence is enabled.  These
162  interactions may result in unexpected offsets.  See
163  <<sec:g92-g52-interaction-cautions,G92 and G52 Interaction Cautions>>
164  below.
165  
166  Programming 'G52 X1 Y2' offsets the current workpiece coordinate
167  system X axis by 1 and Y axis by 2.  Accordingly, on the DRO, the
168  current tool position's X and Y coordinates will be reduced by 1 and
169  2, respectively.  Axes unset in the command, such as Z in the previous
170  example, will be unaffected: any previous 'G52' Z offset will remain
171  in effect, and otherwise the Z offset will be zero.
172  
173  The temporary local offset may be canceled with 'G52 X0 Y0'.  Any axes
174  not explicitly zeroed will retain the previous offset.
175  
176  'G52' shares the same offset registers as 'G92', and thus
177  'G52' is visible on the DRO and preview labeled with 'G92'.
178  
179  === The G92 commands[[sec:g92-commands]]
180  
181  'G92' is typically used in two conceptually different ways: as a
182  "global coordinate system offset" or as a "local coordinate system
183  offset".  The 'G92' set of commands includes:
184  
185  * 'G92' - This command, when used with axis names, sets values to offset
186      variables.
187  
188  * 'G92.1' - This command sets zero values to the G92 variables.
189  
190  * 'G92.2' - This command suspends but does not zero out the G92
191      variables.
192  
193  * 'G92.3' - This command applies offset values that have been suspended.
194  
195  As a global offset, 'G92' is used to shift all workpiece coordinate
196  systems 'G54' through 'G59.3'.  An example use case is when machining
197  several identical parts in fixtures with known locations on a pallet,
198  but the pallet location may change between runs or between machines.
199  Each fixture location offset, relative to a reference point on the
200  pallet, is preset in one of the workpiece coordinate systems, 'G54'
201  through 'G59.3', and 'G92' is used to "touch off" on the pallet
202  reference point.  Then, for each part, the corresponding workpiece
203  coordinate system is selected and the part program is executed.
204  
205  [NOTE]
206  'G10 R-' workpiece coordinate system rotation is specific to the
207  'rs274ngc' interpreter, and the 'G92' offset is applied 'after'
208  rotation.  When using 'G92' as a global offset, workpiece coordinate
209  system rotations may have unexpected results.
210  
211  As a local coordinate system, 'G92' is used as a temporary offset
212  within the workpiece coordinate system.  An example use case is when
213  machining a part with several identical features at different
214  locations.  For each feature, 'G92' is used to set a local reference
215  point, and a subprogram is called to machine the feature starting at
216  that point.
217  
218  [NOTE]
219  The use of 'G92' is discouraged for programming with local coordinate
220  systems in a part program.  Instead, see <<sec:g52,'G52'>>, a local
221  coordinate system offset more intuitive when desired offset relative
222  to the workpiece is known but current tool location may not be known.
223  
224  Programming 'G92 X0 Y0 Z0' sets the current tool location to the
225  coordinates X0, Y0, and Z0, without motion.  G92 *does not* work from
226  absolute machine coordinates.  It works from *current location*.
227  
228  'G92' also works from current location as modified by any other
229  offsets that are in effect when the 'G92' command is invoked. While
230  testing for differences between work offsets and actual offsets it was
231  found that a 'G54' offset could cancel out a 'G92' and thus give the
232  appearance that no offsets were in effect. However, the 'G92' was
233  still in effect for all coordinates and did produce expected work
234  offsets for the other coordinate systems.
235  
236  By default, 'G92' offsets are restored after the machine is started.
237  Programmers that wish for Fanuc behavior, where 'G92' offsets are
238  cleared at machine start and after a reset or program end, may disable
239  'G92' persistence by setting 'DISABLE_G92_PERSISTENCE = 1' in the
240  '[RS274NGC]' section of the '.ini' file.
241  
242  [NOTE]
243  
244  It is good practice to clear the 'G92' offsets at the end of their use
245  with 'G92.1' or 'G92.2'.  When starting up LinuxCNC with 'G92'
246  persistence enabled (the default), any offsets in the 'G92' variables
247  will be applied when an axis is homed.  See
248  <<sec:g92-persistence-cautions,G92 Persistence Cautions>> below.
249  
250  === Setting G92 Values
251  
252  G92 commands work from current axis location and add and subtract
253  correctly to give the current axis position the value assigned by the
254  G92 command. The effects work even though previous offsets are in.
255  
256  So if the X axis is currently showing 2.0000 as its position a 'G92 X0'
257  will set an offset of -2.0000 so that the current location of X becomes
258  zero. A 'G92 X2' will set an offset of 0.0000 and the displayed position
259  will not change. A 'G92 X5.0000' will set an offset of 3.0000 so that the
260  current displayed position becomes 5.0000.
261  
262  === G92 Persistence Cautions[[sec:g92-persistence-cautions]]
263  
264  By default, the values of a 'G92' offset will be saved in the VAR file
265  and be restored after a machine reset or startup.
266  
267  The G92 parameters are:
268  
269  * 5210 - Enable/disable flag (1.0/0.0)
270  * 5211 - X Axis Offset
271  * 5212 - Y Axis Offset
272  * 5213 - Z Axis Offset
273  * 5214 - A Axis Offset
274  * 5215 - B Axis Offset
275  * 5216 - C Axis Offset
276  * 5217 - U Axis Offset
277  * 5218 - V Axis Offset
278  * 5219 - W Axis Offset
279  
280  where 5210 is the 'G92' enable flag (1 for enabled, 0 for disabled)
281  and 5211 to 5219 are the axis offsets. If you are seeing unexpected
282  positions as the result of a commanded move, as a result of storing an
283  offset in a previous program and not clearing them at the end then
284  issue a G92.1 in the MDI window to clear the stored offsets.
285  
286  If G92 values exist in the VAR file when LinuxCNC starts up, the G92
287  values in the var file will be applied to the values of the current
288  location of each axis. If this is home position and home position is
289  set as machine zero everything will be correct. Once home has been
290  established using real machine switches, or by moving each axis to a known
291  home position and issuing an axis home command, any G92 offsets will be
292  applied. If you have a G92 X1 in effect when you home the X axis the
293  DRO will read 'X: 1.000' instead of the expected 'X: 0.000' because the
294  G92 was applied to the machine origin. If you issue a G92.1 and the DRO
295  now reads all zeros then you had a G92 offset in effect when you last
296  ran LinuxCNC.
297  
298  Unless your intention is to use the same G92 offsets in the next
299  program, the best practice is to issue a G92.1 at the end of any G
300  code files where you use G92 offsets.
301  
302  When a program is aborted during processing that has 'G92' offsets in
303  effect a startup will cause them to become active again.  As a
304  safeguard, always have your preamble to set the environment as you
305  expect it.  Additionally, 'G92' persistence may be disabled by setting
306  'DISABLE_G92_PERSISTENCE = 1' in the '[RS274NGC]' section of the
307  '.ini' file.
308  
309  === G92 and G52 Interaction Cautions[[sec:g92-g52-interaction-cautions]]
310  
311  'G52' and 'G92' share the same offset registers.  Unless 'G92'
312  persistence is disabled in the '.ini' file (see <<sec:g92-commands,G92
313  Commands>>), 'G52' offsets will also persist after machine reset,
314  'M02' or 'M30'.  Beware that a 'G52' offset in effect during a program
315  abort may result in unintended offsets when the next program is run.
316  See <<sec:g92-persistence-cautions,G92 Persistence Cautions>> above.
317  
318  == Sample Programs Using Offsets
319  
320  === Sample Program Using Workpiece Coordinate Offsets
321  
322  This sample engraving project mills a set of four .1 radius circles in
323  roughly a star shape around a center circle. We can setup the
324  individual circle pattern like this.
325  
326  ---------------------------------------------------------------------
327  G10 L2 P1 X0 Y0 Z0 (ensure that G54 is set to machine zero)
328  G0 X-0.1 Y0 Z0
329  G1 F1 Z-0.25
330  G3 X-0.1 Y0 I0.1 J0
331  G0 Z0
332  M2
333  ---------------------------------------------------------------------
334  
335  We can issue a set of commands to create offsets for the four other
336  circles like this.
337  
338  -----------------------------------------------------------
339  G10 L2 P2 X0.5 (offsets G55 X value by 0.5 inch)
340  G10 L2 P3 X-0.5 (offsets G56 X value by -0.5 inch)
341  G10 L2 P4 Y0.5 (offsets G57 Y value by 0.5 inch)
342  G10 L2 P5 Y-0.5 (offsets G58 Y value by -0.5 inch)
343  -----------------------------------------------------------
344  
345  We put these together in the following program:
346  
347  ---------------------------------------------------------------------
348  (a program for milling five small circles in a diamond shape)
349  
350  G10 L2 P1 X0 Y0 Z0 (ensure that G54 is machine zero)
351  G10 L2 P2 X0.5 (offsets G55 X value by 0.5 inch)
352  G10 L2 P3 X-0.5 (offsets G56 X value by -0.5 inch)
353  G10 L2 P4 Y0.5 (offsets G57 Y value by 0.5 inch)
354  G10 L2 P5 Y-0.5 (offsets G58 Y value by -0.5 inch)
355  
356  G54 G0 X-0.1 Y0 Z0 (center circle)
357  G1 F1 Z-0.25
358  G3 X-0.1 Y0 I0.1 J0
359  G0 Z0
360  
361  G55 G0 X-0.1 Y0 Z0 (first offset circle)
362  G1 F1 Z-0.25
363  G3 X-0.1 Y0 I0.1 J0
364  G0 Z0
365  
366  G56 G0 X-0.1 Y0 Z0 (second offset circle)
367  G1 F1 Z-0.25
368  G3 X-0.1 Y0 I0.1 J0
369  G0 Z0
370  
371  G57 G0 X-0.1 Y0 Z0 (third offset circle)
372  G1 F1 Z-0.25
373  G3 X-0.1 Y0 I0.1 J0
374  G0 Z0
375  
376  G58 G0 X-0.1 Y0 Z0 (fourth offset circle)
377  G1 F1 Z-0.25
378  G3 X-0.1 Y0 I0.1 J0
379  G54 G0 X0 Y0 Z0
380  
381  M2
382  ---------------------------------------------------------------------
383  
384  Now comes the time when we might apply a set of G92 offsets to this
385  program. You'll see that it is running in each case at Z0. If the mill
386  were at the zero position, a G92 Z1.0000 issued at the head of the
387  program would shift everything an inch. You might also shift the
388  whole pattern around in the XY plane by adding some X and Y offsets
389  with G92. If you do this you should add a G92.1 command just before the
390  M2 that ends the program. If you do not, other programs that you might
391  run after this one will also use that G92 offset. Furthermore it would
392  save the G92 values when you shut down the LinuxCNC and they will be
393  recalled when you start up again.
394  
395  === Sample Program Using G52 Offsets
396  
397  (To be written)