Hello Guest it is March 29, 2024, 09:03:46 AM

Author Topic: Manual touch plate probing after manual tool change  (Read 5640 times)

0 Members and 1 Guest are viewing this topic.

Manual touch plate probing after manual tool change
« on: December 30, 2017, 09:30:13 AM »
So I've done some searching and seen threads such as this one, and I'm aware that dazthegaz has put together a nice M6 macro for automated tool probing.
I really like the idea of daz's automated approach, but it does require having a touch plate/tool setter at a fixed location on the machine.  I am working on setting up that sort of arrangement on my machine, however since I use a dust boot which is manually set to a fixed height based on stock thickness (and is independent of Z travel) I have a lot more interference concerns so it's going to take some work to implement it in a way that doesn't lead to a high risk of crashes.

So, in the meantime I've been experimenting with trying to enable manual Z probing using a touch plate while the machine is paused due to an M6 command.  I have determined that in that case, the machine state is "File Macro Hold".  I added a button on the main panel which does a G31 operation to probe Z, and it works fine when the machine is in the 'idle' state - and the button is set to be enabled in the 'file macro hold' state also.  However, when in 'file macro hold', the probe operation simply doesn't happen.  I'm allowed to jog the machine so clearly motion is not disabled outright, but it seems like it's refusing to execute the G31 command.  Is that behavior something I can change?  Or is there a fundamental limitation that prevents G-code commands from being executed while in the "file macro hold" state?

I understand that the usual answer to this is to postprocess to separate G-code files, each using only a single tool - and that has been my work flow so far.  However, I often find myself doing anywhere from 2 to 5 tool changes to make a given part, and I feel it would be much more convenient and less prone to error (changing to wrong tool, forgetting to load the next file or loading the wrong one, etc) if I could keep everything consolidated and use M6.

Any advice appreciated!
Re: Manual touch plate probing after manual tool change
« Reply #1 on: January 01, 2018, 09:08:02 PM »
Hi,
thats a very interesting problem, and I would only be guessing, and guessing poorly if I tried answering it.

If I understand your workflow you wish to execute Gcode until an M6 occurs whereon it will pause until you have jogged to your probe position
then execute a G31.

When the Gcode halts because of an M6, ie File Macro Hold state, the gcode interpreter is still active. OK so it maybe halted but its still active. What you
wish to happen is the GUI assume control so you can jog to a location. Either the Gcode interpreter or the GUI can run but not both at once.

I think that you will require a coroutine approach where the Gcode interpreter yields on File Macro Hold to the GUI and the GUI resumes the coroutine
when the jogging is done and the Gcode interpreter is required to execute the G31.

If you haven't seen Daz-the-Gaz latest vid it is on coroutines and is a 'must see' for any Mach4 coder. It also represents the extent of my knowledge about
coroutines....very VERY basic. I do get the idea though that the Gcode interpreter and the GUI are separate LUA chunks and a means of transferring back and forth
between them is required.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Manual touch plate probing after manual tool change
« Reply #2 on: January 02, 2018, 08:07:37 AM »
Thanks Craig - that's very useful insight into how Mach works under the hood.  I just watched Daz's video and now I understand the coroutine concept; I'll have to do some digging in the existing code to figure out how to apply it in this case.
Re: Manual touch plate probing after manual tool change
« Reply #3 on: January 05, 2018, 09:31:40 AM »
This is the exact scenario I'm trying to resolve as well.  (recently migrated from Mach3 > Mach4)  It worked exactly as described in Mach3.  On M6, machine would stop and prompt for a tool change.  I could manually jog the machine to a convenient/ad-hoc location of my choosing, change the bit, move the machine back to a location for zeroing against the workpiece, hit the "auto tool zero" button to reset Z height, and then hit "cycle start".  The machine would move to the next location and operations would resume.

Auto Tool Zero - button script/"left up" (adapted from Daz)
Code: [Select]
local TouchPlate = 0.1085 -- toolsetter height in inches
local StartHeight = 0.5 -- once probed, the final retract height

-- Initial Probe --
mc.mcCntlSetLastError(0, "Initiating probe with 2 touches");
AutoToolSetGcode = ""
AutoToolSetGcode = AutoToolSetGcode .. "G91 G31 Z-1.50 F4\n" -- initial move downward to probe
AutoToolSetGcode = AutoToolSetGcode .. "G91 Z0.125 F30\n"  -- retract
AutoToolSetGcode = AutoToolSetGcode .. "G91 G31 Z-1.00 F2\n" -- move down again, slower to probe
mc.mcCntlGcodeExecuteWait(0, AutoToolSetGcode) -- execute gcode

-- Set Z --
mc.mcCntlSetLastError(0, "Resetting Z axis");
mc.mcAxisSetPos(0, mc.Z_AXIS, TouchPlate) -- zero the Z axis
FinalPosition = StartHeight - TouchPlate
AutoToolSetGcode = ""
AutoToolSetGcode = AutoToolSetGcode .. string.format("G91 Z%.4f F30\n", FinalPosition)
mc.mcCntlGcodeExecuteWait(0, AutoToolSetGcode) -- move back
mc.mcCntlSetLastError(0, "Probe complete");

-- Message Box --
wx.wxMessageBox("Z Height Set, Remove TouchPlate")
-Tim

Mach4/Win7, ESS, Xbox360 controller, Router-based Mill & BlackTooth Laser
Re: Manual touch plate probing after manual tool change
« Reply #4 on: January 21, 2018, 10:31:55 AM »
I imagine the workflow as synonymous.

I tried a lot in Mach4, also coroutines. But it does not work either.

This is the M6 Lua macro of Mach4 v3481 in the Profile folder:

