Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 07:26:31 PM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  VB and the development of wizards
| | |-+  Macro for turret tool change on Z axis
Pages: 1   Go Down
Print
Author Topic: Macro for turret tool change on Z axis  (Read 730 times)
0 Members and 1 Guest are viewing this topic.
jevs
Active Member

Offline Offline

Posts: 31


View Profile
« on: April 03, 2011, 09: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)
Logged
jevs
Active Member

Offline Offline

Posts: 31


View Profile
« Reply #1 on: April 04, 2011, 10: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 
Logged
BR549
Active Member

Online Online

Posts: 2,557


View Profile
« Reply #2 on: April 10, 2011, 03: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
Logged
jevs
Active Member

Offline Offline

Posts: 31


View Profile
« Reply #3 on: April 10, 2011, 04: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?
Logged
BR549
Active Member

Online Online

Posts: 2,557


View Profile
« Reply #4 on: April 10, 2011, 09: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
Logged
Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!