M6 Manual tool Change with Auto Tool setting Mach 4

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024
  • M6 manual tool change with tool length auto setter. Written in LUA, I am a novice at best, so any advice is welcomed.
    This macro pauses the G code, moves to a position to make the tool change then moves to the tool setter and inputs tool length into the tool table in Mach 4.
    I did my best to explain things as I understand them, unfortunately that isn't very well.
    I hope this helps someone out there .
    Script;
    function m6()
    local inst = mc.mcGetInstance() ;
    local currentTool = mc.mcToolGetCurrent(inst)
    local selectedTool = mc.mcToolGetSelected(inst)
    local posmode = mc.mcCntlGetPoundVar(inst, mc.SV_MOD_GROUP_3) --get the current mode so we can return to it when macro ends
    --Get positions before moving to do tool change
    local valX, rc = mc.mcAxisGetMachinePos(inst, mc.X_AXIS) --Get the position of the X axis in Machine Position
    local valY, rc = mc.mcAxisGetMachinePos(inst, mc.Y_AXIS) --Get the position of the Y axis in Machine Position
    local valZ, rc = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS) --Get the position of the Z axis in Machine Position

    if selectedTool == currentTool then
    return
    mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
    else

    mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z0.0");--Move the Z axis all the way up
    mc.mcCntlGcodeExecute(inst, "G53 X10 y0");--Move the X axis to the middle and Y axis to the end and
    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
    mc.mcCntlGcodeExecute(inst, "G53 G01 X2.6042 y-0.5357 f350");--Move the X axis and Y axis to the tool setter
    mc.mcCntlGcodeExecute(inst, "G53 G0 z-5")--Moves the z axis down 5 inches rapid


    mc.mcCntlGcodeExecute(inst, "g53 G31 z-9 f15")--Probes z axis to the tool setter
    mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. " Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
    mc.mcToolSetCurrent(inst, selectedTool) --sets the current tool displayed in mach to the selected tool
    --local probedzW = mc.mcAxisGetPos(inst, 2) --This would give 0 axis (z on my machine) coordinates in work coordinate syste, ive shown it just for educational purposes
    local probedz = mc.mcCntlGetPoundVar(inst, 5073) --this retreives the Saved varible of the z position (#5073) in machine coordinates and assigns it to the name probedz
    local ToolLength = math.abs(9.5238 + probedz) -- this calculates the value of the tool lenght by using a gage line off of my spindle to the tool setter. uses the absolute value fuction
    mc.mcCntlSetLastError(inst, "Tool Length" .. tostring(ToolLength))
    mc.mcToolSetData(inst, mc.MTOOL_MILL_HEIGHT, selectedTool, ToolLength) --- this sets the tool length value into the tool table into the selected tool position number, Note - i havent reassigned current tool varible so i have to use the "selectedTool" name
    mc.mcCntlGcodeExecute(inst, "G04 p.5")
    mc.mcCntlGcodeExecute(inst, "G90 G53 G1 Z0 F80") --Retract back to Z home
    local MyChoice = wx.wxMessageBox("Remove Probe Clip","Click OK to continue" , 16) -- brings up a dialog box and waits for a selection to proceed
    if (MyChoice == 16) then --16 is cancel
    rc = mc.mcCntlSetLastError(inst, 'probing.')
    return
    elseif (MyChoice == 4) then
    mc.mcCntlGcodeExecute(inst, string.format('G ' .. posmode))--return to pre macro mode G90, or G91
    mc.mcCntlGcodeExecute(inst, "G90 G53 G0 X" .. tonumber(valX) .. "Y" .. tonumber(valY)) --Move back to X & Y initial location
    mc.mcCntlGcodeExecute(inst, "G90 G53 G0 Z" .. tonumber(valZ)) --Move back to Z initial location
    mc.mcCntlSetLastError(inst, "Tool Change Complete H ".. tostring(selectedTool) .. " set to ".. tostring(ToolLength).." inches")
    end

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

Комментарии • 16

  • @Mastermodeler.
    @Mastermodeler. 6 месяцев назад

    Absolutely invaluable information. Thank you for sharing. It was worth a subscribe!

  • @skorkmaz
    @skorkmaz 2 года назад +1

    Your code helped me workaround a stupid Mach4 bug. Thanks.

  • @outlawlabs8051
    @outlawlabs8051 3 года назад +1

    super helpful, thank you for this

  • @justice_for_juicy4179
    @justice_for_juicy4179 2 года назад +2

    I think I figured out the correct process.... If I force a T1M6 in mdi after homing, I get a positive tool value for T1.... activate tool height offsets.....then locate work 0's while active..... Then T2M6 is called, the script runs as it should(need to dial in my gage line offset value) and T2 is populated in table and code proceeds at correct offset.... Phew. If I forget again its atleast saved here. Lol. I marked on machine also just incase. Now I need to this Chinese tool Setter and see if it is more accurate and reliable than my homemade setter.

    • @kthobbycncmillingmachine9250
      @kthobbycncmillingmachine9250 2 года назад

      can you make video so we can watch. where to do. Thanks 👍👍

    • @kthobbycncmillingmachine9250
      @kthobbycncmillingmachine9250 2 года назад

      I have problems with this too

    • @justice_for_juicy4179
      @justice_for_juicy4179 2 года назад

      @@kthobbycncmillingmachine9250 I got mine pretty dialed in and wrote down work flow so I wouldn't mess it up. 100% confusing to figure out spiddle line height to I out for offset. But the code given is exactly what everyone wants and can't find. Manually change the tool and automatically probe to calculate tool offset... Input new data in table and then proceed with code.... Without need to probe work after initial work offset.

  • @xvolodea
    @xvolodea 2 года назад

    Thanks for your nice work. Can this macro be used in Mach3 ?

  • @justice_for_juicy4179
    @justice_for_juicy4179 3 года назад

    This is exactly what I need and have been struggling with for weeks to figure out. So far, I can your script to raise z, move to probe location, tool change, probe, and move back as it should.... However the tool offset isn't being calculated correctly.
    Right now it skips m6 for T1 at beginning, do I need to probe T1?
    What is importance of gage line measurement? Can it be any number to do the math with?
    I've broken my brain could you please help?

    • @accidentaltradesman5139
      @accidentaltradesman5139  2 года назад

      Sorry I just saw this. Let me read through this and I’ll get back to you!

    • @justice_for_juicy4179
      @justice_for_juicy4179 2 года назад

      @@accidentaltradesman5139 thanks for checking. what is your workflow. im working on it again and cant recall how i got it to work. maybe change tool to T2 once Gcode is loaded....then once it starts T1 M6 gets T1 into the table, but do not use H1? but us H2,H3... in subsequent T_M6 changes? i have tried it without H1 in the code yet. when H1 is used the T2 offset is way above the work. like 1.5 inch or so(prob the length of T1)

  • @people16vt
    @people16vt 2 года назад

    Hello , i am trying to get it work but having troubles , if my current tool is T8 and i call T4M6 or different tool numbers it always go down on my touch plate and change only the T2 lenght offsets . if i try again it is not doing it for the next tool like T3 , always changing the T2 height and always T2 is now CurrentTool . When current tool is the T2 and i call in T1M6 it says "its the same tool selected so not doing anything"
    i am having such a blast playing with the scripts in Mach4 , i was alot better on Mach3 before ....

    • @accidentaltradesman5139
      @accidentaltradesman5139  2 года назад

      Check the general tab on settings. Make sure the “tool change in same line” (or something like that) is checked

  • @keithkuthan2701
    @keithkuthan2701 3 года назад

    Any chance you would share the script?