Hello Guest it is June 14, 2025, 05:55:59 PM

Author Topic: ATC Build With Macros - Use it if you like  (Read 11471 times)

0 Members and 1 Guest are viewing this topic.

Re: ATC Build With Macros - Use it if you like
« Reply #20 on: January 25, 2025, 01:37:20 PM »
OK, it wrote me the following M6 script that basically uses the pocket number that is referenced to the tool #.  I like this alot.  super minimal and streamlined.

Code: [Select]
function m6()
    local inst = mc.mcGetInstance()

    -- Get the selected tool and current tool
    local selectedTool = mc.mcToolGetSelected(inst) -- Tool requested by T# command
    local currentTool = mc.mcToolGetCurrent(inst)   -- Tool currently in the spindle

    -- If the selected tool is the same as the current tool, no tool change is needed
    if selectedTool == currentTool then
        mc.mcCntlSetLastError(inst, string.format("Tool %d is already loaded.", currentTool))
        return
    end

    -- Get the Pocket # for the selected tool from the Tool Table
    local pocket = mc.mcToolGetData(inst, mc.MTOOL_POCKET, selectedTool)

    if not pocket or pocket <= 0 then
        mc.mcCntlSetLastError(inst, string.format("Error: No pocket assigned for Tool %d.", selectedTool))
        return
    end

    -- Display a message about the tool change
    mc.mcCntlSetLastError(inst, string.format("Changing to Tool %d from Pocket %d.", selectedTool, pocket))

    -- Move to a safe position for tool change
    mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 Z0") -- Move Z-axis to machine home (modify as needed)
    mc.mcCntlGcodeExecuteWait(inst, "G90 G53 G0 X0 Y0") -- Move to tool change position (adjust coordinates)

    -- Simulate tool change logic
    -- If you have an ATC (Automatic Tool Changer), you would insert code here to control the ATC
    -- Example: Send commands to move the tool changer to the correct pocket and load the tool
    mc.mcCntlSetLastError(inst, string.format("Loading Tool %d from Pocket %d...", selectedTool, pocket))

    -- Set the selected tool as the current tool
    mc.mcToolSetCurrent(inst, selectedTool)
end

if (mc.mcInEditor() == 1) then
    m6() -- Execute the function if running in the Mach4 script editor
end
Re: ATC Build With Macros - Use it if you like
« Reply #21 on: January 25, 2025, 01:41:32 PM »
I did not see the Pocket# .   I enable the additional fields - And there it was.    Obviously, there is no M6 functionally in Mach to use this in a custom ATC.   This is only a column in a DB.  That can store the pocket if the tool is loaded.  You would still need a DB to store the Pocket X,Y,Z etc.   

 I will give this a day or 2 to brew in my head if I want to go that way.    If there is an easy way to "search" the tool table to get all the tools with a pocket value assigned I might use it.     My gut tells me I will stay with my own DB.  I would like to visualize my tool rack.    If that makes sense.    But yes, definitely worth looking into.    I would prefer to assign tools to pockets,  and not pockets to tools.   

   
Re: ATC Build With Macros - Use it if you like
« Reply #22 on: January 25, 2025, 01:45:00 PM »
I wonder if I can get the tool number from a script, if I provide the pocket#.   That would make it worth it form me ... let me go try ....
Re: ATC Build With Macros - Use it if you like
« Reply #23 on: January 25, 2025, 01:53:31 PM »
I will be able to adjust my screen script, to scan the tool DB and update my screen to show me the loaded tools in my rack.  Will tweak the scripts slightly to update the pockets.  Should work great!!  Thanks a mil for pointed out the pocket.
Re: ATC Build With Macros - Use it if you like
« Reply #24 on: January 25, 2025, 02:08:17 PM »
My next step will be to make an editable tool table tab that shows the 10 tools loaded into the carousel

Re: ATC Build With Macros - Use it if you like
« Reply #25 on: January 25, 2025, 02:11:07 PM »
On it already . hehe
Re: ATC Build With Macros - Use it if you like
« Reply #26 on: January 25, 2025, 02:11:23 PM »
Luckily for me this makes things super easy because I can now just use the pocket # instead of the tool# in all of my functions for the toolchanger (my carousel tool changer functions had tool# mapped to carousel positions 1-10 previously, so I change 2 lines of code and it all works as intended! super lucky!)
Re: ATC Build With Macros - Use it if you like
« Reply #27 on: January 25, 2025, 02:12:09 PM »
Yes, that screen was basically a cut and paste of yours with some mods  :)
Re: ATC Build With Macros - Use it if you like
« Reply #28 on: January 25, 2025, 02:13:57 PM »
chaztGPT also gave me some code to recreate the actual editable tool table window in a tab but I haven't tried it out yet.  That's where this all started.
Re: ATC Build With Macros - Use it if you like
« Reply #29 on: January 25, 2025, 02:23:20 PM »
You screen looks impressive -  We will all be out of jobs one day.. thank you AI