Hello Guest it is December 02, 2024, 01:12:11 PM

Author Topic: Commission work, Macro needed please help!  (Read 12059 times)

0 Members and 1 Guest are viewing this topic.

Commission work, Macro needed please help!
« on: January 23, 2018, 10:29:35 AM »
Hello all,  anyone interested in lending a hand or a commission to write a macro for me.   I  need a macro for atc on cnc router.   the tool rack lays along the X axis on home position.   ATC spindle has tool IN/OUT sensors.  and requires two relays to release and lock the tool in place.    If anyone care to help or point me in the right direction.

Best regards
Anna


I need something similar to this video
https://www.youtube.com/watch?v=xBg1Je-2lUo
« Last Edit: January 23, 2018, 10:43:47 AM by uniquerc »

Offline TPS

*
  •  2,535 2,535
Re: Commission work, Macro needed please help!
« Reply #1 on: January 23, 2018, 03:39:30 PM »
hello Anna,

if you can provide a "little" (just a little bit) bit more information about:
-you're machine
-you're Hardware
-you're requiremen's

it will be easier for someone to write a "macro".

sorry Tom
anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.
Re: Commission work, Macro needed please help!
« Reply #2 on: January 23, 2018, 03:57:56 PM »
Thank you for your reply
machine is
x 500mm
y700mm
z 115mm
 iso20 atc spindle 2 sensors for proximity and tool in/out

controller usb motion card 16 input IO, 8 output IO

I need a macro for 8 tool rack slide in/out along X axis.
Machine needs to home, than  set tool into sliding tool holder(activate 2 relays simultaneously) to active air and release tool, move up and to next tool while relays remain on, once in position of next tool deactivate relay 2 to lock tool in, 2 seconds deactivate relay 1, slide out.  I will be storing tool offsets in mach3
same process for the other 7 tools.   Please let me know if you will need more info.

Best regards
Anna :)  
Re: Commission work, Macro needed please help!
« Reply #3 on: February 01, 2018, 07:39:00 PM »
 
' ---------------------------------------------------------------------------------
' TPS 26.01.2018 
' ATC macro for 8 places
' V 1.0.0
' ---------------------------------------------------------------------------------

' Main routine for tool change -----------------------------------------------------
Sub Main()

' declare ten global variables ----------------------------------------------------
  Dim Pos_X_Tool(8) as double

' variables for the feedrate
F_slow   = 400      'feedrate for slow moves
F_fast   = 2000      'feedrate for fast moves


'remark all TC position are in machine coordinates !!!

'variables for the X positions
Pos_X_Tool(1)   = 100.0000   'X position for tool 1
Pos_X_Tool(2)   = 200.0000   'X position for tool 2
Pos_X_Tool(3)   = 300.0000   'X position for tool 3
Pos_X_Tool(4)   = 400.0000   'X position for tool 4
Pos_X_Tool(5)   = 500.0000   'X position for tool 5
Pos_X_Tool(6)   = 600.0000   'X position for tool 6
Pos_X_Tool(7)   = 700.0000   'X position for tool 7
Pos_X_Tool(8)   = 800.0000   'X position for tool 8

'variables for the Y Position
Pos_Y_before   = 200.0000   'Y position in front of TC
Pos_Y_in      = 100.0000   'Y position in TC

'variables for the Z Position
Pos_Z_save      = 300.0000   'Z position over all that we can move (X/Y) save to TC
Pos_Z_over      = 200.0000   'Z position over the placed tool (X move possible)
Pos_Z_in      = 100.0000   'Z position in TC

'variable for toolclamp output
TC_output       = Output1
 
