Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Videos => Topic started by: DazTheGas on October 13, 2015, 03:50:37 PM

Title: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: DazTheGas on October 13, 2015, 03:50:37 PM
Yay Finished (with a crashed machine  ???

Although the machine crashed at the end the code has been retested completely and works a treat.

Video https://youtu.be/w1xzYPT27NY (https://youtu.be/w1xzYPT27NY)

The Final Code

Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local xstart = mc.mcAxisGetPos(inst,0)
    local ystart = mc.mcAxisGetPos(inst,1)

    if selectedtool == currenttool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n X14 Y30")
    wx.wxMessageBox("Please turn off spindle and click ok to continue") --can be removed if required
    RunProbe(currenttool)
    local toolz = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    local changetoo = mc.mcToolGetDesc(inst,selectedtool)
    wx.wxMessageBox("Please change to tool number "..selectedtool.." "..changetoo.." and press ok to continue")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X14 Y30")
    RunProbe(selectedtool)
    mc.mcAxisSetPos(inst, 2 , toolz)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    wx.wxMessageBox("Please turn on spindle and click ok to continue") --can be removed if required
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..xstart.." Y"..ystart)
    mc.mcToolSetCurrent(inst, selectedtool)
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end

function RunProbe(tool)
    local inst = mc.mcGetInstance()
    toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, tool)
    if toollen == 0 then toollen = 40 end -- User Preference
    mc.mcCntlSetLastError(inst, "Changing to Fallback Length")
    local probestart = -60 + toollen
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\nG91 G31 Z-15 F25")
end

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

now to do a quick vid on that crash!!!!

DazTheGas
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: dhnaranjo on November 03, 2015, 11:19:43 AM
Hey, I wanted to thank you for this post, using your macro as a reference and knowing like, literally no G Code or LUA I was able to get a manual toolchange with automatic touchoff working.

I really appreciate it.
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Bx3mE on November 28, 2016, 05:50:24 PM
Just adding a thankyou! :)

I Made some Modifications
- Probemove for approach probe to avoid Crash :) and back off probe before real probing.
- Lots of Variables to tune the script
---Preset for probelocation
---Preset for ToolChange position
---Preset for defaults and speeds


Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local changeToTool = 3--mc.mcToolGetSelected(inst)
    local changeFromTool = 2--mc.mcToolGetCurrent(inst)
    local XPositionBeforeToolChange = mc.mcAxisGetPos(inst,0)
    local YPositionBeforeToolChange = mc.mcAxisGetPos(inst,1)
    local XToolProbePosition = "1"
    local YToolProbePosition = "1"
    local XManualToolChangePosition = "2"
    local YManualToolChangePosition = "2"
    local ColletAtProbeZCoordinate = -103 -- Machine Z-coordinate when collet tip touches TouchPlate (Must be more than ProbeOperationDistance - DefaultToolLength
    local ExtraProbeDistance = 5 -- SafetyMargin
    local ProbeOperationDistance = -30 -- Length of Probemove before giving up
    local ProbePrepSpeed = 100
    local ProbeSpeed = 25
    local DefaultToolLength = 70 -- Used if tool info is not found. (Should be a value slightly longer than the longest tool in the shop :D)
        -- QUICK REFERENCE
        -- G90 - Absolute (Go to coordinate)
        -- G91 - Incremental (Godistance along axis from current position)
        -- G53 - Machine Coordinate Move

    if changeToTool == changeFromTool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0\nM5" )
    RunProbe(inst,changeFromTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed)
    local ToolZCoordinate = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n X"..XManualToolChangePosition.." Y"..YManualToolChangePosition)
    local changeToToolDescription = mc.mcToolGetDesc(inst,changeToTool)
    wx.wxMessageBox("Please change to tool number "..changeToTool.." "..changeToToolDescription.." and press ok to continue")
    RunProbe(inst,changeToTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed)
    mc.mcAxisSetPos(inst, 2 , ToolZCoordinate)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..XPositionBeforeToolChange.." Y"..YPositionBeforeToolChange)
    mc.mcToolSetCurrent(inst, changeToTool)
    wx.wxMessageBox("If Toolchange was Sucessful - click ok to continue")
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end

