Hello Guest it is April 28, 2024, 05:04:08 PM

Author Topic: ATC Macro adjustment for reversed tool forks  (Read 833 times)

0 Members and 1 Guest are viewing this topic.

Offline JtheB

*
  •  35 35
    • View Profile
ATC Macro adjustment for reversed tool forks
« on: February 01, 2023, 05:41:30 PM »
Set my tool magazine up facing rearward to play nice with the dust boot.
Tool changes work great.... except when followed by an actual toolpath.
The spindle grabs the requested tool, YSlides 2.00", then goes up to Z-Home.
But then immediately back down the Z axis to magazine level (approx), powers up and heads straight for the first cut...  smashing into the  magazine....
I need to add an additional macro command to traverse about Y -10.00" to clear the tool magazine before dropping in to make the first cut. This is my first venture into macros.....  but hey, I made it this far, yeah?

Um, help?

Thank you kind & wise people.
Re: ATC Macro adjustment for reversed tool forks
« Reply #1 on: February 01, 2023, 05:50:45 PM »
Hi,
you'll have to post the code you are using already.

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

Offline JtheB

*
  •  35 35
    • View Profile
Re: ATC Macro adjustment for reversed tool forks
« Reply #2 on: February 01, 2023, 05:57:44 PM »
function m6()
   
 local inst=mc.mcGetInstance()
 mc.mcCntlSetLastError(inst, 'Tool change in progress again')
 
 
 ------ Get and compare next and current tools ------
 local SelectedTool = mc.mcToolGetSelected(inst)
 local CurrentTool = mc.mcToolGetCurrent(inst)
 if (SelectedTool == CurrentTool) then
 mc.mcCntlSetLastError(inst, "Next tool = Current tool")
 do return end
end
mc.mcCntlSetLastError(inst, 'Break 0')

--[[
-- Define slide distance and direction ------

Only 1 of these should have a non-zero value
 Changing from a positive to negative slide value, or vice-versa,
 will change the direction that the tool slides into the tool fork
 ]]

 local XSlide = 0.00 -- X direction does not move
 local YSlide = -2.00 -- Slides into the fork in the +Y direction
 local dwell = 5.00  -- Duration of time the spindle rests for the drawbar to engage or disengage
 
------- Declare Position Variables ------
 local XPos = 0
 local YPos = 0
 local ZPos = 0
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Defining Tool Station Position Variables, this is the only place fork X, Y, Z values need to edited. --
-- IF additional fork locations are need, there are three locations that will need to be editing.       --
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --
-- !!!!!!!!!!!!!!!!!                                                                !!!!!!!!!!!!!!!!!!! --
-- !!!!!!!!!!!!!!!!!  Important: Tool positions are entered as MACHINE CORRDINATES  !!!!!!!!!!!!!!!!!!! --
-- !!!!!!!!!!!!!!!!!                                                                !!!!!!!!!!!!!!!!!!! --
-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------

-----------------------------------------------
----- Defining Tool Station Postions (section 1) ------
-----------------------------------------------

--Tool Station 01--
    local ToolPos_1_X = 1.6906
    local ToolPos_1_Y = 95.9000
    local ToolPos_1_Z = -8.400

--Tool Station 02--
    local ToolPos_2_X = 6.2449
    local ToolPos_2_Y = 95.9000
    local ToolPos_2_Z = -8.400

--Tool Station 03--
    local ToolPos_3_X = 10.8208
    local ToolPos_3_Y = 95.9000
    local ToolPos_3_Z = -8.400

--Tool Station 04--
    local ToolPos_4_X = 15.4052
    local ToolPos_4_Y = 95.9000
    local ToolPos_4_Z = -8.400

--Tool Station 05--
    local ToolPos_5_X = 19.989
    local ToolPos_5_Y = 95.9000
    local ToolPos_5_Z = -8.400

--Tool Station 06--
    local ToolPos_6_X = 24.5744
    local ToolPos_6_Y = 95.9000
    local ToolPos_6_Z = -8.400

--Tool Station 07--
    local ToolPos_7_X = 29.1363
    local ToolPos_7_Y = 95.9000
    local ToolPos_7_Z = -8.4000

--Tool Station 08--
    local ToolPos_8_X = 33.6982
    local ToolPos_8_Y = 95.9000
    local ToolPos_8_Z = -8.4000

--Tool Station 09--
    local ToolPos_9_X = 38.2677
    local ToolPos_9_Y = 95.9000
    local ToolPos_9_Z = -8.4000

--Tool Station 10--
    local ToolPos_10_X = 42.8452
    local ToolPos_10_Y = 95.9000
    local ToolPos_10_Z = -8.4000
--[[
To add more tool station positions, copy the code below and paste it after your last
active tool station position. Don't forget to add and edit code in tool station
sections 1 and 2 when adding additional tool station locations.  Ensure the # symbol
is change to the correct tool station position number

--------------- Copy Start------------------

Tool Station # --
local ToolPos_#_X = 0
local ToolPos_#_Y = 0
local ToolPos_#_Z = 0

--------------- Copy Stop ------------------
]]



 ------ For spindles that have a partial tool push out, define the amount of movement here -----
 local ZBump = 0.100

 ------ Define the OUTPUT# for the drawbar signal -----
 local DrawBarOut = mc.OSIG_OUTPUT6

 ------ Get current state ------
 local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
 local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
 local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)


 ------ Turn off spindle and wait for decel -------