' ---------------------------------------------------------------------------------


   'get the tool relvated numbers
   newtool = GetSelectedTool()   'get the new toolnumber
   acttool  = GetCurrentTool()   'get the actual toolnumber

   'do some basic check's

   ' no tool loaded nothing to unload
   If ((newtool = 0) and (acttool = 0)) Then
      message("no tool loaded nothing to unload !")
      Exit Sub
   End If   

   ' nothing to do newtool = acttool
   If newtool = acttool Then
      message("nothing to do newtool = acttool !")
      Exit Sub
   End If
 
   'check toolnumber in range
   If  (((newtool > 8) Or (newtool < 1)) and (newtool <> 0)) Then
      Message (" toolnumber " & newtool & " is not in range (1-8). abort toolchange  ! ")
      DoButton(3)
      Exit Sub
   End If

   'X-axis is not referenced
   If GetOEMLED(807) Then
      Message ("X-axis no reference -> abort !!")
      DoButton(3)
      Exit Sub
   End If
   
   'Y-axis is not referenced
   If GetOEMLED(808) Then
      Message ("Y-axis no reference -> abort !!")
      DoButton(3)
      Exit Sub
   End If

   'Z-axis is not referenced
   If GetOEMLED(809) Then
      Message ("Z-axis no reference -> abort !!")
      DoButton(3)
      Exit Sub
   End If
   
   Message "change tool: " +CStr(acttool) + " to: " + CStr(newtool)
   
   'get the current position and settings
   CurrentFeed    = GetOemDRO(818)     'Get the current feedrate to return to later
   CurrentAbsInc    = GetOemLED(48)    'Get the current G90/G91 state
   CurrentGmode    = GetOemDRO(819)    'Get the current G0/G1 state
   CurrentXpos      = GetOemDRO(83)      'Get t X position where we came from
   CurrentYpos      = GetOemDRO(84)      'Get t Y position where we came from
   CurrentZpos      = GetOemDRO(85)      'Get t Z position where we came from

   'Get Axis Scale factors in use
   XScale = GetOEMDRO(59)
   YScale = GetOEMDRO(60)
   ZScale = GetOEMDRO(61)

   'Set All Axis Scales to 1
   SetOEMDRO(59,1)
   SetOEMDRO(60,1)
   SetOEMDRO(61,1)
   Sleep(250)   
   
   ' turn spindle off just in case
   Code "M5"
   
   ' go to save Z position
   Message "goto Z-save"
   Code "G53 G90 G01 Z"+CStr(Pos_Z_save)+"F"+CStr(F_fast)
   WaitForMove

   'only unload tool
   If newtool = 0 Then
      'go to X/Y position (Y-before)
      Message "go to X/Y position"
      Code "G53 G90 G01 X"+CStr(Pos_X_Tool(acttool))+"Y"+CStr(Pos_Y_before)
      WaitForMove
      'goto Z-in fast
      Message "goto Z-in fast"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_in)
      WaitForMove
      'go to Y position in
      Message "go to Y position in"
      Code "G53 G90 G01 Y"+CStr(Pos_Y_in)+"F"+CStr(F_slow)
      WaitForMove
      'open toolclamp
      Message "open toolclamp"
      ActivateSignal(TC_output)
      Sleep(1000)
      'goto Z-over slow
      Message "goto Z-over slow"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_over)
      WaitForMove
   End If   
   
   'only load tool
   If acttool = 0 Then
      'go to X/Y position
      Message "go to X/Y position"
      Code "G53 G90 G01 X"+CStr(Pos_X_Tool(newtool))+"Y"+CStr(Pos_Y_in)
      WaitForMove
      'goto Z-over fast
      Message "goto Z-over fast"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_over)
      WaitForMove
      'open toolclamp
      Message "open toolclamp"
      ActivateSignal(TC_output)
      Sleep(1000)
      'goto Z-in slow
      Message "' goto Z-in slow"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_in)+"F"+CStr(F_slow)
      WaitForMove
      'close toolclamp
      Message "close toolclamp"
      DeactivateSignal(TC_output)
      Sleep(1000)
      'go to Y position before
      Message "go to Y position before"
      Code "G53 G90 G01 Y"+CStr(Pos_Y_before)
      WaitForMove
   End If   

   'full tool change
   If ((acttool <> 0) and (newtool <> 0)) Then
      'unload tool
      'go to X/Y position (Y-before)
      Message "go to X/Y position"
      Code "G53 G90 G01 X"+CStr(Pos_X_Tool(acttool))+"Y"+CStr(Pos_Y_before)
      WaitForMove
      'goto Z-in fast
      Message "goto Z-in fast"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_in)
      WaitForMove
      'go to Y position in
      Message "go to Y position in"
      Code "G53 G90 G01 Y"+CStr(Pos_Y_in)+"F"+CStr(F_slow)
      WaitForMove
      'open toolclamp
      Message "open toolclamp"
      ActivateSignal(TC_output)
      Sleep(1000)
      'goto Z-over slow
      Message "goto Z-over slow"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_over)
      WaitForMove
   
      'load new tool
      'go to X/Y position
      Message "go to X/Y position"
      Code "G53 G90 G01 X"+CStr(Pos_X_Tool(newtool))+"Y"+CStr(Pos_Y_in)+"F"+CStr(F_fast)
      WaitForMove
      'goto Z-in slow
      Message "' goto Z-in slow"
      Code "G53 G90 G01 Z"+CStr(Pos_Z_in)+"F"+CStr(F_slow)
      WaitForMove
      'close toolclamp
      Message "close toolclamp"
      DeactivateSignal(TC_output)
      Sleep(1000)
      'go to Y position before
      Message "go to Y position before"
      Code "G53 G90 G01 Y"+CStr(Pos_Y_before)
      WaitForMove
      
   End If   
   
   
   ' go to save Z position
   Message "goto Z-save"
   Code "G53 G90 G01 Z"+CStr(Pos_Z_save)+"F"+CStr(F_fast)
   WaitForMove

   'restore the origin values
   Code "F" &CurrentFeed          'Returns to prior feed rate
   If CurrentAbsInc = 0 Then       'if G91 was in effect before then return to it
      Code "G91"
   End If
   If CurrentGMode = 0 Then    '   if G0 was in effect before then return to it
      Code "G0"
   End If   

   'Put previous Axis Scale factors back
   SetOEMDRO(59,XScale)
   SetOEMDRO(60,YScale)
   SetOEMDRO(61,ZScale)
   Sleep(250)

   'set new tool
    SetCurrentTool( newtool )
   
   ' go back to the position we came from
   Message "goto origin X/Y"
   Code "G53 G01 X"+CStr(CurrentXpos)+"Y"+CStr(CurrentYpos)
   WaitForMove
   Message "goto origin Z"
   Code "G53 G01 Z"+CStr(CurrentZpos)
   WaitForMove

   'set new tool
    SetCurrentTool( newtool )
   Message " "
   