function RunProbe(finst,ftool,fXToolProbePosition,fYToolProbePosition,fDefaultToolLength,fColletAtProbeZCoordinate,fExtraProbeDistance,fProbePrepSpeed,fProbeSpeed)
    mc.mcCntlGcodeExecuteWait(finst, "G90 G53 G0 X"..fXToolProbePosition.." Y"..fYToolProbePosition)
    local toollen = mc.mcToolGetData(finst, mc.MTOOL_MILL_HEIGHT, ftool)
    if toollen == 0 then toollen = fDefaultToolLength end
    mc.mcCntlSetLastError(finst, "Tool length not found - using Default Length")
    local probestart = fColletAtProbeZCoordinate + fExtraProbeDistance + toollen
    local GCODE = "G90 G53 G31 G0 Z"..probestart.." F"..fProbePrepSpeed
    GCODE = ""..GCODE.." \n G91 G0 Z5 F"..fProbePrepSpeed.." \n G91 G31 Z-15 F"..fProbeSpeed
    mc.mcCntlGcodeExecuteWait(finst,GCODE)
end

if (mc.mcInEditor() == 1) then
    M6()
end
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Bx3mE on November 29, 2016, 08:08:14 AM
The change i made to avoid Crash on approach did not behave as expected ( NOT WORKING AT ALL ;D)
So fixed now...And Some other stuff :P

I have not done any rigorus testing but tried some stupid stuff and the script still behaves...