Code: [Select]
--[[function m6()

local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)

mc.mcCntlSetLastError(inst, "M06 Lua makro")

if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up

--mc.mcCntlGcodeExecute(inst, "G59\nG00 Z0\nG00 X0 Y48");--Move the Z axis all the way up
--mc.mcCntlFeedHold(inst);


mc.mcCntlToolChangeManual(inst, true);
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. "   Previous Tool == " .. tostring(currenttool))
mc.mcToolSetCurrent(inst, selectedtool)
end
end

if (mc.mcInEditor() == 1) then
 m6()
end]]

As soon as mc.mcCntlToolChangeManual(inst, true); is called, Mach4 is in a waiting loop. Execute MDI or gcode do not work (not allowed).


I developed my own solution.
If M6 is called then M00 (program stop) is executed and Output 1 is set to on. Then i change the tool and press the Cycle Start Button. The Output 1 is set to off and gcode will be processed further.

Here is my M6 Macro Code:

Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)

--if selectedtool == currenttool then
--mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
--else
--Remove this line if you would not like the Z axis to move
--mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up

--mc.mcCntlSetLastError(inst, "m6()");

local signal = mc.OSIG_OUTPUT1;
--local signalToolchange = mc.OSIG_TOOL_CHANGE;

local hSig = mc.mcSignalGetHandle(inst, signal);
local state = mc.mcSignalGetState(hSig);

local stateToolchange = mc.mcSignalGetState(mc.mcSignalGetHandle(inst, mc.OSIG_TOOL_CHANGE));
mc.mcCntlSetLastError(inst, "m6(): mc.OSIG_OUTPUT1 state"..tostring(state));
mc.mcCntlSetLastError(inst, "m6(): mc.OSIG_TOOL_CHANGE state"..tostring(stateToolchange));
if state == 0 then
mc.mcCntlSetLastError(inst, "m6(): Tool change active");
mc.mcCntlGcodeExecute(inst, "M00");
mc.mcSignalSetState(hSig, true);

mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. "   Previous Tool == " .. tostring(currenttool))
mc.mcToolSetCurrent(inst, selectedtool)
else
mc.mcSignalSetState(hSig, false);
mc.mcCntlSetLastError(inst, "m6(): Tool change inactive");
--mc.mcCntlSetLastError(inst, "m6(): mcCntlToolChangeManual");
--mc.mcCntlToolChangeManual(inst, true);
end;
--end
end

if (mc.mcInEditor() == 1) then
 m6()
end

There is still a problem. If press the Stop, Reset, etc. Button during the tool change (Output 1 on), the Output 1 will not be reseted. I will try to find a solution.



Re: Manual touch plate probing after manual tool change
« Reply #5 on: January 21, 2018, 08:59:35 PM »
Hi,
not quite sure what your achieving. If you wish to jog or MDI then Machs GUI must be in control.
While your running a program Machs Gcode interpreter is in control up till and including an M06 toolchange.

What you want to do is have control temporarily go back to the GUI so you can jog but then go back to the interperter
to carry on with the program.

What you have done is stopped the program (and stopped the interperter) with an M00. But now you can't go back
and carry on from where you left off, you'll either have to rerun the program or RunFromHere.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Manual touch plate probing after manual tool change
« Reply #6 on: January 22, 2018, 12:15:39 AM »
I'm confused. The title of the post is "Manual touch plate probing after manual tool change". What is there to automate through script?

I know you might be able to do stuff like this with Mach3 but it has never been a good idea.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Manual touch plate probing after manual tool change
« Reply #7 on: January 22, 2018, 08:22:02 AM »
When you click cycle start this sets the OSIG_RUNNING_GCODE signal to HIGH and also sets the OSIG_JOG_ENABLED signal to LOW preventing ANY jogging.

If you try and enable the OSIG_JOG_ENABLED whilst OSIG_RUNNING_GCODE is HIGH this can and more likely will crash the core and kill your part, there is a little extract from the api docs

Quote from: API Docs
The Mach core communicates with the outside world via a signal mechanism. All signals are "owned" by the core. The core drives output signals and input signals direct the core. This means that a user should never set an output signal and the core will never set an input signal.

So to answer the question, jogging should`nt be done or allowed

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Manual touch plate probing after manual tool change
« Reply #8 on: January 22, 2018, 04:27:33 PM »
Hi Daz,
very well put and explained.

There are a couple of threads on the forum at the moment which pose exactly this problem.

While I understand its not possible to run Gcode AND jog at the same time, is it possible to suspend a Gcode job,
manually jog and/or MDI and THEN return to where the Gcode job left off?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Manual touch plate probing after manual tool change
« Reply #9 on: January 22, 2018, 05:01:12 PM »
I hate when something is right in front of you but cant see it!!!!!!

Try something like this, hell you have to press cycle start but still  ;D ;D

Code: [Select]
function m6()
local inst = mc.mcGetInstance()
local selectedtool = mc.mcToolGetSelected(inst)
local currenttool = mc.mcToolGetCurrent(inst)

if selectedtool == currenttool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
        mc.mcCntlCycleStop(inst)
        wx.wxMessageBox("Please change tool and press Cycle Start\nAfter setting tool please RAISE Z Axis")
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. "   Previous Tool == " .. tostring(currenttool))
        mc.mcToolSetCurrent(inst, selectedtool)
end
end

if (mc.mcInEditor() == 1) then
    m6()
end

After the cycle is stopped in the m6 mach is then in a jogable state, you can then jog around as much as you like. before pressing cycle start again you must put your Z at a safe hight.
I have only tried this on the sim so cannot say how it will go with variables or anything else.

DazTheGas
New For 2022 - Instagram: dazthegas