Hello Guest it is April 25, 2024, 06:45:41 PM

Author Topic: M6 Tool Change Code Question  (Read 845 times)

0 Members and 1 Guest are viewing this topic.

M6 Tool Change Code Question
« on: November 22, 2022, 12:13:53 PM »
Hello all!
I built a CNC router for my shop class about 14 years ago. The windows XP computer we were using to run Mach3 died a couple of weeks ago. I can't find another computer with windows xp and a parallel port so I'm trying to move over and use Mach4.  I can't seem to get the M6 function to work like it did in Mach 3. I've been searching but I can't seem to find the answer to my question. Any help you can provide would be much appreciated by me and my students who are waiting to use the machine!

What I would like the M6 command to do is as follows:
1. Stop the spindle
2. Allow us to manually jog the machine to a tool change location.
3. Run the probing script to reset Z zero when I press a button on the screen. ( My script does not allow me to press the touch button on the screen)
4. Press cycle start
5. Move the machine to a safe z location
6. Start the spindle
6. Move the machine back the the starting x,y,z location
7. Resume the program

Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local SpindleDwell = 20000
local xstart = mc.mcAxisGetPos (inst, 0)
local ystart = mc.mcAxisGetPos (inst, 1)

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 G0 Z0.0");--Move the Z axis all the way up
mc.mcCntlGcodeExecute(inst, "M5 G4 P"..SpindleDwell) --Turn off spindle
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue
--What code is needed to allow me to jog the machine and use the tool touch plate function?
mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..xstart.."Y"..ystart)--Move to start location
mc.mcCntlGcodeExecute(inst, "M3 G4 P"..SpindleDwell)--Turn spindle on and wait for dwell
mc.mcCntlGcodeExecuteWait(inst, "G90 G0 Z0")--Move to Z0

end
end

if (mc.mcInEditor() == 1) then
m6()
end
Re: M6 Tool Change Code Question
« Reply #1 on: November 22, 2022, 02:34:15 PM »
You can use a Win10 computer running Mach3 with a motion controller quite happily.  I use a uc100 usb controller with a Dell mini pc and the move was painless and all my settings and macros worked.  So you could carry on using Mach3 on a new PC with the macros you are used to.
Re: M6 Tool Change Code Question
« Reply #2 on: November 22, 2022, 03:09:57 PM »
You can use a Win10 computer running Mach3 with a motion controller quite happily.  I use a uc100 usb controller with a Dell mini pc and the move was painless and all my settings and macros worked.  So you could carry on using Mach3 on a new PC with the macros you are used to.

Thanks. I purchased a PMDX-411 for mach 4. I don't think that will work with mach 3 but I will give it a shot.
Re: M6 Tool Change Code Question
« Reply #3 on: November 22, 2022, 03:14:52 PM »
Hi,
you can do as you want. There is a thread that covers some of the important points:

https://www.machsupport.com/forum/index.php?topic=45873.0

You need to be able to pause the m6 macro so that the trajectory planner is released so that you can manually jog the machine.

That is what the API is for:

LUA Syntax:
rc = mc.mcFileHoldAquire(
      number mInst,
      string reason,
      number JogAxisBits)

Description:
Used to hold G code processing.


Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: M6 Tool Change Code Question
« Reply #4 on: November 22, 2022, 04:29:13 PM »
Hi,
you can do as you want. There is a thread that covers some of the important points:

https://www.machsupport.com/forum/index.php?topic=45873.0

You need to be able to pause the m6 macro so that the trajectory planner is released so that you can manually jog the machine.

That is what the API is for:

LUA Syntax:
rc = mc.mcFileHoldAquire(
      number mInst,
      string reason,
      number JogAxisBits)

Description:
Used to hold G code processing.

Craig

Thank you for the help. If I pose the M6 macro how to I start it again after I have finished the touch off?
Re: M6 Tool Change Code Question
« Reply #5 on: November 22, 2022, 04:54:05 PM »
Hi,
I've just recognised that I have directed you to the wrong thread. The thread I did direct you to is related and requires the same solution but this is better:

https://www.machsupport.com/forum/index.php?topic=46728.0

You will see also that my first post in that thread is if not wrong, certainly uninformed. I made the argument that to jog the machine would require you to terminate
the current program, not just pause it. It needs be terminated so that the trajectory planner can then attend the jog commands.

Fortunately Smurph chimed in with yet another one of his gems, namely the API I posted. The complementary API is:

LUA Syntax:
rc = mc.mcFileHoldRelease(
      number mInst)

Description:
Used to exit a file hold state.

But take heed of Smurphs warning you MUST do a preparatory move back to the machine position at the moment the m6 was called....or you will crash,
just like a poorly performed RunFromHere.

Craig

« Last Edit: November 22, 2022, 04:55:52 PM by joeaverage »
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: M6 Tool Change Code Question
« Reply #6 on: November 22, 2022, 06:53:38 PM »
JoeAverage thank you for the help, I fear I'm in over my head on this one. I think I need to find someone who can code it for me. I'm on a tight deadline to get everything back up and running for my students.
Re: M6 Tool Change Code Question
« Reply #7 on: November 22, 2022, 07:51:03 PM »
Hi,
I wonder if you are making this a little more complicated than it need be.

Is there a reason for instance that you want to manually jog to a tool change location?. Does that location change from one job to the next?
If it does not change location then just have the m6 macro drive to that location, then pause while the tool change is happening....no need to FileHold
or anything fancy, then <cycle start> now have the macro drive to the probing location, again assuming this location remains fixed from one job to another, and perform
a g31 to set the tool. If the tool length is widely variable you may want to be able to manually jog the tool tip close to the toolsetter, is use FileHold, buit otherwise just probe
the tool then drive back to the machine re-start position and carry on.

Its only the need to manually jog during your macro that adds the complexity. Do you strictly need to jog?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: M6 Tool Change Code Question
« Reply #8 on: November 22, 2022, 08:06:29 PM »
Hi,
I wonder if you are making this a little more complicated than it need be.

Is there a reason for instance that you want to manually jog to a tool change location?. Does that location change from one job to the next?
If it does not change location then just have the m6 macro drive to that location, then pause while the tool change is happening....no need to FileHold
or anything fancy, then <cycle start> now have the macro drive to the probing location, again assuming this location remains fixed from one job to another, and perform
a g31 to set the tool. If the tool length is widely variable you may want to be able to manually jog the tool tip close to the toolsetter, is use FileHold, buit otherwise just probe
the tool then drive back to the machine re-start position and carry on.

Its only the need to manually jog during your macro that adds the complexity. Do you strictly need to jog?

Craig

The tool change location does change from job to job (My machine does not have homing switches to maintain good machine coordinates).

What I have done in the past is jog the machine to a good location to change the bit. Then jog it to the material and press the button on the screen to touch off on the plate and reset z zero. Then when I click cycle start it turns on the spindle, moves to a safe z location, moves back to the last location in the g-code, and resumes the program.

Similar to what is shown in this avid CNC video:  https://youtu.be/XUXeJywH46I?t=268
Re: M6 Tool Change Code Question
« Reply #9 on: November 22, 2022, 08:17:46 PM »
Hi,
without Homing switches you are sunk.

The best single addition I ever made to my mini-mill six years ago was to add good Home switches. I used to have battles such as you are facing and plenty of
other crashes.....until I fitted Home switches, thereafter three crashes in six years, and all of those were operator induced!

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