Author Topic: Programmatically zero axis (G code)  (Read 819 times)

0 Members and 1 Guest are viewing this topic.

Offline FocusPaul

  • Active Member
  • Posts: 45
    • View Profile
Programmatically zero axis (G code)
« on: November 10, 2017, 04:20:45 AM »
Hello!

Is there a way to zero specific axis (G54) in G code?
I currently use the following piece of code, but I guess there's a better way to do it, because without the appended wait, it sometimes does not work.

Code: [Select]
G10 L2 P1 X[#5001] Y[#5002]  (#5001 and #5002 are machine coordinates for X/Y; make a local coordinate system shift)
G4 P0.3 (wait for variable to become set)

Best regards,
Paule

Offline joeaverage

  • Active Member
  • Posts: 4,730
    • View Profile
Re: Programmatically zero axis (G code)
« Reply #1 on: November 10, 2017, 08:52:25 PM »
Hi,
Machs API provides:
Quote
LUA Syntax:
rc = mc.mcAxisSetPos(
   number mInst,
   number axisId,
   number val);

Description:
Set the Position of an axis by changing the fixture offset.

Which could be used:
Quote
function m105();
local inst=mc.mcGetInstance();
mc.mcAxisSetPos(inst,mc.X_AXIS,0.0);
mc.mcAxisSetPos(inst,mc.Y_AXIS,0.0);
mc.mcAxisSetPos(inst,mc.Z_AXIS,0.0);
end
if mc.mcInEditor()==1 then
    m105()
end   
Thus whenever you want to zero the axes you can code m105.

Craig
My wife left with my best friend...
     and I miss him!

Offline FocusPaul

  • Active Member
  • Posts: 45
    • View Profile
Re: Programmatically zero axis (G code)
« Reply #2 on: November 13, 2017, 01:54:39 AM »
Hello Craig,

thank you for the Lua script!

Is there a G code only way to do it, which is easier than the G code mentioned in my 1st post? (M code breaks the CV chain, that's why I ask.)

Paule

Offline joeaverage

  • Active Member
  • Posts: 4,730
    • View Profile
Re: Programmatically zero axis (G code)
« Reply #3 on: November 13, 2017, 05:28:09 AM »
Hi,
not to my knowledge. The Gcode that you posted is simple and effective but doesn't it occasion a pause as well?

Craig
My wife left with my best friend...
     and I miss him!

Offline FocusPaul

  • Active Member
  • Posts: 45
    • View Profile
Re: Programmatically zero axis (G code)
« Reply #4 on: November 13, 2017, 05:34:05 AM »
Correctly, there's a 0.3 seconds pause. Without it, the new axis position is sometimes not recognized. That's why I'm looking for smth better.

Your Lua script is probably faster than my one, but maybe there's a version without any delay. *cough-cough-Steve-cough*