End Sub


'global Sub's
Sub WaitForMove ()
   While IsMoving()
      Sleep(15)
   Wend
End Sub


Thanks Thomas you are a live saver,    ;) ;) ;) ;) ;) ;) ;)

Offline TPS

*
  •  2,535 2,535
Re: Commission work, Macro needed please help!
« Reply #4 on: February 02, 2018, 02:57:50 AM »
here the code in code tag, to Keep the Smileys out

Code: [Select]

 
' ---------------------------------------------------------------------------------
' TPS 26.01.2018 
' ATC macro for 8 places
' V 1.0.0
' ---------------------------------------------------------------------------------

' Main routine for tool change -----------------------------------------------------
Sub Main()

' declare ten global variables ----------------------------------------------------
  Dim Pos_X_Tool(8) as double

' variables for the feedrate
F_slow = 400 'feedrate for slow moves
F_fast = 2000 'feedrate for fast moves


'remark all TC position are in machine coordinates !!!

'variables for the X positions
Pos_X_Tool(1) = 100.0000 'X position for tool 1
Pos_X_Tool(2) = 200.0000 'X position for tool 2
Pos_X_Tool(3) = 300.0000 'X position for tool 3
Pos_X_Tool(4) = 400.0000 'X position for tool 4
Pos_X_Tool(5) = 500.0000 'X position for tool 5
Pos_X_Tool(6) = 600.0000 'X position for tool 6
Pos_X_Tool(7) = 700.0000 'X position for tool 7
Pos_X_Tool(8) = 800.0000 'X position for tool 8