local GCode = ""
 GCode = GCode .. "M5\n"
 GCode = GCode .. string.format("G04 P%.4f\n", dwell)
 mc.mcCntlGcodeExecuteWait(inst, GCode)


 ------ Move to current tool station change position ------
 local tool = CurrentTool


-----------------------------------------------
----- Defining Tool Station Postions (section 2) ------
-----------------------------------------------

--Tool Station 1--
if tool == 1 then
    XPos = ToolPos_1_X
    YPos = ToolPos_1_Y
    ZPos = ToolPos_1_Z

--Tool Station 2--
elseif tool == 2 then
    XPos = ToolPos_2_X
    YPos = ToolPos_2_Y
    ZPos = ToolPos_2_Z

--Tool Station 3--
elseif tool == 3 then
    XPos = ToolPos_3_X
    YPos = ToolPos_3_Y
    ZPos = ToolPos_3_Z

--Tool Station 4--
elseif tool == 4 then
    XPos = ToolPos_4_X
    YPos = ToolPos_4_Y
    ZPos = ToolPos_4_Z

--Tool Station 5--
elseif tool == 5 then
    XPos = ToolPos_5_X
    YPos = ToolPos_5_Y
    ZPos = ToolPos_5_Z

--Tool Station 6--
elseif tool == 6 then
    XPos = ToolPos_6_X
    YPos = ToolPos_6_Y
    ZPos = ToolPos_6_Z

--Tool Station 7--
elseif tool == 7 then
    XPos = ToolPos_7_X
    YPos = ToolPos_7_Y
    ZPos = ToolPos_7_Z

--Tool Station 8--
elseif tool == 8 then
    XPos = ToolPos_8_X
    YPos = ToolPos_8_Y
    ZPos = ToolPos_8_Z

--Tool Station 9--
elseif tool == 9 then
    XPos = ToolPos_9_X
    YPos = ToolPos_9_Y
    ZPos = ToolPos_9_Z

--Tool Station 10--
elseif tool == 10 then
    XPos = ToolPos_10_X
    YPos = ToolPos_10_Y
    ZPos = ToolPos_10_Z

--[[
To add more tool station positions, copy the code below and paste it after your last
active tool station position. Don't forget to add and edit code in tool station
sections 1 and 3 when adding additional locations.  Ensure the # symbol is change
to the correct tool station position number

--------------- Copy Start -----------------

Tool Station # --
elseif tool == # then
XPos = ToolPos_#_X
YPos = ToolPos_#_Y
ZPos = ToolPos_#_Z

--------------- Copy Stop ------------------
]]

else
wx.wxMessageBox("Invalid tool #. Cancelling tool change!\nYour requested tool will now be set as the current tool in the spindle.\n****Ensure that the tool station that you have selected is empty!****")
mc.mcToolSetCurrent(inst, SelectedTool)
do return end

end


 local GCode = ""
 GCode = GCode .. "G00 G90 G53 Z0.0\n"
 GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", (XPos-XSlide), (YPos-YSlide))
 GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos)
 GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos, YPos)
 mc.mcCntlGcodeExecuteWait(inst, GCode)

 ------ Open drawbar ------

 local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
 mc.mcSignalSetState(hsig, 1)


 ------ Raise spindle, after releasing tool ------
 GCode = ""
 GCode = GCode .. string.format("G01 G90 G53 Z0.00 F50.0\n")
 mc.mcCntlGcodeExecuteWait(inst, GCode)

 ------ Move to next tool station change position ------
 tool = SelectedTool


-----------------------------------------------
----- Defining Tool Station Postions (section 3) ------
-----------------------------------------------

----- Define Tool Station Postions ------
--Tool Station 1
if tool == 1 then
    XPos = ToolPos_1_X
    YPos = ToolPos_1_Y
    ZPos = ToolPos_1_Z

--Tool Station2
elseif tool == 2 then
    XPos = ToolPos_2_X
    YPos = ToolPos_2_Y
    ZPos = ToolPos_2_Z

--Tool Station 3
elseif tool == 3 then
    XPos = ToolPos_3_X
    YPos = ToolPos_3_Y
    ZPos = ToolPos_3_Z

--Tool Station 4
elseif tool == 4 then
    XPos = ToolPos_4_X
    YPos = ToolPos_4_Y
    ZPos = ToolPos_4_Z

--Tool Station 5
elseif tool == 5 then
    XPos = ToolPos_5_X
    YPos = ToolPos_5_Y
    ZPos = ToolPos_5_Z

--Tool Station 6
elseif tool == 6 then
    XPos = ToolPos_6_X
    YPos = ToolPos_6_Y
    ZPos = ToolPos_6_Z

--Tool Station 7
elseif tool == 7 then
    XPos = ToolPos_7_X
    YPos = ToolPos_7_Y
    ZPos = ToolPos_7_Z