New Version:

Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local changeToTool = mc.mcToolGetSelected(inst)
    local changeFromTool = mc.mcToolGetCurrent(inst)
    local XPositionBeforeToolChange = mc.mcAxisGetPos(inst,0)
    local YPositionBeforeToolChange = mc.mcAxisGetPos(inst,1)
    local XToolProbePosition = "1"
    local YToolProbePosition = "1"
    local XManualToolChangePosition = "2"
    local YManualToolChangePosition = "2"
    local ColletAtProbeZCoordinate = -105 -- Machine Z-coordinate when collet tip touches TouchPlate (Must be more than ProbeOperationDistance - DefaultToolLength
    local ExtraProbeDistance = 5 -- SafetyMargin
    local ProbeOperationDistance = -30 -- Length of Probemove before giving up
    local ProbePrepSpeed = 100
    local ProbeSpeed = 25
    local DefaultToolLength = 70 -- Used if tool info is not found. (Should be a value slightly longer than the longest tool in the shop :D)
        -- QUICK REFERENCE
        -- G90 - Absolute (Go to coordinate)
        -- G91 - Incremental (Godistance along axis from current position)
        -- G53 - Machine Coordinate Move

    if changeToTool == changeFromTool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0\nM5" )
    RunProbe(inst,changeFromTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
    local ToolZCoordinate = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n G90 G53 G0 X"..XManualToolChangePosition.." Y"..YManualToolChangePosition)
    local changeToToolDescription = mc.mcToolGetDesc(inst,changeToTool)
    wx.wxMessageBox("Please change to tool number "..changeToTool.." "..changeToToolDescription.." and press ok to continue")
    RunProbe(inst,changeToTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
    mc.mcAxisSetPos(inst, 2 , ToolZCoordinate)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..XPositionBeforeToolChange.." Y"..YPositionBeforeToolChange)
    mc.mcToolSetCurrent(inst, changeToTool)
    wx.wxMessageBox("If Toolchange was Sucessful - click ok to continue")
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end

function RunProbe(finst,ftool,fXToolProbePosition,fYToolProbePosition,fDefaultToolLength,fColletAtProbeZCoordinate,fExtraProbeDistance,fProbePrepSpeed,fProbeSpeed,fProbeOperationDistance)
    mc.mcCntlGcodeExecuteWait(finst, "G90 G53 G0 X"..fXToolProbePosition.." Y"..fYToolProbePosition)
    local toollen = mc.mcToolGetData(finst, mc.MTOOL_MILL_HEIGHT, ftool)
    if toollen == 0 then
        toollen = fDefaultToolLength
        mc.mcCntlSetLastError(finst, "Tool length not found - using Default Length")
    end
    local probestart = fColletAtProbeZCoordinate + fExtraProbeDistance + toollen
    local GCODE = "G91 G31 G0 Z"..probestart.." F"..fProbePrepSpeed
    GCODE = ""..GCODE.." \n G91 G0 Z1 F"..fProbePrepSpeed.." \n G91 G31 Z"..fProbeOperationDistance.." F"..fProbeSpeed
    mc.mcCntlGcodeExecuteWait(finst,GCODE)
end

if (mc.mcInEditor() == 1) then
    M6()
end
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Firechief on May 01, 2017, 02:05:14 PM
I have used your tool change code.. after a little set in inch's it works great. One thing I would like to do is have the code turn off the spindle and wait for 12 sec or have the VFD trip a spindle has stopped before it moves. The Post code from Vcarve has the start up of the spindle and is working good.

Big thanks to your help as I have used other code and it always is great. Please keep up your help, there is a lot of us that need it.

Firechief
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: DazTheGas on May 01, 2017, 04:03:50 PM
Thats quite a good point, since creating that script I have moved on to using vfd and spindle etc so it could do with a revamp. I see what I can muster up ;-)

DazTheGas
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Firechief on May 03, 2017, 11:22:30 AM
Just another point I found in the code you may like to fine tune. when the Z move up to your set point Z0, my Z0 will trip my limit switch. Sounds dumb but it took my some time to find out why it would not run the tool change. reset it to -2 and all was good.  :D
I'am just glad that the code is starting to make some logic to me. [Little]

BIG THANKS
firechief
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Firechief on May 08, 2017, 11:16:26 AM
All my testing was done in the MDI window this M6 code work great... when I run it in the gcode it would not set the tool to the right height. (way off). What I found was the post Processor was adding a tool offset to the gcode on the next line in the gcode. I mod the post processor and remove it and then all was well. Big thanks for all your code.



Tim Smith


 
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Xillianto on August 31, 2017, 03:41:21 PM
The change i made to avoid Crash on approach did not behave as expected ( NOT WORKING AT ALL ;D)
So fixed now...And Some other stuff :P

I have not done any rigorus testing but tried some stupid stuff and the script still behaves...

New Version:

Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local changeToTool = mc.mcToolGetSelected(inst)
    local changeFromTool = mc.mcToolGetCurrent(inst)
    local XPositionBeforeToolChange = mc.mcAxisGetPos(inst,0)
    local YPositionBeforeToolChange = mc.mcAxisGetPos(inst,1)
    local XToolProbePosition = "1"
    local YToolProbePosition = "1"
    local XManualToolChangePosition = "2"
    local YManualToolChangePosition = "2"
    local ColletAtProbeZCoordinate = -105 -- Machine Z-coordinate when collet tip touches TouchPlate (Must be more than ProbeOperationDistance - DefaultToolLength
    local ExtraProbeDistance = 5 -- SafetyMargin
    local ProbeOperationDistance = -30 -- Length of Probemove before giving up
    local ProbePrepSpeed = 100
    local ProbeSpeed = 25
    local DefaultToolLength = 70 -- Used if tool info is not found. (Should be a value slightly longer than the longest tool in the shop :D)
        -- QUICK REFERENCE
        -- G90 - Absolute (Go to coordinate)
        -- G91 - Incremental (Godistance along axis from current position)
        -- G53 - Machine Coordinate Move

    if changeToTool == changeFromTool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0\nM5" )
    RunProbe(inst,changeFromTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
    local ToolZCoordinate = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n G90 G53 G0 X"..XManualToolChangePosition.." Y"..YManualToolChangePosition)
    local changeToToolDescription = mc.mcToolGetDesc(inst,changeToTool)
    wx.wxMessageBox("Please change to tool number "..changeToTool.." "..changeToToolDescription.." and press ok to continue")
    RunProbe(inst,changeToTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed,ProbeOperationDistance)
    mc.mcAxisSetPos(inst, 2 , ToolZCoordinate)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..XPositionBeforeToolChange.." Y"..YPositionBeforeToolChange)
    mc.mcToolSetCurrent(inst, changeToTool)
    wx.wxMessageBox("If Toolchange was Sucessful - click ok to continue")
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end

function RunProbe(finst,ftool,fXToolProbePosition,fYToolProbePosition,fDefaultToolLength,fColletAtProbeZCoordinate,fExtraProbeDistance,fProbePrepSpeed,fProbeSpeed,fProbeOperationDistance)
    mc.mcCntlGcodeExecuteWait(finst, "G90 G53 G0 X"..fXToolProbePosition.." Y"..fYToolProbePosition)
    local toollen = mc.mcToolGetData(finst, mc.MTOOL_MILL_HEIGHT, ftool)
    if toollen == 0 then
        toollen = fDefaultToolLength
        mc.mcCntlSetLastError(finst, "Tool length not found - using Default Length")
    end
    local probestart = fColletAtProbeZCoordinate + fExtraProbeDistance + toollen
    local GCODE = "G91 G31 G0 Z"..probestart.." F"..fProbePrepSpeed
    GCODE = ""..GCODE.." \n G91 G0 Z1 F"..fProbePrepSpeed.." \n G91 G31 Z"..fProbeOperationDistance.." F"..fProbeSpeed
    mc.mcCntlGcodeExecuteWait(finst,GCODE)
end

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

Hi, where do i set up manual toolchange position and fixed probe position ? Cant locate it in your script
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: gene8522 on January 11, 2018, 07:49:50 PM
Is this post dead? Or can I still get a response to a question?
Gene
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: DazTheGas on January 12, 2018, 02:21:37 AM
Mach4 has come on a long way since making these videos and lots of new commands added, there will be an updated video soon on the way i now do it but still ask away  ;)

DazTheGas
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: gene8522 on January 12, 2018, 09:20:28 AM
Thanks for the reply. I have been running Mach3 for about 7 years W/ Screenset2010 on my diy CNC without many problems. Now for some unknown reason, while running a gcode file, about every two minutes I keep getting an error code (error 3336) pop-up that shuts the program down. ArtSoft technicians dosen't know what to do about it. So I'm trying to install Mach4 V2 to see if it will correct these problem. Screenset 2010 has an M6 manual tool change that I would like to use with Mach4, but Mach4 will not run the 2010 screensets. I was wondering if it would be possible to get your latest M6 code and help getting it into my Mach4? 
Thanks in advance for your help. If it wasn't for these forums I would never have my DIY CNC working as well as it does.
Gene 
P.S. I don't have Mach4 completely installed yet, trying to get all of the settings just right is a pain you know where >:( ??? >:D
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Firechief on January 12, 2018, 10:46:59 AM
I will be looking forward to the new video. I have your tool change run at this time.
Thanks.
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: lesspaul on June 12, 2018, 06:30:01 PM
Here's hoping this update is still in the works. Thanks!
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: DazTheGas on June 13, 2018, 05:24:00 PM
Yep still in the pipeline, just have to get machine finished first ;-)