'variables for the Y Position
Pos_Y_before = 200.0000 'Y position in front of TC
Pos_Y_in = 100.0000 'Y position in TC

'variables for the Z Position
Pos_Z_save = 300.0000 'Z position over all that we can move (X/Y) save to TC
Pos_Z_over = 200.0000 'Z position over the placed tool (X move possible)
Pos_Z_in = 100.0000 'Z position in TC

'variable for toolclamp output
TC_output = Output1

'variable for delay open/close toolclamp
TC_wait = 1000
 
' ---------------------------------------------------------------------------------


'get the tool relvated numbers
newtool = GetSelectedTool() 'get the new toolnumber
acttool  = GetCurrentTool() 'get the actual toolnumber

'do some basic check's

' no tool loaded nothing to unload
If ((newtool = 0) and (acttool = 0)) Then
message("no tool loaded nothing to unload !")
Exit Sub
End If

' nothing to do newtool = acttool
If newtool = acttool Then
message("nothing to do newtool = acttool !")
Exit Sub
End If
 
'check toolnumber in range
If  (((newtool > 8) Or (newtool < 1)) and (newtool <> 0)) Then
Message (" toolnumber " & newtool & " is not in range (1-8). abort toolchange  ! ")
DoButton(3)
Exit Sub
End If

'X-axis is not referenced
If GetOEMLED(807) Then
Message ("X-axis no reference -> abort !!")
DoButton(3)
Exit Sub
End If

'Y-axis is not referenced
If GetOEMLED(808) Then
Message ("Y-axis no reference -> abort !!")
DoButton(3)
Exit Sub
End If

'Z-axis is not referenced
If GetOEMLED(809) Then
Message ("Z-axis no reference -> abort !!")
DoButton(3)
Exit Sub
End If

Message "change tool: " +CStr(acttool) + " to: " + CStr(newtool)

'get the current position and settings
CurrentFeed = GetOemDRO(818)  'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
CurrentXpos = GetOemDRO(83) 'Get t X position where we came from
CurrentYpos = GetOemDRO(84) 'Get t Y position where we came from
CurrentZpos = GetOemDRO(85) 'Get t Z position where we came from

'Get Axis Scale factors in use
XScale = GetOEMDRO(59)
YScale = GetOEMDRO(60)
ZScale = GetOEMDRO(61)

'Set All Axis Scales to 1
SetOEMDRO(59,1)
SetOEMDRO(60,1)
SetOEMDRO(61,1)
Sleep(250)

' turn spindle off just in case
Code "M5"

' go to save Z position
Message "goto Z-save"
Code "G53 G90 G01 Z"+CStr(Pos_Z_save)+"F"+CStr(F_fast)
WaitForMove

'only unload tool
If newtool = 0 Then
'go to X/Y position (Y-before)
Message "go to X/Y position"
Code "G53 G90 G01 X"+CStr(Pos_X_Tool(acttool))+"Y"+CStr(Pos_Y_before)
WaitForMove
'goto Z-in fast
Message "goto Z-in fast"
Code "G53 G90 G01 Z"+CStr(Pos_Z_in)
WaitForMove
'go to Y position in
Message "go to Y position in"
Code "G53 G90 G01 Y"+CStr(Pos_Y_in)+"F"+CStr(F_slow)
WaitForMove
'open toolclamp
Message "open toolclamp"
ActivateSignal(TC_output)
Sleep(TC_wait)
'goto Z-over slow
Message "goto Z-over slow"
Code "G53 G90 G01 Z"+CStr(Pos_Z_over)
WaitForMove
End If