--Tool Station 8
elseif tool == 8 then
    XPos = ToolPos_8_X
    YPos = ToolPos_8_Y
    ZPos = ToolPos_8_Z

--Tool Station 9--
elseif tool == 9 then
    XPos = ToolPos_9_X
    YPos = ToolPos_9_Y
    ZPos = ToolPos_9_Z

--Tool Station 10--
elseif tool == 10 then
    XPos = ToolPos_10_X
    YPos = ToolPos_10_Y
    ZPos = ToolPos_10_Z

--[[
To add more tool station positions, copy the code below and paste it after your last
active tool station position. Don't forget to add and edit code in tool station
sections 1 and 2 when adding additional locations.  Ensure the # symbol is change
to the correct tool station position number

--------------- Copy Start ---------------

Tool Station # --
elseif tool == # then
XPos = ToolPos_#_X
YPos = ToolPos_#_Y
ZPos = ToolPos_#_Z

--------------- Copy Stop ----------------
]]

else
wx.wxMessageBox("Invalid tool #.  Retrieving previous tool!")
SelectedTool = CurrentTool

end

---- Tool Drop off Section ----

 GCode = ""
 GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos, YPos)
 GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos + ZBump)
 mc.mcCntlGcodeExecuteWait(inst, GCode)

 ------ Clamp drawbar ------
 mc.mcSignalSetState(hsig, 0)

 GCode = ""
 GCode = GCode .. string.format("G01 G90 G53 Z%.4f F50.0\n", ZPos)
 GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", (XPos-XSlide), (YPos-YSlide))
 mc.mcCntlGcodeExecuteWait(inst, GCode)


 ------ Move Z to home position ------
 GCode = ""
 mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n")

 ------ Reset state ------
 mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
 mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
 mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)

 ------ Set new tool ------
 mc.mcToolSetCurrent(inst, SelectedTool)
 mc.mcCntlSetLastError(inst, string.format("Tool change - Tool: %.0f", (SelectedTool)))

end
Re: ATC Macro adjustment for reversed tool forks
« Reply #3 on: February 01, 2023, 06:40:56 PM »
Hi,
OK. It looks to me that the last thing this macro does after clamping the new tool is:

Code: [Select]
------ Move Z to home position ------
 GCode = ""
 mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n")

Which is right near the bottom (of your code). My understanding of this move is that the machine will drive vertically upwards while retaining its current X, Y location,
presumably the last tool pocket visited. The G53 means that the machine should travel to Z=0 in machine coordinates which according to common practice is the very
top of the Z axis travel.  Is this where you expect? Where is your machine Z zero? If its not right at the top where its it?

Craig
« Last Edit: February 01, 2023, 06:44:27 PM by joeaverage »
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: ATC Macro adjustment for reversed tool forks
« Reply #4 on: February 01, 2023, 06:46:48 PM »
Hi,
I think there is some extra code we are missing. There is no code to drive the machine to the new start location....and I think that is where the failure is happening.

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

Offline JtheB

*
  •  35 35
    • View Profile
Re: ATC Macro adjustment for reversed tool forks
« Reply #5 on: February 01, 2023, 09:19:26 PM »
Yup, it goes to the top of Z as it should.
The next step I need it to do from the top of Z is slide 10” on the -Y axis.
THEN it’s clear of the magazine and can drop down and execute the tool paths.

Offline JtheB

*
  •  35 35
    • View Profile
Re: ATC Macro adjustment for reversed tool forks
« Reply #6 on: February 01, 2023, 09:22:46 PM »
Can I get a YSlide command just after the last Z-Home command at the end?
Between these two below?

 ------ Move Z to home position ------
 GCode = ""
 mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n")

 ------ Reset state ------
 mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
 mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
 mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)
Re: ATC Macro adjustment for reversed tool forks
« Reply #7 on: February 01, 2023, 09:26:42 PM »
Hi,
yes you could add an extra Y 'slide', and I'm assuming you mean Y axis movement? at that point but we are still missing the code that takes the controlled point back to the
new start point. I think adding a line of code WITHOUT at least inspecting the other code is likely to lead to disaster.

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

Offline JtheB

*
  •  35 35
    • View Profile
Re: ATC Macro adjustment for reversed tool forks
« Reply #8 on: February 01, 2023, 09:49:36 PM »
Yes, Y axis movement.
The only other code I’m aware of is the actual toolpath file.
What am I missing here?
And thanks for the help Craig.
Big deal for me.
Re: ATC Macro adjustment for reversed tool forks
« Reply #9 on: February 01, 2023, 09:55:25 PM »
Hi,
my machine does not have an ATC and so I could be well out to lunch here, but I was of the opinion that a tool change macro was in fact two macros,
the first stops the machine, records its state, then moves to the tool change location, changes tools and clamps the new tool in, and resets the machines state.
Thereafter the second half of the macro runs which does the tool touch off if required, and then does the preparatory move to the new start point.

I'd swear therefore that there is a piece of code missing, in particular that piece of code that does the preparatory move.

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