Hello Guest it is April 16, 2024, 05:59:54 AM

Author Topic: Run macro from g-code program makes erratic move  (Read 970 times)

0 Members and 1 Guest are viewing this topic.

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)
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

Online Graham Waterworth

*
  • *
  •  2,671 2,671
  • Yorkshire Dales, England
    • View Profile
Re: Run macro from g-code program makes erratic move
« Reply #1 on: November 13, 2021, 06:25:34 PM »
I see nothing in your macro that reads the current state of your machine e.g.

Is machine in G90/91 mode, G53,54,55,56 etc, current feed, speed etc.

Then it can be set back on exit so you dont get strange moves.

By the look of it you enter the macro in G90 mode and exit in G91 mode.
Without engineers the world stops
Re: Run macro from g-code program makes erratic move
« Reply #2 on: November 13, 2021, 06:41:50 PM »
I see nothing in your macro that reads the current state of your machine e.g.
I am going to try and post back, thanks Graham.

By the look of it you enter the macro in G90 mode and exit in G91 mode.
That true too :)
Re: Run macro from g-code program makes erratic move
« Reply #3 on: November 13, 2021, 07:25:29 PM »
By the look of it you enter the macro in G90 mode and exit in G91 mode.
You was/are right, because it not change to G90 as when it start does it. I was trying to solve other problems before and when that happened i get so frustrated and didn't see the obvious. Again thanks a lot. 

I try by adding it inside g-code after the macro and it works, i believe it will work from the macro too.
Re: Run macro from g-code program makes erratic move
« Reply #4 on: November 13, 2021, 09:02:34 PM »
Problem solved

I use inside the macro to change back the position mode G90 and all went smooth.
Code: [Select]
--To get the current position mode
local positionMode = mc.mcCntlGetPoundVar(inst,4003);

--To set back the position mode
mc.mcCntlGcodeExecuteWait(inst,"G"..positionMode);

Online Graham Waterworth

*
  • *
  •  2,671 2,671
  • Yorkshire Dales, England
    • View Profile
Re: Run macro from g-code program makes erratic move
« Reply #5 on: November 14, 2021, 07:15:40 PM »
Happy to help  :)
Without engineers the world stops

GOOMBA

*
Re: Run macro from g-code program makes erratic move
« Reply #6 on: November 15, 2021, 04:20:28 PM »
Hello,
If you use the machine state push and pop functions documented in the API it will solve this for you.

mcCntlMachineStatePush at the beginning of the macro.

Then before you leave the macro

mcCntlMachineStatePop

This will revert you back to all the previous modal states called before the macro :)
Best of luck!
Re: Run macro from g-code program makes erratic move
« Reply #7 on: November 15, 2021, 04:57:58 PM »
Hello,
If you use the machine state push and pop functions documented in the API it will solve this for you.

mcCntlMachineStatePush at the beginning of the macro.

Then before you leave the macro

mcCntlMachineStatePop

This will revert you back to all the previous modal states called before the macro :)
Best of luck!


Good to know, i find it and at the core manual. Thanks a lot, sure i will give it a try :)