Hello Guest it is March 29, 2024, 07:33:44 AM

Author Topic: Macro for turret tool change on Z axis  (Read 8465 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
Macro for turret tool change on Z axis
« on: April 03, 2011, 10:31:49 PM »
I am working on a Macro for a turret tool changer. You can see the machine here:
http://www.youtube.com/watch?v=W-0q5uM8jbU
I have the motions programmed and I have it set to auto turn off soft limits if they are on to get past the soft limit at Zhome.

My next task is how to make it keep track of what tool it is on and run the macro the number of times it needs to get to the right tool. Also if something were to crash or power was lost or something wierd happened while it was in the tool change area, how would it know what tool it is on when you get it back up and running and homed?
Should I make it ask me what tool it is on when I start the program or something? If so how would I do this.
Here is what I got so far which works (motion wise)


'Turn off soft limits if they are on
If GetOEMLED(23) Then
DoOEMButton(119)
End If
NewTool = GetSelectedTool()
'Make it the current tool
SetCurrentTool(NewTool)
'Get positions before moving to do tool change
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )
'Moves to Z home from where ever it is
code "G53G0Z0"
While IsMoving()
Wend 
'Moves Z axiis to the top of tool change
code "G53 G1 F70 Z5.800"
While IsMoving()
Wend
'Moves back to Z home with the next tool loaded
code "G53 G1 F70 Z0"
While IsMoving()
Wend
'Turn back on soft limits
DoOEMButton(119)

Offline jevs

*
  •  315 315
    • View Profile
Re: Macro for turret tool change on Z axis
« Reply #1 on: April 04, 2011, 11:45:30 PM »
After a day to clear my head and start fresh, I got back to it tonight and got it fully funtional. Here is a video:
http://www.youtube.com/watch?v=DsizLpAXTns

Here is the Code in case anyone else has something like this:

'Tool change macro for 7 tool turret
Sub Main()
   'Sets variable OldTool to what is currently loaded
   OldTool=GetCurrentTool()
   'Sets variable Newtool to the one being selected
   NewTool=GetSelectedTool()
   'Sets Variable MaxToolNum to the max number of tools possible
   MaxToolNum=7
   
   'Get positions before moving to do tool change
   x = GetToolChangeStart( 0 )
   y = GetToolChangeStart( 1 )
   z = GetToolChangeStart( 2 )
   a = GetToolChangeStart( 3 )
   b = GetToolChangeStart( 4 )
   c = GetToolChangeStart( 5 )
   
   'If the current tool loaded is 0 or greater than 7 then tool has been lost
   'so need to ask what tool is currently loaded
   While OldTool=0 Or OldTool>7
   OldTool=Question ("Current tool unknown, enter tool in spindle 1 to " & MaxToolNum)
   Wend
   
   'Sets CurrentTool to Oldtool in case a it was lost and entered above
   SetCurrentTool(OldTool)

   'If the tool asked for is invalid then this makes you select a valid tool
   While NewTool > MaxToolNum Or NewTool <1
   NewTool = Question ("Invalid tool selected, select a tool number 1 to " & MaxToolNum)
   Wend
   
   'If the tool asked for is the same one that is already loaded then exit macro
   If NewTool=OldTool Then
      Exit Sub
   End If

'Turn off soft limits if they are on
If GetOEMLED(23) Then
DoOEMButton(119)
End If

'Moves To Z home from where ever it is
code "G53G0Z0"
While IsMoving()
Wend

'Sets ChangeNums to 0 for safety in case it is not at 0
ChangeNums=0

'Makes the magic happen and moves the proper number of times if new tool is higher than old
If NewTool>OldTool Then
   For ChangeNums=1 To NewTool-OldTool
   
   'Moves Z axiis to the top of tool change
   code "G53 G1 F70 Z5.800"
   While IsMoving()
   Wend

   'Moves back to bottom of tool change area
   code "G53 G1 F70 Z3.8"
   While IsMoving()
   Wend
   
   Next
   
'Makes the magic happen and moves the proper number of times if new tool is lower than old   
Else
   For ChangeNums=(OldTool-NewTool) To 6
   
   'Moves Z axis to the top of tool change
   code "G53 G1 F70 Z5.800"
   While IsMoving()
   Wend

   'Moves back to bottom of tool change area
   code "G53 G1 F70 Z3.8"
   While IsMoving()
   Wend
   
   Next
End If

'Move Back to Z Home
code "G53 G1 F70 Z0"
While IsMoving()
Wend
   
'Should be a succesful tool change at this point so this sets the NewTool as the current tool
SetCurrentTool(NewTool)

'Turn back on soft limits
DoOEMButton(119)
End Sub 

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Macro for turret tool change on Z axis
« Reply #2 on: April 10, 2011, 04:16:01 PM »
Just a side note, anytime your machine faluts or crashes or whatever you need to rehome the toolchanger .that way mach knows for sure what the tool really is.  Most use an auto home routine that homes to a known tool AND reset the current tool as that tool#.

(;-) TP

Offline jevs

*
  •  315 315
    • View Profile
Re: Macro for turret tool change on Z axis
« Reply #3 on: April 10, 2011, 05:43:37 PM »
There is no way to home so that it knows what tool it is on. The only way it will know is if you tell it. There is no swiitch or sensor for a certain tool position. How would you deal with that? If the tool number goes to 0 or greater than 7 my macro is supposed to ask what tool your really on, but that is the only thing I could think of.