DazTheGas
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: KatzYaakov on June 26, 2018, 12:02:15 PM
https://www.youtube.com/watch?v=uxeQrFIWq8U

change tool with servo magazine with mach 4
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: lsgreen on July 08, 2018, 03:14:51 PM
Greetings to all,
I’ve installed the m6 script on my machine, (thanks for everyone’s hard work), each time it runs the message boxes remain hidden. Obviously sense they can’t be accessed, it’s not possible to complete the routine. The only thing left to do is close Mach4 down. After Mach has closed the message boxes then appear allowing them to be closed also. The other messages in Mach appear to work normally. If an m6 command is in g code the machine will retract the z, move to the tool change position etc. If the command is issued in the MDI, nothing happens but it is apparent that Mach is in a wait condition, waiting for input from the message box. I’m sure there is a simple answer for this, I just can’t find it.
Thanks, Lou
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: rajdzos on October 07, 2018, 03:03:01 PM
Just adding a thankyou! :)

I Made some Modifications
- Probemove for approach probe to avoid Crash :) and back off probe before real probing.
- Lots of Variables to tune the script
---Preset for probelocation
---Preset for ToolChange position
---Preset for defaults and speeds


Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local changeToTool = 3--mc.mcToolGetSelected(inst)
    local changeFromTool = 2--mc.mcToolGetCurrent(inst)
    local XPositionBeforeToolChange = mc.mcAxisGetPos(inst,0)
    local YPositionBeforeToolChange = mc.mcAxisGetPos(inst,1)
    local XToolProbePosition = "1"
    local YToolProbePosition = "1"
    local XManualToolChangePosition = "2"
    local YManualToolChangePosition = "2"
    local ColletAtProbeZCoordinate = -103 -- Machine Z-coordinate when collet tip touches TouchPlate (Must be more than ProbeOperationDistance - DefaultToolLength
    local ExtraProbeDistance = 5 -- SafetyMargin
    local ProbeOperationDistance = -30 -- Length of Probemove before giving up
    local ProbePrepSpeed = 100
    local ProbeSpeed = 25
    local DefaultToolLength = 70 -- Used if tool info is not found. (Should be a value slightly longer than the longest tool in the shop :D)
        -- QUICK REFERENCE
        -- G90 - Absolute (Go to coordinate)
        -- G91 - Incremental (Godistance along axis from current position)
        -- G53 - Machine Coordinate Move

    if changeToTool == changeFromTool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0\nM5" )
    RunProbe(inst,changeFromTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed)
    local ToolZCoordinate = mc.mcAxisGetPos(inst,2)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n X"..XManualToolChangePosition.." Y"..YManualToolChangePosition)
    local changeToToolDescription = mc.mcToolGetDesc(inst,changeToTool)
    wx.wxMessageBox("Please change to tool number "..changeToTool.." "..changeToToolDescription.." and press ok to continue")
    RunProbe(inst,changeToTool,XToolProbePosition,YToolProbePosition,DefaultToolLength,ColletAtProbeZCoordinate,ExtraProbeDistance,ProbePrepSpeed,ProbeSpeed)
    mc.mcAxisSetPos(inst, 2 , ToolZCoordinate)
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..XPositionBeforeToolChange.." Y"..YPositionBeforeToolChange)
    mc.mcToolSetCurrent(inst, changeToTool)
    wx.wxMessageBox("If Toolchange was Sucessful - click ok to continue")
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end

