I have already asked this on the general forum:
How can I read the current X,Y,Z into parameters to use in calculations?
A reply there suggested using #5021, #5022 etc. This doesn't seem to work in EMC2. (V2.2.8) and I suspect may be Fanuc-specific.
What I am trying to do is to write a simple general-purpose lathe block, where I can say "starting where you are now, face of to Z=40mm in 0.5mm cuts". Easy enough, except that I can't find a way to read the current position in order to return to the same X for the next cut.
I am sure that there are other ways to do this, too. Perhaps I have too much of a manual machinist / generic coder mindset and am not getting the G-code thing.
You could use G92 to set the position that the machine is at, to whatever you want.
Eg G92 X0 Y0 Z0 sets the current position to X, Y, Z 0 . One problem is it also offset all the other coordinate systems by whatever the difference was of current position and requested position. meaning if you were at X 2 and G92 x 0, you offset -2 inches so all the other coordinate systems will subtract - 2 from X.
So remember to cancel G92 afterwards (G92.1). See the manual for more info.
It is easy to get your self in trouble with G92 if you forget to cancel it.