3131
VB and the development of wizards / Re: Need help with manual toolchange macro
« on: June 05, 2008, 04:25:56 PM »
For information look on the wiki, videos, docs., ect. in the support tab at the top of this page. Can also ask questions here and do searches. The standard macros for tool cahnge are M6. Mach has two, M6 start and M6end. In general config., top left there are check boxes to choose ignore tool change, stop and wait, and auto. Ignor will do nothing if a M6 is called, stop and wait will run thru the M6 start macro and wait on a press of cycle start to run the M6 end macro. The auto will just run thru the M6 start I think and ignor the M6. You can make your on macro in a text file and save them as M6start.m1s and M6end.m1s or edit the ones allready there. They will be in you c/mach3/macros folder. In there all of the profiles are listed and the macros for each are in those folders. Also, with Mach open their is a tap at the top, operator. Two vb editors in their button script and vb editor. You can open the editor and scroll thru the code and see what mach does at each line.Â
Here is a M6start macro that stops the spindle, goes to the tool change pos. set by the tool change pos. DROs on the settings page, ask if you want to do an auto touch off, runs the auto tool touch off if you choose and then you have the M6 end macro that returns it to state prior to tool change. Doesn't return it to the pos. though. I had that in there but going back to where it requested the tool change was a waste of time mostly for me. Usually after a tool change it starts back in a different pos. any ways. I will try to find that one for if you really want it though.
Be sure to test these!!!!! Been a long time since I messed with these particular ones.
'M6 start macro with auto tool touch off
'M6Start.m1s
tool = GetselectedTool()
oldTool = GetOEMDRO(1212)
If (oldTool <>Â tool) Then
Old_tool = GetCurrentTool()
New_Tool = GetSelectedTool()
DoSpinStop()
If getoemled(13) Then
  'coolant is on
  setuserled(1000,1)' set user led on
  Code "M9"
Else
  'coolent is off
  setuserled(1000,0) ' set user led off
End If
 'Get the tool change pos from the settings page
 ChangeX = GetOEMDRO(1200)
 ChangeY = GetOEMDRO(1201)
 ChangeZ = GetOEMDRO(1202)
Â
 Code "G00 G54 Z.25"
 Code "G00 G53 X" & ChangeX & "Y" & ChangeY
 'Code "G00 G53 Z" & ChangeZ, You may want to use this.
Â
 Response = MsgBox ( "Would you like to set your Z height automatically? If so, click OK", 1 )
 If Response = 1 Then
CurrentFeed = GetOemDRO(818) 'Get the current feedrate.
PlateThickness =0.062
ProbeFeed = 5
Code "G90 F" &ProbeFeed
If GetOemLed (825)=0 Then
'Code "G4 P5" 'Time to get to the z-plate
Code "G31Z-5 F" &ProbeFeed
While IsMoving()
Wend
Code "G4 P0.25"
ZProbePos = GetVar(2002)
Code "G0 Z" &ZProbePos
While IsMoving ()
Wend
Call SetDro (2, PlateThickness)
Code "G4 P0.5" 'Pause for Dro to update.
Code "G0 Z0.25" 'Change the Z retract height here
Code "(Z axis is now zeroed)"
Code "F" &CurrentFeed
Else
Code "(Z-Plate is grounded, check connection and try again)"
Exit Sub
End If
End If Â
 SetCurrentTool( tool )                 Â
Â
End If
This is the M6 End Macro
'M6End.m1s
tool = GetDRO(24)
oldTool = GetOEMDRO(1212)
If getuserled(1000) Then ' check user led
  'coolant was on
  Code "M8"
End If
If (oldTool <>Â tool) Then
SetOEMDRO(1212,tool)
End If
Brett
     Â
Here is a M6start macro that stops the spindle, goes to the tool change pos. set by the tool change pos. DROs on the settings page, ask if you want to do an auto touch off, runs the auto tool touch off if you choose and then you have the M6 end macro that returns it to state prior to tool change. Doesn't return it to the pos. though. I had that in there but going back to where it requested the tool change was a waste of time mostly for me. Usually after a tool change it starts back in a different pos. any ways. I will try to find that one for if you really want it though.
Be sure to test these!!!!! Been a long time since I messed with these particular ones.
'M6 start macro with auto tool touch off
'M6Start.m1s
tool = GetselectedTool()
oldTool = GetOEMDRO(1212)
If (oldTool <>Â tool) Then
Old_tool = GetCurrentTool()
New_Tool = GetSelectedTool()
DoSpinStop()
If getoemled(13) Then
  'coolant is on
  setuserled(1000,1)' set user led on
  Code "M9"
Else
  'coolent is off
  setuserled(1000,0) ' set user led off
End If
 'Get the tool change pos from the settings page
 ChangeX = GetOEMDRO(1200)
 ChangeY = GetOEMDRO(1201)
 ChangeZ = GetOEMDRO(1202)
Â
 Code "G00 G54 Z.25"
 Code "G00 G53 X" & ChangeX & "Y" & ChangeY
 'Code "G00 G53 Z" & ChangeZ, You may want to use this.
Â
 Response = MsgBox ( "Would you like to set your Z height automatically? If so, click OK", 1 )
 If Response = 1 Then
CurrentFeed = GetOemDRO(818) 'Get the current feedrate.
PlateThickness =0.062
ProbeFeed = 5
Code "G90 F" &ProbeFeed
If GetOemLed (825)=0 Then
'Code "G4 P5" 'Time to get to the z-plate
Code "G31Z-5 F" &ProbeFeed
While IsMoving()
Wend
Code "G4 P0.25"
ZProbePos = GetVar(2002)
Code "G0 Z" &ZProbePos
While IsMoving ()
Wend
Call SetDro (2, PlateThickness)
Code "G4 P0.5" 'Pause for Dro to update.
Code "G0 Z0.25" 'Change the Z retract height here
Code "(Z axis is now zeroed)"
Code "F" &CurrentFeed
Else
Code "(Z-Plate is grounded, check connection and try again)"
Exit Sub
End If
End If Â
 SetCurrentTool( tool )                 Â
Â
End If
This is the M6 End Macro
'M6End.m1s
tool = GetDRO(24)
oldTool = GetOEMDRO(1212)
If getuserled(1000) Then ' check user led
  'coolant was on
  Code "M8"
End If
If (oldTool <>Â tool) Then
SetOEMDRO(1212,tool)
End If
Brett
     Â