function RunProbe(finst,ftool,fXToolProbePosition,fYToolProbePosition,fDefaultToolLength,fColletAtProbeZCoordinate,fExtraProbeDistance,fProbePrepSpeed,fProbeSpeed)
    mc.mcCntlGcodeExecuteWait(finst, "G90 G53 G0 X"..fXToolProbePosition.." Y"..fYToolProbePosition)
    local toollen = mc.mcToolGetData(finst, mc.MTOOL_MILL_HEIGHT, ftool)
    if toollen == 0 then toollen = fDefaultToolLength end
    mc.mcCntlSetLastError(finst, "Tool length not found - using Default Length")
    local probestart = fColletAtProbeZCoordinate + fExtraProbeDistance + toollen
    local GCODE = "G90 G53 G31 G0 Z"..probestart.." F"..fProbePrepSpeed
    GCODE = ""..GCODE.." \n G91 G0 Z5 F"..fProbePrepSpeed.." \n G91 G31 Z-15 F"..fProbeSpeed
    mc.mcCntlGcodeExecuteWait(finst,GCODE)
end

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

how i define probeposition?
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: struechi on April 15, 2019, 01:57:00 PM
Hello,

A big thank you to all,
Had until a few days still no idea of macro programming but there are very helpful videos and forums =)

The M6 version of DazTheGas works very well, just got it adapted to my machine.
I also understand the processes

But now I have a problem / question:
Is it possible not to adjust the Z position in the fixture table, but to adjust the tool length in the tool table.

For me it is more logical if the fixture position in Z is 0 and the height changes with the tool length.
Do I have a thinking mistake or is that a possible solution?

Does anyone happen to have such a solution?

I've tried it but can not come to a solution

Thank you
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: DazTheGas on April 15, 2019, 04:34:34 PM
At the time of creating the M6 Macro the tool table was limited, but as time has progressed so has mach4 and the tool table. You now have the ability to create custom user fields, this makes things much more easier and expandable.

lets say in the tool table you were to create a custom field called m6Height and make this a float value,

instead of using "toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, tool)"  you would use instead "toollen = mc.mcToolGetDataExDbl(inst,   tool,   "m6Height")

Hope that makes sense and what you were looking for...

DazTheGas
Title: Re: Creating an M6 Toolchange in Mach4 (Part 3)
Post by: Veronica56 on September 21, 2019, 01:32:16 AM
Hello, I wanted to thank you for this post, using your macro as a reference and knowing like, literally no G Code or LUA I was able to get a manual toolchange with automatic touchoff working.