'only load tool
If acttool = 0 Then
'go to X/Y position
Message "go to X/Y position"
Code "G53 G90 G01 X"+CStr(Pos_X_Tool(newtool))+"Y"+CStr(Pos_Y_in)
WaitForMove
'goto Z-over fast
Message "goto Z-over fast"
Code "G53 G90 G01 Z"+CStr(Pos_Z_over)
WaitForMove
'open toolclamp
Message "open toolclamp"
ActivateSignal(TC_output)
Sleep(TC_wait)
'goto Z-in slow
Message "' goto Z-in slow"
Code "G53 G90 G01 Z"+CStr(Pos_Z_in)+"F"+CStr(F_slow)
WaitForMove
'close toolclamp
Message "close toolclamp"
DeactivateSignal(TC_output)
Sleep(TC_wait)
'go to Y position before
Message "go to Y position before"
Code "G53 G90 G01 Y"+CStr(Pos_Y_before)
WaitForMove
End If

'full tool change
If ((acttool <> 0) and (newtool <> 0)) Then
'unload tool
'go to X/Y position (Y-before)
Message "go to X/Y position"
Code "G53 G90 G01 X"+CStr(Pos_X_Tool(acttool))+"Y"+CStr(Pos_Y_before)
WaitForMove
'goto Z-in fast
Message "goto Z-in fast"
Code "G53 G90 G01 Z"+CStr(Pos_Z_in)
WaitForMove
'go to Y position in
Message "go to Y position in"
Code "G53 G90 G01 Y"+CStr(Pos_Y_in)+"F"+CStr(F_slow)
WaitForMove
'open toolclamp
Message "open toolclamp"
ActivateSignal(TC_output)
Sleep(TC_wait)
'goto Z-over slow
Message "goto Z-over slow"
Code "G53 G90 G01 Z"+CStr(Pos_Z_over)
WaitForMove

'load new tool
'go to X/Y position
Message "go to X/Y position"
Code "G53 G90 G01 X"+CStr(Pos_X_Tool(newtool))+"Y"+CStr(Pos_Y_in)+"F"+CStr(F_fast)
WaitForMove
'goto Z-in slow
Message "' goto Z-in slow"
Code "G53 G90 G01 Z"+CStr(Pos_Z_in)+"F"+CStr(F_slow)
WaitForMove
'close toolclamp
Message "close toolclamp"
DeactivateSignal(TC_output)
Sleep(TC_wait)
'go to Y position before
Message "go to Y position before"
Code "G53 G90 G01 Y"+CStr(Pos_Y_before)
WaitForMove

End If


' go to save Z position
Message "goto Z-save"
Code "G53 G90 G01 Z"+CStr(Pos_Z_save)+"F"+CStr(F_fast)
WaitForMove

'restore the origin values
Code "F" &CurrentFeed 'Returns to prior feed rate
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
End If
If CurrentGMode = 0 Then ' if G0 was in effect before then return to it
Code "G0"
End If   

'Put previous Axis Scale factors back
SetOEMDRO(59,XScale)
SetOEMDRO(60,YScale)
SetOEMDRO(61,ZScale)
Sleep(250)

'set new tool
    SetCurrentTool( newtool )

' go back to the position we came from
Message "goto origin X/Y"
Code "G53 G01 X"+CStr(CurrentXpos)+"Y"+CStr(CurrentYpos)
WaitForMove
Message "goto origin Z"
Code "G53 G01 Z"+CStr(CurrentZpos)
WaitForMove

'set new tool
    SetCurrentTool( newtool )
Message " "

End Sub


'global Sub's
Sub WaitForMove ()
While IsMoving()
Sleep(15)
Wend
End Sub



anything is possible, just try to do it.
if you find some mistakes, in my bad bavarian english,they are yours.