Is there a way to make Mach3 ask you what tool it's on as soon as it boots up or something?

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Macro for turret tool change on Z axis
« Reply #4 on: April 10, 2011, 10:06:49 PM »
Then you would have to do it manually. Rotate the tool changer to  tool 1  then tell mach what tool is the current tool.

Most tool changers use a tool table that lets mach know what tool is in what location in the tool changer. The tool changer then uses a tool slot number to identify the acutal tool.

These routines are programmed as a VB macro OR programed into a PLC.

(;-) TP

Offline jevs

*
  •  315 315
    • View Profile
Re: Macro for turret tool change on Z axis
« Reply #5 on: February 12, 2013, 11:04:29 PM »
I built a new computer and am now useing an ethernet smoothstepper.

For some reason on my new setup my tool change M6 command will only work 1 time now.

It works just right the first time you input it and select a tool number. After that I just get an annoying beep everytime I put in M6.

The only way it will work again is to restart the computer and then it only works once again. Restarting Mach does not make it work again and shutting off mach then resetting power to the smoothstepper, then restarting mach again does not work either. Only restarting the computer will make it work one time again. 

Any ideas? Other codes will still work after this, it must be something with all the new stuff and my macro. Everything else seems to work in Mach, but a second command of M6 does nothing.
« Last Edit: February 12, 2013, 11:14:31 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
Re: Macro for turret tool change on Z axis
« Reply #6 on: February 14, 2013, 12:51:19 AM »
Solved!

What was happening is that I was just typing in M6 and the first time you do this my macro had no idea what the "GetSelectedTool" Value was since no tool had ever been selected since last boot up. I assume this defaults the value to 0 which would initiate the "Invalid tool chosen..." question. Upon the next time only M6 was entered it would ignore it because it would have the last good tool number used set as the "GetSelectedTool" Value so it would not initiate the question and just beep with seemingly nothing happening. It has been so long I forgot you should specify the tool number as a T# and I was trying either a M6 which would do something only the first time, or I was typing in M6 5 and forgetting that I need a T in front of the tool number (dumb I know).

Anyway, I solved all this so you always know what is going on by adding a message "Tool already loaded or tool not specified with T# (ex:M6 T4)" . This pops up if you select the same tool number that is already loaded or if you do not use a "T" command to designate a different tool. So now even if I do not use this for a very long time I will be reminded of what I am doing wrong.

Here is the updated Macro:
 
'Tool change macro for 7 tool turret
Sub Main()
   'Sets variable OldTool to what is currently loaded
   OldTool=GetCurrentTool()
   
   'Sets Variable MaxToolNum to the max number of tools possible
   MaxToolNum=7
   
   'Sets variable Newtool to the one being selected with M6 T#
   NewTool=GetSelectedTool()   
   
   'Get positions before moving to do tool change
   x = GetToolChangeStart( 0 )
   y = GetToolChangeStart( 1 )
   z = GetToolChangeStart( 2 )
   a = GetToolChangeStart( 3 )
   b = GetToolChangeStart( 4 )
   c = GetToolChangeStart( 5 )
   
   'If the current tool loaded is 0 or greater than 7 then tool has been lost
   'so need to ask what tool is currently loaded
   While OldTool=0 Or OldTool>7
   OldTool=Question ("Current tool unknown, enter tool in spindle 1 to " & MaxToolNum)
   Wend
   
   'Sets CurrentTool to Oldtool in case it was lost and entered above
   SetCurrentTool(OldTool)

   'When the tool asked for is invalid then this makes you select a valid tool
   While NewTool > MaxToolNum Or NewTool <1
   NewTool = Question ("Invalid tool chosen, enter tool number 1 to " & MaxToolNum)
   Wend
   
        'If the tool asked for is the same one that is already loaded then exit macro
   If NewTool=OldTool Then
   Message "Tool already loaded or tool not specified with T# (ex:M6 T4)"
      Exit Sub
   End If

'Turn off soft limits if they are on
If GetOEMLED(23) Then
DoOEMButton(119)
End If

'Moves To Z home from where ever it is
code "G53G0Z0"
While IsMoving()
Wend

'Sets ChangeNums to 0 for safety in case it is not at 0
ChangeNums=0

'Makes the magic happen and moves the proper number of times if new tool is higher than old
If NewTool>OldTool Then
   For ChangeNums=1 To NewTool-OldTool
   
   'Moves Z axis to the top of tool change
   code "G53 G1 F70 Z5.800"
   While IsMoving()
   Wend

   'Moves back to bottom of tool change area
   code "G53 G1 F70 Z3.8"
   While IsMoving()
   Wend
   
   Next
   
'Makes the magic happen and moves the proper number of times if new tool is lower than old   
Else
   For ChangeNums=(OldTool-NewTool) To 6
   
   'Moves Z axis to the top of tool change
   code "G53 G1 F70 Z5.800"
   While IsMoving()
   Wend

   'Moves back to bottom of tool change area
   code "G53 G1 F70 Z3.8"
   While IsMoving()
   Wend
   
   Next
End If

'Move Back to Z Home
code "G53 G1 F70 Z0"
While IsMoving()
Wend
   
'Should be a succesful tool change at this point so this sets the NewTool as the current tool
SetCurrentTool(NewTool)

'Turn back on soft limits
DoOEMButton(119)
End Sub