Hello Guest it is April 23, 2024, 03:33:18 AM

Author Topic: Tool change Macro Issue  (Read 1788 times)

0 Members and 1 Guest are viewing this topic.

Tool change Macro Issue
« on: February 13, 2021, 08:03:35 AM »
Hi everybody,

I'm a bit new to mach3 macros, gcode length compensation, and visual basic, but not all that new to programing.  I guess my first question would be is there any way to get the script to trigger a break point during a call to m6 from the MDI?  I think that might make debugging a little easier.

I'm having some difficulty with this modification of CNC4XR7's m6 tool change macro. 

First I get the current tool and set the length compensation (because it might not be set for the first tool change).
I then call GetToolChangeStart (I think I am getting an incorrect Z value here... maybe this requires time to update after the G43?)
Then move to the tool change position, and wait for the user to change it.
I then move back to the starting XY position that was saved earlier
and here is where things go wrong...
when I move back to the Z position I usually end up trying to plunge into the mill bed.

I think I am making some mistake by not accounting for the work offset, the length compensation is not updating, or I have some error in my use of g43.  I'm really scratching my head on this one...  Any ideas what I'm doing wrong here?

Thanks,

      Brian

Code: [Select]
'get the currently active tool
Dim Msg, Style, Title, Help, Ctxt, Response,MyString

OldTool = GetCurrentTool()
If OldTool = 0 Then
  'do something here...  this is not a valid condition!
  DoOEMButton(1003) 'stop code
  Msg = "Can't start from Tool 0!  Load a different tool"
  End
End If

Code "G43 H" & OldTool  'set the old tool length offset

  'tool = GetSelectedTool()
  'SetCurrentTool( tool )
  'Tool Change Macro For Manual tool change 09/14 CNC4XR7
  'OldTool = GetOEMDRO (1224) 'Tool In spindle DRO You must add this to your settings screen
x = GetToolChangeStart( 0 ) ' Get x tool change start position
y = GetToolChangeStart( 1 ) ' Get y tool change start position
z = GetToolChangeStart( 2 ) ' Get z tool change start position
Code "G53 G0 Z0" ' Move z to tool change position in Machine cord.
While IsMoving ' wait for z to move
Wend
Code "G53 G0 X-7 Y-10" ' Move to tool change position in Machine cord.
While IsMoving ' wait for z to move
Wend

tool = GetSelectedTool() ' tool to be changed to
NewTool = tool
Call SetUserDRO (1224,NewTool)
SetCurrentTool( NewTool ) ' input new tool into tool in spindle dro
Code "G43 H" & NewTool  'set new tool offset
' Verify Tool Change Complete
Msg = "Please Insert Tool Number " & " ( " & GetSelectedTool() & " ) " & " " & GetToolDesc(NewTool) ' Define message
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons
Style = 0 + 48 + 0 ' Define buttons.
Title = "Tool Change Requested" ' Define title
Help = "DEMO.HLP" ' Define Help file
Ctxt = 1000 ' Define topic 'context. ' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbOk Then ' User chose Ok




MyString = "Ok" ' Perform some action
End If
Message "Tool # " & GetCurrentTool() & " : " & GetToolDesc(GetCurrentTool()) & " Installed " & " Returning to Tool Change Start Position"

Code "G00 X" & x & "Y" & y 'Move above where the tool change was prompted
While IsMoving ' wait for z to move
Wend

Code "G00 X" & x & "Y" & y & "Z" & z 'Move back to where the tool change was prompted
'Code "G00 Z .25" 'Move Z back to .25" above zero in work cord.
While IsMoving
Wend

Code "G43 H" & tool ' Call tool offsets for new tool


End       

Offline TPS

*
  •  2,505 2,505
    • View Profile
Re: Tool change Macro Issue
« Reply #1 on: February 14, 2021, 10:16:23 AM »
first i would replace:
Code: [Select]
x = GetToolChangeStart( 0 ) ' Get x tool change start position
y = GetToolChangeStart( 1 ) ' Get y tool change start position
z = GetToolChangeStart( 2 ) ' Get z tool change start position

by:
Code: [Select]
x = GetOEMDro( 800 ) ' Get x tool change start position
y = GetOEMDro( 801 ) ' Get y tool change start position
z = GetOEMDro( 802 ) ' Get z tool change start position

this:
Code: [Select]
Call SetUserDRO (1224,NewTool)
does not make sense to me, but don't know wether DRO 1224 is used somewhere else

all this verifycation for tool insert:
Code: [Select]
' Verify Tool Change Complete
Msg = "Please Insert Tool Number " & " ( " & GetSelectedTool() & " ) " & " " & GetToolDesc(NewTool) ' Define message
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons
Style = 0 + 48 + 0 ' Define buttons.
Title = "Tool Change Requested" ' Define title
Help = "DEMO.HLP" ' Define Help file
Ctxt = 1000 ' Define topic 'context. ' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)

If Response = vbOk Then ' User chose Ok
MyString = "Ok" ' Perform some action
End If

does not make many sense too, except that the machine is waiting for tool insert, because:
1.the MSG has only a OK button
2.no matter what you do (press OK or the X of msgbox), the rest of code will be done anyway

also no Chance to cancel via MSGBox input.
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Tool change Macro Issue
« Reply #2 on: February 15, 2021, 11:00:27 PM »
Thanks TPS!

         I appreciate the help!  This was a modification of somebody elses tool change macro that I found online...  So there is a lot of cruft.   

Code: [Select]
x = GetOEMDro( 800 ) ' Get x tool change start position
y = GetOEMDro( 801 ) ' Get y tool change start position
z = GetOEMDro( 802 ) ' Get z tool change start position

Do the 800->802 DRO's read out the current work offset or machine coordinates?  How do those DRO's change based on g90/g91?  I have to admit that the documentation I was able to find on this was unclear.

Code: [Select]
Call SetUserDRO (1224,NewTool)
This is a user DRO that was added to the settings screen by the original author...  I think I can get rid it.

Code: [Select]
' Verify Tool Change Complete
Msg = "Please Insert Tool Number " & " ( " & GetSelectedTool() & " ) " & " " & GetToolDesc(NewTool) ' Define message
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons
Style = 0 + 48 + 0 ' Define buttons.
Title = "Tool Change Requested" ' Define title
Help = "DEMO.HLP" ' Define Help file
Ctxt = 1000 ' Define topic 'context. ' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)

If Response = vbOk Then ' User chose Ok
MyString = "Ok" ' Perform some action
End If

This is just to wait until the user manually changes the tool.  Is there a way to cancel the current running gcode?  I think A cancel option would be a good thing to add!  That is if I can cancel the currently running program.

Thanks again!

      Brian