In the past I had experienced some unexpected behavior in how Marlin handles work offsets, and in digging through the code recently, I finally understand why it behaves the way it does. Previously I thought that G28 performs an implicit G92, but this is not fully correct either.
When you set an offset using G92, it sets the current offset (position_shift
) and also saves the shift to one of the workspace slots based on which workspace you’re currently in. Then switching workspaces with G55, G54, etc. loads the shift from the saved workspace slot and updates position_shift
. Good enough so far.
The exception to the save/restore behavior is if you are in G53 native coordinates. In G53 coordinates, it allows you to set an offset with G92, but it does not save, so switching to a different workspace and switching back to native G53 loses the position_shift
that you had and resets it to zero. That’s reasonable enough, since G53 is supposed to be native coordinates.
What’s potentially confusing is that homing with G28 will reset the position_shift
to zero, but it doesn’t change any of the saved workspace values. So suppose you do this:
- Home the machine
- Choose workspace G54
- Jog to the workpiece
- G92 X0 Y0 Z0 to set the workspace origin to the workpiece
- Cut part 1 of a job
- Disable steppers with M84 and come back the next day
- (Controller has remained on but maybe the machine has moved)
Now you want to home the machine again and continue the job. You are still in workspace G54, but if you home the machine with G28, it will report X=0 Y=0 Z=0 at the machine origin since it has reset position_shift
. It still has the correct offsets saved for the workspace for slot G54, but they are not reflected in position_shift
even though you are theoretically still in workspace G54.
If you change to a different workspace and change back, say with G55 and then G54, then it will restore the position_shift
to the correct values and then you can continue the job from the previous day. Another way to switch to another workspace and switch back is to use G53 <command>
which temporarily runs the command in native workspace and then switches back, which loads position_shift
from the saved slot. You can do a simple dwell, like G53 G4 S0
.
So to continue the example above, suppose you return to the machine the next day. To cut part 2 of a job:
- Home the machine
-
G53 G4 S0
to force reloading of the workspace offsets - If the gcode for part 2 contains
G92 X0 Y0 Z0
then you can jog to the workpiece origin (G1 X0 Y0 Z0
) before running part 2 - Cut part 2 of the job
Workspace offsets survive homing with G28, although they give the initial impression that they don’t.
I haven’t tried saving workspace offsets to EEPROM, but presumably this could be used to continue a job even after the entire machine has been powered off.
Now, in the unlikely case that you have a dual-x-carriage LR3 setup, switching tools T0
/T1
reuses some of the code from homing (G28
), the effect of which is to sometimes* clear the position_shift
in the X direction similar to G28 X
. If you had set up an X offset with G92, that offset is lost, unless you had selected a workspace like G54, and in that case you can restore the offset by switching away and switching back. I find the simplest way to do that is with the G53 dwell: G53 G4 S0
.
*Clearing of position_shift
occurs when switching from T1 to T0, but not when switching from T0 to T1. Go figure.