Hello Guest it is March 28, 2024, 09:08:13 AM

Author Topic: Need help with manual toolchange macro  (Read 42225 times)

0 Members and 1 Guest are viewing this topic.

Need help with manual toolchange macro
« on: June 05, 2008, 03:30:41 PM »
Hi All:

I have a new mill running under Mach3 and need to create a macro for manual tool changing, since it is a single tool machine. The g-code files that I am using contain an M998 call and this simply causes the machine to stop and wait for a cycle start press. I could change the tool then but usually the head is too close to the workpiece, and in any event, I still need to reset the Z offset for the new tool since they're not standard length.

What I want to be able to do therefore is to have the machine move 'home' and pause so that I can manually change the tool and set a new Z offset for it. Then I want to hit cycle start and have the machine return to the point where it originally stopped (and then hit cycle start again to recommence machining).

It's not complex, but I am tearing my hair out trying to figure out how to do this. I'd like to be able to 'trap' the G998 call in some way and modify the behaviour. VB is no problem for me but I cannot find where this macro is coded in Mach3 or how to modify it (the documentation is kinda sparse here, as far as I can see).

Any pointers as to where to get started (and to Mach3 programming docs) would be appreciated, as will any existing examples or code skeletons that I can 'borrow' from or modify.

Regards,

Rick

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Need help with manual toolchange macro
« Reply #1 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
           

;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Need help with manual toolchange macro
« Reply #2 on: June 06, 2008, 10:53:23 AM »

Ta Brett,

I'll start from there.

Rick

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: Need help with manual toolchange macro
« Reply #3 on: June 06, 2008, 01:33:44 PM »
Rick,

    Ok, here is something that may help you out.
First let me ask you this Question, do you have Tool Holders???
If you do, you can set up all your tool Ht. offsets in Mach3's tool library
on the setup page. That way, once you run your program, it will just call
the offset by the tool number you previously set in the library. It would
save you alot of time.

I am going to work on the assumption though at your post that you DON'T have
tool holders and have something like an R-8 that you have to set the tool H, for
each tool change, the macros below will be for that scenerio, if you have holders
let me know, and I will try and help you modify for that situation.

Ok your M998 will be used AFTER the a M6 call.
For M6 to work, you will need to go under:
config>general and tick the Auto Tool changer
also under general you will need to tick off "use M1" for optional stop.
under config>homing limits, you will need to set the coordinates of your G28 move
under config>SafeZ settings, you will need to set the type of Safe Z you want, for this
example I used "1" above "Program" corrdinates.
Note: the Tool path does NOT see the moves of your M998 so, your tool path may look a little funny.

ASSUMPTIONS:

here are the assumptions that this macro makes about your machine, change them if not true
to your machine.

It assumes that "Z0" is the Top of your Work Piece, OR, some Place on
your table that you reference your tool Zero's. Z0 MUST be the same physical
point hiegth for all the tools to zero againts that you will use on the part.

Assumes Negative Z is DOWN into your part, and Z0 is the top of your stock or some
other repeatable point. Positive Z goes up away from your table/part.

 It assumes you have Ref'ed your machine
prior to the tool change, if not, it will kick out and make your ref your machine.
   It also assumes that any complex tool/paths like reverse counter bores that you have brought
the tool out, at least where it can safely be drawn Straight up after the tool completes
its path.
   It assumes "English" measure.
   you will NOT be doing any fixture, or other coordinate offsets between tool changes or
   until this part is finished.

Sequence of Events:

   A M6 tool change is called
   it grabs the Z location of the the current cutting tool tip
   the m6 moves your old tool to program z0.1, and then grabs the xyz positon in program cord.
   stores that location in your Mach Vars
   it then moves to SafeZ, and then goes to your G28 location
   Does a "M1" optional stop (you will need that ticked off in gen, see above).
   You will then change your tool.
   then goto your offsets page.
   You will then jog the new tool to your program "0" point, and zero (touch off) what ever the next tool # is set its zero.
   If you dont want crap in your tool library, then use all T0's for each tool
   You will then hit "Cycle Start"
   your spindle will start running, at the new speed and direction
   Your M998 will then run this will move to Safe Z hieght directly above
   where your last tool left off.
   it will rapid down to slightly above your part or (program "z0")
   it will move down into the work to the hiegth the last tool left off at new Feed speed
   Your M998 will exit, and the new tool follow the new path.
   
   
G-code Programming notes:
   After your M6 and before your M998 you will need to program in your S word,
   and M3 or M4, any F Feed speed canges,
      
EXAMPLE G-code:
   
M3 S1000 F10        'sets the rot. dir, feed and speed for your new tool.   
T2 M6            'Set tool# and execute M6
   
M998            'returns to last point, spindle spinning, at G0, and safe Z ht.
                  'then it will feed at last F speed, to where the Old tool left off
                  
G code FILE:
there is G-code at the bottom of this post that you can run to test all of this

M6 TOOL CHANGE CODE:                  

'M6Start.m1s

Sub Main()

   'Semi-Auto Tool Change
   
    Dim OldTool
    Dim NewTool
    Dim CurX, CurY, CurZ, ZLast
    Dim SafeZ
       
    OldTool = GetCurrentTool()     'get old tool number
    NewTool = GetSelectedTool()     'get new tool number
    SafeZ = GetParam("SafeZ")      'get Safe Z ht, from Config>SafeZ setup
   
   
   If (GetOemLed(807) Or GetOemLed(808) Or GetOemLed(809)) Then 'Check all axes referenced
    Message("           Please Home Machine before Tool Change")
    DoButton(3)                  'Cycle Stop
    Exit Sub
   End If   
   
    '******************************************************************************
       
    ZLast = GetOemDRO(802)
    SetVar(103,ZLast)            
   
    'get current Z position in program Coords where
    'this tool, (oldtool), has stopped cutting IN the work at what ever level and position in the
    'work where it stopped spinning at. This is so the new tool can have a place in the
    'work to pick up exactly where the old tool left off. The danger here is for example
    'if the new tool is bigger than the slot you just cut, The M998 will bring the new
    'tool above the work at Safe Z, then it will feed directly Down at Feed Speed to
    'the level the old tool left off. If this is not what you want, take this code out.
      
    '*******************************************************************************
     
    DoSpinStop()               'Request spindle stop
       While IsMoving()
        Wend
   
    Code "G90 G1 Z0.1 F20"          'Move oldtool up from its current
    'cutting depth to slightly above part/program "Z0" coordinates
   
    CurX = GetOemDRO(800)         'get current X position in program Coords
    CurY = GetOemDRO(801)         'get current Y position in program Coords
    CurZ = GetOemDRO(802)         'get current Z position in program Coords
    SetVar(100,CurX)            'sets the "0" return point for X for your M998
    SetVar(101,CurY)            'sets the "0" return point for Y for your M998
    SetVar(102,CurZ)            'sets the "0" return point for Z for your M998
    Code "G0 Z" & SafeZ             'Move to safe Z travel hieght
          While IsMoving()         'Wait for spindle up
        Wend   
 
        Code "G28"               'this will move to the G28 homing position for tool
        'change
        While IsMoving()
        Wend
       
        SetOEMDRO(824, NewTool)            'set old tool to New tool
       
       Code "M1"                     'sets a machine pause for you to change tool
       'When you have changed to your new tool, zero it to your zero point then hit
       'cycle start.       
   
End Sub


'End of M6

'===================================================================================
'===================================================================================
'===================================================================================

'M998.m1s

Sub Main()

Dim SafeZ, CurX, CurY, CurZ, ZLast, CurFeed

SafeZ = getParam("SafeZ")         'gets your safe Z settings.
CurX = getVar(100)            'gets the "0" return point for X from your M6
CurY = getVar(101)            'gets the "0" return point for Y from your M6
CurZ = getVar(102)            'gets the "0" return point for Z from your M6
ZLast = getVar(103)            'gets the last Z program cutting ht that the
CurFeed = GetOemDro(818)         'get current feed rate                           'old tool left off at.

Code "G0 Z" & SafeZ             'Move to safe Z travel hieght
While IsMoving()         
Wend

