584,841 active members*
4,467 visitors online*
Register for free
Login
Results 1 to 19 of 19
  1. #1
    Join Date
    Oct 2005
    Posts
    225

    NewFangled Tool Length Macro Help

    I am having trouble with the auto tool setter that is posted on youtube and would like to know what I am doing wrong. I have searched all over the WWW to no avail. I am using the macro below and it does not input the correct tool length. I believe it is because the macro needs to know how tall my tool setter is but I do not know where to include that information in the macro. The rest of the macro works fine but the lengths are wrong. My "Z" axis cuts are all over the place. I also don't know if I need to use tool length comp or not. I have an ER20 collet so I do not have repeatable lengths. THe master tool doesn't seem to help but I may be doing that wrong also.

    Can someone help me?



    function m6()

    local inst = mc.mcGetInstance()

    ----------------------------------------------------------------------------------
    --change lines here to either auto rapid, or manually jog to a tool change position
    ----------------------------------------------------------------------------------
    --Manual Lines. Uncomment line below to allow you to manually jog to a tool change position.
    --local MyChoice = wx.wxMessageBox("Click OK, \nThen Jog to A Safe Tool Change Position,\nInsert New tool,\nThen Click Cycle Start.","Click OK to continue" , 16)
    ---------------------------------------------------------------------------------
    --Auto Lines. Uncomment both lines below (and comment out local MyChoice line above) to automatically move to tool change position.
    --Edit to include the machine coordinate values of that tool change position.

    --AUTO LINES
    --mc.mcCntlGcodeExecuteWait(inst, "G53 G0 Z0\nG53 G0 X14.7148 Y-22.713")--Move the Z to Home.Then to the X, Y Coords for our touch pad.
    --mc.mcCntlSetLastError(inst, 'Now in Tool Change Position. Hit Cycle Start!')
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
    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.mcCntlToolChangeManual(inst, true);
    mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. " Previous Tool == " .. tostring(currenttool))
    mc.mcToolSetCurrent(inst, selectedtool)

    local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
    mc.mcCntlSetLastError(inst, "Probing in Progress!")
    mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F5.")--probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
    mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
    mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z0 ")--Retract

    local NewOffset = probedz
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
    wx.wxMessageBox("Toolchange Complete.\nTLO Set")
    end

    end

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

  2. #2
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    I'm not sure where or why your code is failing but in all the code you've posted you've done absolutely no error checking....and that's spells trouble.

    Have a look at all the Lua APIs...like this example:

    Code:
    LUA Syntax: 
    retval, rc = mc.mcCntlGetLocalVar(
    		number mInst, 
    		number hVars, 
    		number varNumber)


    Note that the function has two outputs, retval (return value) and rc (return code). You should test the return code for error for each and EVERY API call....after all thats what they are
    for. If you don't test each return code how do you know that the function executed?

    Craig

  3. #3
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    I know nothing about Lua or any other coding for that matter. The macro came straight from New Fangled Solutions and I think the only thing wrong is the code does not know how tall my touch off block is.

  4. #4
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    look at the probing code:
    Code:
    mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F5.")--probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
    and then look at how the ToolTable gets updated a few lines later:
    Code:
    local NewOffset = probedz
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
    There is no calculation provide for the touch-off block height. If you want one you could add it simply enough.

    Craig

  5. #5
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    If I new how to add something I would. As I mentioned earlier I know nothing about Lua or any other coding so I cannot add it. I am asking for help to make this work right.
    I am getting the idea that trying to get this to work without fixed tool lengths may be impossible.

  6. #6
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    just add, or is it subtract? the gauge block height
    Code:
    local NewOffset = probedz
    would become
    Code:
    local GageBlockHeight=0.5  -- substitute whatever number, in whatever units
    local NewOffset = probedz-GageBlockHeight
    This is not rocket science......if you want to mess around with the internals of Mach4 then a modest knowledge of Lua is required.

    If you want to be able to vary the gage block height at will you can do so with a wxWidgets dialog box to populate GaugeBlockHeight variable,
    that becomes a little harder.

    Craig

  7. #7
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    Thanks joeaverage

    I must be doing something else wrong ! I put this in:

    function m6()

    local inst = mc.mcGetInstance()

    ----------------------------------------------------------------------------------
    --change lines here to either auto rapid, or manually jog to a tool change position
    ----------------------------------------------------------------------------------
    --Manual Lines. Uncomment line below to allow you to manually jog to a tool change position.
    --local MyChoice = wx.wxMessageBox("Click OK, \nThen Jog to A Safe Tool Change Position,\nInsert New tool,\nThen Click Cycle Start.","Click OK to continue" , 16)
    ---------------------------------------------------------------------------------
    --Auto Lines. Uncomment both lines below (and comment out local MyChoice line above) to automatically move to tool change position.
    --Edit to include the machine coordinate values of that tool change position.

    --AUTO LINES
    mc.mcCntlGcodeExecuteWait(inst, "G53 G0 Z-1.5\nG53 G0 X6 Y6")--Move the Z to Home.Then to the X, Y Coords for our touch pad.
    mc.mcCntlSetLastError(inst, 'Now in Tool Change Position. Hit Cycle Start!')
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
    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.mcCntlToolChangeManual(inst, true);
    mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. " Previous Tool == " .. tostring(currenttool))
    mc.mcToolSetCurrent(inst, selectedtool)

    local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
    mc.mcCntlSetLastError(inst, "Probing in Progress!")
    mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F6.5")--probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
    mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
    mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z-1.5 ")--Retract

    local GageBlockHeight=.394 --Gage Block Height
    local NewOffset = probedz-GageBlockHeight
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
    wx.wxMessageBox("Toolchange Complete.\nTLO Set")
    end

    end

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



    and every time I do a tool change
    t4 m6
    g43 h4 (for example)
    I get inconsistent tool lengths. If I change the tool lengths by about .25 shorter or longer the finish probed length will be an inch more or less different, not the .25 inch I changed it.
    I can run a basic mdi or program with very accurate "Z" movement, even if I move the "Z" up and down 3 inches in four or 5 moves it still repeats back to zero perfectly.
    Is there something in the setup procedure that I am missing. This machine is a chinese machine running ess board and runs very well with just one tool. I am wanting to step up to running multiple tools in one program using an ER20 collet.

    Thanks again,
    Tommy

  8. #8
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    I am also wondering what this means

    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))

    Especially: Offset = %.4f

  9. #9
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    one of the Goto ways of diagnosing mal-conformed scripts is to use either the Status Bar or a wxMessageBox as output at various places through the script.

    For example:

    Code:
    mc.mcCntlSetLastError(inst, "Probing in Progress!")
    mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F6.5")--probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
    wx.wxMessagebox("probedz= ",toString(probedz))
    mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
    mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z-1.5 ")--Retract
    
    local GageBlockHeight=.394 --Gage Block Height
    local NewOffset = probedz-GageBlockHeight
    wx.wxMessagebox("NewOffset= ",toString(NewOffset))
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
    wx.wxMessageBox("Toolchange Complete.\nTLO Set")
    With these two wxMessagbox(es) you should be able to confirm the raw probed height and then compare that to the NewOffset which should be (probedz-GagaBlockHeight)

    Craig

  10. #10
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    I will give this a try today.
    can you tell me what this statement means?

    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))

    Tommy

  11. #11

    Re: NewFangled Tool Length Macro Help

    It's sending a text message to your UI screen in the error message section rather than as a popup message.

    In Mach4 default UI that's on the bottom and it typically reads the current status. The messages are like when you ref all a is home and you get the popup at the end that the homing is complete.

  12. #12
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    Gotcha!

  13. #13
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    I tried the code you suggested with the wxmessagebox and I must of put it in wrong because after it touch my probe the machine stopped and would not complete the g31. After many more tries with the prior macro I come to the conclusion that I do not have the knowledge to get it working so I am back to just one tool Tommy and touch ecah one manually with the touch button on Mach 4 and by the way the standard touch button in mach4 for material top and tool length works fine but if the tool length changes the start getting very unpredictable. So now I am going to try and get a macro for g31 to just set material top or bottom with an adjustable probe so I can adjust it up or down to the thickness of my material.

    Thanks for the help though.

  14. #14
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    unlike a status bar message (mcCntlSetLastError(inst, string.f....etc) a wxMessageBox message will stop execution UNTIL the message box is dismissed.

    That's why I chose it, and it should not interfere with any probing event....it occurs outside of any time critical event.

    You need to open ZeroBraneEditor and single step through the macro.

    Craig

  15. #15
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    look at the code:
    Code:
    local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
    mc.mcCntlSetLastError(inst, "Probing in Progress!")
    mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F6.5")--probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
    The local probedz=mc.mcCntlGetPoundVariable(..... etc occurs AFTER the g31 probe move. If the probe move is not completing its not
    the wxMessageBox statement.

    As I posted earlier you need to single step through the macro, its not helped that none of the API return codes have been tested.

    Craig

  16. #16
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    I do not know how to use zero brain editor and I also do not know what an API is!!

    This code runs perfect but after probing the material top is off buy an inch or more. I have tried altering gage block height to make the adjustment but when I change the length of the tool (putting a fixed length gage block under tool) the returned tool height is completely different, not the expected gage block difference.

    function m6()

    local inst = mc.mcGetInstance()

    ----------------------------------------------------------------------------------
    --change lines here to either auto rapid, or manually jog to a tool change position
    ----------------------------------------------------------------------------------
    --Manual Lines. Uncomment line below to allow you to manually jog to a tool change position.
    --local MyChoice = wx.wxMessageBox("Click OK, \nThen Jog to A Safe Tool Change Position,\nInsert New tool,\nThen Click Cycle Start.","Click OK to continue" , 16)
    ---------------------------------------------------------------------------------
    --Auto Lines. Uncomment both lines below (and comment out local MyChoice line above) to automatically move to tool change position.
    --Edit to include the machine coordinate values of that tool change position.

    --AUTO LINES
    mc.mcCntlGcodeExecuteWait(inst, "G53 G0 Z-1.5\nG53 G0 X6 Y6")--Move the Z to Home.Then to the X, Y Coords for our touch pad.
    mc.mcCntlSetLastError(inst, 'Now in Tool Change Position. Hit Cycle Start!')
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
    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.mcCntlToolChangeManual(inst, true);
    mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedtool) .. " Previous Tool == " .. tostring(currenttool))
    mc.mcToolSetCurrent(inst, selectedtool)

    local MyChoice = wx.wxMessageBox("Click Ok to Begin Probing the New Tool","Click OK to continue" , 16)
    mc.mcCntlSetLastError(inst, "Probing in Progress!")
    mc.mcCntlGcodeExecuteWait(inst, " G91 G31 Z-5. F6.5")--probe the new tool
    local probedz = mc.mcCntlGetPoundVar(inst, mc.SV_PROBE_POS_Z) -- Z Probe position in Machine coords
    wx.wxMessagebox("probedz= ",toString(probedz))
    mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
    mc.mcCntlGcodeExecuteWait(inst, "G00 G53 Z-1.5 ")--Retract

    local GageBlockHeight=.394 --Gage Block Height
    local NewOffset = probedz-GageBlockHeight
    wx.wxMessagebox("NewOffset= ",toString(NewOffset))
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool, NewOffset)
    mc.mcCntlSetLastError(inst, string.format("Auto tool setting complete, Offset = %.4f", NewOffset))
    wx.wxMessageBox("Toolchange Complete.\nTLO Set")
    end

    end

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

  17. #17
    Join Date
    Nov 2013
    Posts
    4280

    Re: NewFangled Tool Length Macro Help

    Hi,
    I don't think you have much choice but to learn.

    One of the real strengths of Mach4 is that you can write custom code to do a wide variety of tasks.....the weakness of Mach4 is that you can write custom code!!!
    The flexibility comes at a cost and the cost is learning the basics of Lua, Machs API and modular structure. It might seem daunting at first but the sense of satisfaction
    that comes from doing so is imense....aside from being able to write your own code!

    This code runs perfect but after probing the material top is off buy an inch or more.
    I think that's your fault right there, the parameters of the g31 probe move are wrong and consequently the move is not completing correctly and thereafter it 's all rubbish.

    API=Appilcation Program Interface.

    All the codes like mc.mcCntlSetLastError() are an API....its the means that you use to get Mach4s core to do a specific thing. Look in Mach4Hobby/Docs/Mach4CoreAPI.chm
    or open Mach4CoreAPI from the HelpDocuments button from Mach's screen. There are hundreds of APIs for every conceivable purpose.

    If you open the script editor from the Edit/DebugScript option of the Operator tab menu the ZeroBraneEditor will open and you can scan around for m6.mcs. With the editor you can
    single step through the code.

    Alternately you can open the editor from the OpenScriptEditor option of the Operator tab menu and scan up the file tree until you find m6.mcs and run it in single step from there.

    Craig

  18. #18
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    After all of the trouble I think I got it working thanks to you. I will put it to the test tomorrow and see.

    Thanks

  19. #19
    Join Date
    Oct 2005
    Posts
    225

    Re: NewFangled Tool Length Macro Help

    I run some complete g code for testing and to make Mach 4 have the right Tool Height I had to G49 in MDI before every tool change. Mach 4 does not read the new off set it looks like it reads the old or original offset. Is this a setting in Mach 4 or do I just edit my Post to add G49 say after the rapid to clearance plane? The only setting I can find is T on M6 line is next tool or tool in use and I have it set as tool in use because Mach would just skip over the tool change command.

    G-Code
    (0.394 DRILL)
    N01T29M06
    N02S10000M03M08
    N03G0G90G54X3.Y3.
    N04G0 G43H29Z1.M08
    N05G1Z0.750F52.
    N06G0Z1.
    N07M09
    N08M05
    N09M00
    (0.375 DRILL)
    N10T14M06
    N11S11000M03
    N12G0G90G54X1.5Y1.5
    N13G0 G43H14Z1.M08
    N14G1Z0.750F52
    N15G0Z1.
    N16M09
    N17M05
    N18M00
    (0.125 DRILL)
    N19T28M06
    N20S13000M03
    N21G0G90G54X4.5Y1.5
    N22G0 G43H28Z1.M08
    N23G1Z0.750F52.
    N24G0Z1.
    N25M09
    N26M05
    N45M30
    %

    Thanks,
    Tommy

Similar Threads

  1. Tool length offset macro
    By ChippyMcChip in forum Fanuc
    Replies: 4
    Last Post: 01-17-2018, 11:09 AM
  2. Need help with Macro for checking tool length before tool change
    By mioduz in forum Tormach Personal CNC Mill
    Replies: 11
    Last Post: 04-18-2014, 08:43 PM
  3. In Need of a macro for checking tool length
    By mioduz in forum Mach Wizards, Macros, & Addons
    Replies: 0
    Last Post: 04-16-2014, 08:20 PM
  4. macro variable for mazatrol tool length
    By kendo in forum Mazak, Mitsubishi, Mazatrol
    Replies: 9
    Last Post: 08-24-2011, 05:13 PM
  5. makino automatic tool length presetter macro
    By PETE1968 in forum Uncategorised MetalWorking Machines
    Replies: 0
    Last Post: 12-08-2010, 09:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •