1
Mach4 General Discussion / Run macro from g-code program makes erratic move
« on: November 13, 2021, 09:34:46 AM »
Hi guys, i hope everyone is well. I try to run a macro with probe movement to reference my Z axis, when i run the program without the macro it goes as expected but when i add the macro inside after the sequence ends (the script works as suppose) then next movement will go with acceleration that in not suppose to be (it will do a erratic move and threw driver error).
This the test program i use (a simple rectangle with lead in/lead out)
And this is the m script
Has anyone had that kind of problem and know the solution?
Thanks a lot
This the test program i use (a simple rectangle with lead in/lead out)
Code: [Select]
%
(Filename: Test.nc)
(Date: 13/11/2021)
G21 (Units: Metric)
G17 G90 G80 G40
G00 Z10
X0.5800 Y80.0200
m108 (if i remove this line all runs great)
G00 Z5
G01 F254.0
G03 X2.5000 Y78.1000 I1.9200 J0.0000 F2200.0
G01 X77.5000
G02 X78.1000 Y77.5000 I0.0000 J-0.6000
G01 Y2.5000
G02 X77.5000 Y1.9000 I-0.6000 J0.0000
G01 X2.5000
G02 X1.9000 Y2.5000 I0.0000 J0.6000
G01 Y77.5000
G03 X-0.0200 Y79.4200 I-1.9200 J0.0000
G00 Z10
M30
%
And this is the m script
Code: [Select]
function m108()
local inst = mc.mcGetInstance('m108 script: ');
local probeCode = "G31"; --G code of the probe to use
local safeProbestart = -50;
local returnZ = 20;
local probeOffset = 0.1;
--define motors mapping
local zAxisNb = 2;
local ProbeSignal = mc.ISIG_PROBE
--Track original Z position
local orgZ = mc.mcAxisGetPos(inst,zAxisNb);
mc.mcCntlSetLastError(inst,"M108 – Processing Ohmic sensor touch!");
------------- Check Probe -------------
local hsig = mc.mcSignalGetHandle(inst, ProbeSignal)
local ProbeState = mc.mcSignalGetState(hsig)
if (ProbeState == 1) then
mc.mcCntlSetLastError(inst, "ERROR: Probe signal is ALREADY activated.")
mc.mcCntlEStop(inst);
return;
end
--Ensure we are homed on Z axis
local zHomed = mc.mcAxisIsHomed(inst,zAxisNb);
if (zHomed == 0) then
mc.mcCntlSetLastError(inst,"Z axis is not homed");
mc.mcCntlEStop(inst);
return;
end
--Move Z to safe start position
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z"..safeProbestart); -- Move to probing pos
mc.mcCntlGcodeExecuteWait(inst,"G91 "..probeCode.." Z-25 F200"); --Probe to a max of -40mm
mc.mcAxisSetPos(inst,2,probeOffset); -- Set Z to old tool probed Z
mc.mcCntlGcodeExecuteWait(inst,"G91 G0 Z"..returnZ); -- Move Z to org pos
if (ProbeState == 1) then
wx.wxMessageBox("Probe is still activated! Check to make sure probe is not damaged or still contacting strike plate.");
else
mc.mcCntlSetLastError(inst, "Z Axis now referenced.");
end
end
if (mc.mcInEditor() == 1) then
m108()
end
Has anyone had that kind of problem and know the solution?
Thanks a lot