Code "G0 X" & CurX & " Y" & CurY
Code "G0 Z" & CurZ
'The new tool will rapid move directly over the x,y where your old tool left off
'Then it will rapid down to slightly above your Program Z0.
While IsMoving()
Wend

Code "G01 Z" & ZLast & " F" & CurFeed
'The new cutter moves down from slightly above Program/Part Z0 (z0.1 in this case)
While IsMoving()
Wend

'once it reaches the -Z plane that the last cutter left off at, this macro will
'exit and the new tool will follow what ever path you have laid out for it.

End Sub

'End M998     =================================================================

G code testing file

G28M6testfile.TAP

(Turn on your Single block so you can step through)
(the Gcode, once done, run regular)
m3 S500 F10
T0
g1 x1
g1 Z-1
T2 (m6 open vb window and step through the code here)
(look under Operator>Gcode Var monitor, punch in vars)
(100, 101, 102, 103 you will see the saved last coordinates)
(close the vb window after you have stepped all the way through)
(Zero your next tool here)
m3 s1000 F5
(M998  step through this one as well)
g1 y1
g1 z-1
g1 z0
m30

'Enjoy,
'Scott
fun times
Re: Need help with manual toolchange macro
« Reply #4 on: February 01, 2010, 03:30:34 PM »
hello everybody,
i have atc in my milling machine.. controlled by plc... the plc changes the tools this way ..
if apply 12 to input 1  (i1.0) changes the tool to no 1.. if apply 12v to input 2 (i0.1) changes the tool to number 2... etc..
so i want to write a vb macro in mach 3 so that if the program asks to change to tool number 1.. the s.s. activates output pin for ex port1 pin 10 ...
 if the program asks to change to tool number 2.. the s.s. activates output pin for ex port1 pin 11.. ..
and after the plc changes the tool .. gives back a signal to the s.s. that tool changed... continue working...

how can i do that Huh??
and how can i control the plc 12 v... by the s.s. 5 v?HuhHuh??
please help mee..
best regards,
haig,
haig.artin@yahoo.com
Re: Need help with manual toolchange macro
« Reply #5 on: February 18, 2010, 02:21:25 PM »
hello everybody,

I am looking for help to create a Macro M6start and M6end simple.

At each load a file G-code tools are called, I want a macro that sets the axes has a special place for me to make the change tools manually. As push the button "Start Cycle" that repositions the axes for job.

Thanks

Chris ???
Re: Need help with manual toolchange macro
« Reply #6 on: February 18, 2010, 05:15:23 PM »
Seems things are getting over complicated.

If you are using manual tool change "ME" then when a tool is finished i have a go tool change position in the G code

It waits while i change the tool i can jog to another position i can change the tool press start & off she goes

Like Scott says best to set tool offsets first

Phil
The Good Thing About Mach3, Is It's very Configurable

The Bad Thing About Mach3, Is It's Too Configurable
Re: Need help with manual toolchange macro
« Reply #7 on: December 12, 2012, 10:28:15 PM »
Hi Everyone,
I always got a great help from this forum. I need a help with an information, does anyone know if can I activate an output signal on a macro without stop the G-code sequence, I'm running my Gcode in a macro and I want to activate the output in same macro without interrupt my Gcode execution. Or is there a command that I can use to VB to get the righ position from my axis and turn on the output and in another position turn it off , without stop. thanks
darli
Re: Need help with manual toolchange macro
« Reply #8 on: December 26, 2012, 08:41:59 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
           



simpleton's question here.  What part of the M6end macro is it that gets everything to carry on where it left off with a simple cycle start.  I would like to initiate a tool change macro via an input so I can check the progress of my work, condition of my cutter, and other things in the middle of a program without banging my calipers, head, or hands on the spindle.   

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Need help with manual toolchange macro
« Reply #9 on: December 26, 2012, 08:49:08 PM »
It's not in the macro. When you go to General Config and set Mach3 to "Stop Spindle, Wait for Cycle Start", it runs the M6 Start macro, then waits for Cycle Start. After you press Cycle Start, it runs the M6 End macro, then continues running the code.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html