Hello Guest it is November 08, 2024, 09:44:57 PM

Author Topic: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog  (Read 30776 times)

0 Members and 1 Guest are viewing this topic.

Hi,

I've written a macro for an ATC carousel type using an Ac motor. Each motor rotation indexes the carousel by one position.
I can drive it CW or CCW. There's two inductive sensors, one fro the Ac motor rotation ( i++ or i--) and one for the carousel Home Position.
The carousel is sent in tool change position by an air cylinder, the only driven axis is Z.

I tried to use it and have a scripter compile error.

If someone would tell me what's wrong?

Thanks for your attention,

J.

Here's the code:

Sub Main()
'Global variables declaration
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()

'Flow sequence

'Compare between actual tool and requested tool
call Compare
'Carrousel air cylinder position check : Home, in Mvt and ToolChange
call AirCyHome
call ToolChangerPos
'Move to Z tool position and wait until position reached
call Z_TcPosition
'Spindle Home Sequence
call SpindleHome
'Activate air cylinder valve to put old tool back to carrousel
call OldToolBack2TC
'Spindle: Tool Unclamp
call Unclamp
'Go to safe tool change Z coordinates
call Z_TcPosition
'Spindle: Tool Clamp
call Clamp
'Sequence to determine the least travel to move for TC, CW or CCW
call LeastTravel
'Turn CW or turn CCW integrated in above Sub
'Activate air cylinder valve to put old tool back to carrousel
call OldToolBack2TC
'Spindle: Tool Unclamp
call Unclamp
'Move to Z tool position and wait until position reached
call Z_TcPosition
'Spindle: Tool Clamp
call Clamp
'Air Cylinder Homing
call AirCyHome
'Store new tool as actual tool value
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )

' Compare between actual tool and requested tool

Function Compare() As Integer
   Dim Compare As Integer
   If NewTool = OldTool Then
   Compare = 1
   Else
   Compare = 0
   End If
End Function

'Carrousel air cylinder position check : Home, in Mvt and ToolChange
Function ToolChangerPos() As Boolean
   If IsActive(INPUT1)>IsActive(INPUT2)Then 'We are at Home Position
   ToolChangerPos = 0
   TCMove = False 'We are stopped
   
   ElseIf IsActive(INPUT1)<IsActive(INPUT2) Then
      ToolChangerPos = 1
      TCMove = False
      Else
      ToolChangerPos = -1
      TCMove = True
   End If
End Function

'Air Cylinder Homing
sub AirCyHome()
   DeactivateSignal(OUTPUT8)
   AirCyHome=IsActive(INPUT1)
end sub


'Move to Z tool position and wait until position reached
Sub Z_TcPosition() As Integer
   code("G53")'Move in Absolute Machine coordinates
   while(IsMoving())
      Sleep(100)'temporisation entre while++
   Wend
   code("G00 Z-116") 'Z value as to be checked for exact match with carrousel height
   while(IsMoving())
      Sleep(100)'temporisation entre while++
   Wend
   Z_TcPosition=1 '1 quand en position pour Tool Change
end Sub

'Spindle Home Sequence
Sub SpindleHome()
   ActivateSignal(OUTPUT1)'activate spindle indexing for ToolChange
   while(IsMoving())'Do nothing while spindle is rotating
      sleep(100)
   wend
   'Maybe necessary to invoke a case select for tooling choice if more than 10 tools
end sub

'Spindle Release
Sub SpindleRelease()
   DeactivateSignal(OUTPUT1)
end sub

'Put old tool back to carrousel
'Maybe necessary to invoke a case select for tooling choice if more than 10 tools
sub OldToolBack2TC ()
   If Z_TcPosition=1 then
      Activate Signal(OUTPUT8)'Move carrousel via the air cylinder to reach the tool change position
   else
      call Z_TcPosition
   End if
end Sub
 
'Spindle: Tool Unclamp
Sub Unclamp()
   If IsActive(INPUT2)'Sensor indicates that carrousel is at tool change position then
      ActivateSignal(OUTPUT9)'Release the tool, unclamp
   End If
end Sub

'Spindle: Tool Clamp
Sub Clamp()
   DeactivateSignal(OUTPUT9)'Grip the tool, Clamp
end Sub

'Go to safe tool change Z coordinates
Sub ZUp_TcPosition() as Integer
   ZUp_TcPosition=0 'var init
   code("G53") 'Move in absolute machine coordinates
   while(IsMoving())
      Sleep(100)
   code("G00 Z-35")'Move to the safe Z position for tool change
   while (IsMoving())
      sleep(100) '0.1sec delay between loops
   wend
   ZUp_TcPosition=1
end Sub

'Sequence to determine the least travel to move for TC, CW or CCW
'atp = Actual tool position, rtp = Requested tool positon
Sub LeastTravel()
   NTool = 10 ' Number of tools changer holds
   CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
   If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
      CWPos = CWPos + NTools
   End If
   CCWPos = NTools - CWPos
   If CWPos < CCWPos Then
      call CW()
   Else
      call CCW()
   End If
End Sub

'Rotation CW

Sub CW()
   dim x as Integer
   dim CTPos as Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(OUTPUT10)'Turns the AC Motor On
   Do until IsActive(OEMTrig1)
      Sleep(50)
   loop
      for x=0 to CWPos
         If IsActive(OEMTrig1) then
            x=x+1
            While IsActive(OEMTrig1)
               'Wait for OEMTrig to de-assert
            End While
         End If
      next x
      CTPos=x
   DeactivateSignal(OUTPUT10)
End Sub

'Rotation CCW

Sub CCW()
   dim y as Integer
   dim CTPos as Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(OUTPUT11)
   Do until IsActive(OEMTrig1) 'Turns the AC Motor On
      Sleep(50)
   loop
   for y=0 to CCWPos
      If IsActive(OEMTrig1) then
      y=y+1
         While IsActive(OEMTrig1)
            'Wait for OEMTrig to de-assert
         End While   
      End If            
   next y
   CTPos=y
   DeactivateSignal(OUTPUT11)
End Sub

Main

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #1 on: May 06, 2012, 02:56:50 PM »
Try;

While IsMoving()
Wend

Instead of

While (IsMoving())
Wend
Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #2 on: May 06, 2012, 03:07:43 PM »
Hi,

I removed all occurrences and it doesn't give better results.
I also tried a very simple test by making calls to the clamp and unclamp subs only, without any change in the error message.

I'm a newbie in macro programming so I probably missed something but what...

J.
 

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #3 on: May 06, 2012, 03:40:50 PM »
I didn't read the whole thing, and I'm no expert, but here's another issue. This:
  while(IsMoving())
      Sleep(100)
   code("G00 Z-35")'Move to the safe Z position for tool change
   while (IsMoving())

Should be this:

Code "G00 Z-35"
While IsMoving()
Wend

You don't need the Sleep() in the While IsMoving().


Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #4 on: May 06, 2012, 04:49:23 PM »
Hi Gerry,

I tried that and other changes like a mix with(out) parenthesis :

IsMoving()<>(IsMoving())
code("G00 Z-35")<>Code "G00 Z-35"
This doesn't gave me any results.

I will try without using calls, maybe I'm not using them well:

Call Statement
Call funcname [(parameter(s)]
or
[parameter(s)]
Activates an Enable Subroutine called name or a DLL function with the
name name. The first parameter is the name of the function or
subroutine to call, and the second is the list of arguments to pass to the
called function or subroutine.
You are never required to use the Call statement when calling an
Enable subroutine or a DLL function. Parentheses must be used in the
argument list if the Call statement is being used.
Example:
Sub Main ()
Call Beep MsgBox "Returns a Beep"
End Sub

Source: Language Reference page 45 Cypress Enable for Mach


So if someone has a good idea, he's welcome.

Thanks for help,
J.

Offline ger21

*
  • *
  •  6,295 6,295
    • The CNC Woodworker
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #5 on: May 06, 2012, 06:43:00 PM »
Everything I told you is correct. Yuo probably have multiple issues, and you'll need them all fixed before it will work.

I usually add msgbox statements to track down trouble areas.
Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #6 on: May 06, 2012, 09:09:49 PM »
Hi Gerry,

I started debugging this evening, more to come tomorrow.
I suppressed some functions and have to try some tests.
Good suggestion about the msgbox.

I'll keep in touch.

Regards,

J.

PS: I had some corrections made by other sources and tested both () solutions.


Offline BR549

*
  •  6,965 6,965
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #7 on: May 07, 2012, 09:57:09 AM »
It appears mach3 is having problems in the way you are using the Function and sub calls. I cleaned up all the obvious problems but still get errors on the function calls and sub calls.  Not being a programmer can't be much more help.

I can get it to work BUT it sure is NOT a pretty way to do it. (so I am told(;-) ).

IF you can't get it worked out I will dive into it with you and see IF we can get it working.  THERE are VB WIZARDS on here so hopefully they will chime in on this one.

(;-) TP
« Last Edit: May 07, 2012, 09:59:34 AM by BR549 »
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #8 on: May 07, 2012, 08:55:17 PM »
Hi,

I started to make many debugging tests and files to see what ans why.

Here is an example of code, partial since there's not all the functionalities.

If I add the Sub Main() and End at the end it's not working, syntax error, and if I don't, it's the same....
For clarity reasons I'll post another one message with other code related issues.

Regards,

J.

'Global variables declaration
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
Dim Z_TcPos As Integer
Dim ZUp_TcPos As Integer
'Flow sequence


' Compare between actual tool and requested tool

If NewTool = OldTool Then
   End
   Else
End If


'Carrousel air cylinder position check : Home, in Mvt and ToolChange
'Call AirCyHome
   DeactivateSignal(OUTPUT8)
   AirCyHome=IsActive(INPUT1)

'Spindle Home Sequence
'Call SpindleHome
   ActivateSignal(OUTPUT1)'activate spindle indexing for ToolChange
   Sleep (500)
   While(IsMoving())'Do nothing while spindle is rotating
      sleep(100)
   Wend
' Show the user the state of the OUTPUT #1 input
   If IsActive(OUTPUT1) Then
   MsgBox "OUTPUT #1 output is active"
   Else
   MsgBox "OUTPUT #1 output is inactive"
   End If

'Spindle: Tool Clamp
'Call Clamp

   DeactivateSignal(OUTPUT9)'Grip the tool, Clamp


'Sequence to determine the least travel to move for TC, CW or CCW
'Call LeastTravel

   NTool = 10 ' Number of tools changer holds
   CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
   If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
      CWPos = CWPos + NTools
   End If
   CCWPos = NTools - CWPos
   If CWPos < CCWPos Then
         
   Dim x As Integer
   Dim CTPos As Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(OUTPUT10)'Turns the AC Motor On
   Do Until IsActive(OEMTrig1)
      Sleep(50)
   Loop
      For x=0 To CWPos
         If IsActive(OEMTrig1) Then
            x=x+1
            While IsActive(OEMTrig1)
               'Wait for OEMTrig to de-assert
            Wend
         End If
      Next x
      CTPos=x
   DeactivateSignal(OUTPUT10)
         
   Else
   'Rotation CCW
   Dim y As Integer
   CTPos=0
   ActivateSignal(OUTPUT11)
   Do Until IsActive(OEMTrig1) 'Turns the AC Motor On
      Sleep(50)
   Loop
   For y=0 To CCWPos
      If IsActive(OEMTrig1) Then
      y=y+1
         While IsActive(OEMTrig1)
            'Wait for OEMTrig to de-assert
         Wend   
      End If            
   Next y
   CTPos=y
   DeactivateSignal(OUTPUT11)
   
   End If
   
'Turn CW or turn CCW integrated in above Sub

'Move to Z tool position and wait until position reached
'Call Z_TcPosition

   code("G53")'Move in Absolute Machine coordinates
   While(IsMoving())
      Sleep(100)'temporisation entre while++
   Wend
   code("G00 Z-116") 'Z value as to be checked for exact match with carrousel height
   While(IsMoving())
      Sleep(100)'temporisation entre while++
   Wend
   Z_TcPos=1 '1 quand en position pour Tool Change

'Activate air cylinder valve to put old tool back to carrousel
'Call OldToolBack2TC
   If Z_TcPos=1 Then
      ActivateSignal(OUTPUT8)'Move carrousel via the air cylinder to reach the tool change position
   Else
      Call Z_TcPosition
   End If

'Spindle: Tool Unclamp
'Call Unclamp

If IsActive(INPUT2) Then'Sensor indicates that carrousel is at tool change position then
       ActivateSignal(OUTPUT9)'Release the tool, unclamp

'Move to Z tool position and wait until position reached
'Call ZUp_TcPosition

   ZUp_TcPos=0 'var init
   code("G53") 'Move in absolute machine coordinates
   While(IsMoving())
      Sleep(100)
   Wend   
   code("G00 Z-35")'Move to the safe Z position for tool change
   While(IsMoving())
      sleep(100) '0.1sec delay between loops
   Wend
   ZUp_TcPos=1


'Spindle: Tool Clamp
'Call Clamp

DeactivateSignal(OUTPUT9)'Grip the tool, Clamp
'Spindle Release
DeactivateSignal(OUTPUT1)

'Air Cylinder Homing
'Call AirCyHome

   DeactivateSignal(OUTPUT8)
   AirCyHome=IsActive(INPUT1)
   While (Not(AirCyHome))
   Sleep(100)
   Wend
   
'Store new tool as actual tool value
Call SetUserDRO (1200,NewTool)
Call SetCurrentTool( NewTool )
 
Re: ATC automatic tool change M6 macro Dynomotion Kflop+Kanalog
« Reply #9 on: May 07, 2012, 09:01:49 PM »
Hi,


This is basically the same code than before, excepted that I use Functions rather than subs. It's a little bit better, I can have Z moves but nothing more.
Normally the OUTPUT1 should be activated but there's no actions, MsgBox confirms the statement.
Something strange occurs, my call sequence isn't respected, I can check that using more MsgBox.

If I try to use the functions inside the Main Sub, this is not working at all: Syntax error, this is also strange to me.

Thanks for your attention,

Jerome


Sub Main()
'Global variables declaration
NewTool = GetSelectedTool()
OldTool = GetCurrentTool()
Dim Z_TcPos As Integer
Dim ZUp_TcPos As Integer


'Flow sequence


' Compare between actual tool and requested tool

If NewTool = OldTool Then
   End
   Else
End If
ActivateSignal(OUTPUT1)
'Carrousel air cylinder position check : Home, in Mvt and ToolChange
Call AirCyHome
MsgBox "Carrousel air cylinder position check"
'Spindle Home Sequence
Call SpindleHome
MsgBox "Spindle Home call"
'Spindle: Tool Clamp
Call Clamp
'Sequence to determine the least travel to move for TC, CW or CCW
Call LeastTravel
'Turn CW or turn CCW integrated in above Sub
'Activate air cylinder valve to put old tool back to carrousel
Call OldToolBack2TC
'Spindle: Tool Unclamp
Call Unclamp
'Move to Z tool position and wait until position reached
Call Z_TcPosition
'Spindle: Tool Clamp
Call Clamp
'Air Cylinder Homing
Call AirCyHome
'Store new tool as actual tool value
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )

End Sub



'Carrousel air cylinder position check : Home, in Mvt and ToolChange
Function ToolChangerPos()
   If IsActive(INPUT1)>IsActive(INPUT2)Then 'We are at Home Position
   ToolChangerPos = 0
   TCMove = False 'We are stopped

   ElseIf IsActive(INPUT1)<IsActive(INPUT2) Then
      ToolChangerPos = 1
      TCMove = False
      
      ToolChangerPos = -1
      TCMove = True
   End If
End Function

'Air Cylinder Homing
Function AirCyHome() As Integer
   DeactivateSignal(OUTPUT8)
   AirCyHome=IsActive(INPUT1)
End Function
'Spindle Home Sequence
Function SpindleHome()
   ActivateSignal(OUTPUT1)'activate spindle indexing for ToolChange
   While(IsMoving())'Do nothing while spindle is rotating
      sleep(100)
   Wend
   'Maybe necessary to invoke a case select for tooling choice if more than 10 tools
'Show the user the state of the OUTPUT #1 input
If IsActive(OUTPUT1) Then
MsgBox "OUTPUT #1 output is active"
Else
MsgBox "OUTPUT #1 output is inactive"
End If
   Call ToolChangerPos
'Move to Z tool position and wait until position reached
   Call ZUp_TcPosition

'Activate air cylinder valve to put old tool back to carrousel
   Call OldToolBack2TC
'Spindle: Tool Unclamp
   Call Unclamp
'Go to safe tool change Z coordinates
   Call ZUp_TcPosition
End Function


'Move to Z tool position and wait until position reached
Function Z_TcPosition()
   code("G53")'Move in Absolute Machine coordinates
   While(IsMoving())
      Sleep(100)'temporisation entre while++
   Wend
   code("G00 Z-116") 'Z value as to be checked for exact match with carrousel height
   While(IsMoving())
      Sleep(100)'temporisation entre while++
   Wend
   Z_TcPos=1 '1 quand en position pour Tool Change
End Function

'Spindle Home Sequence


'Spindle Release
Function SpindleRelease()
   DeactivateSignal(OUTPUT1)
End Function

'Put old tool back to carrousel
'Maybe necessary to invoke a case select for tooling choice if more than 10 tools
Function OldToolBack2TC ()
   If Z_TcPos=1 Then
      ActivateSignal(OUTPUT8)'Move carrousel via the air cylinder to reach the tool change position
   else
      Call Z_TcPosition
   End if
End Function
 
'Spindle: Tool Unclamp
Function Unclamp()
   If IsActive(INPUT2) then'Sensor indicates that carrousel is at tool change position then
       ActivateSignal(OUTPUT9)'Release the tool, unclamp
   End If
End Function

'Spindle: Tool Clamp
Function Clamp()
   DeactivateSignal(OUTPUT9)'Grip the tool, Clamp
End Function

'Go to safe tool change Z coordinates
Function ZUp_TcPosition()
   ZUp_TcPos=0 'var init
   code("G53") 'Move in absolute machine coordinates
   While(IsMoving())
      Sleep(100)
   Wend   
   code("G00 Z-35")'Move to the safe Z position for tool change
   while(IsMoving())
      sleep(100) '0.1sec delay between loops
   wend
   ZUp_TcPos=1
End Function

'Sequence to determine the least travel to move for TC, CW or CCW
'atp = Actual tool position, rtp = Requested tool positon
Function LeastTravel()
   NTool = 10 ' Number of tools changer holds
   CWPos = GetSelectedTool() - GetCurrentTool() ' Assume a CW move
   If CWPos < 0 Then ' CWPos < 0 ==> rtp < atp
      CWPos = CWPos + NTools
   End If
   CCWPos = NTools - CWPos
   If CWPos < CCWPos Then
      call CW()
   Else
      call CCW()
   End If
End Function

'Rotation CW

Function CW()
   dim x as Integer
   dim CTPos as Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(OUTPUT10)'Turns the AC Motor On
   Do until IsActive(OEMTrig1)
      Sleep(50)
   loop
      for x=0 to CWPos
         If IsActive(OEMTrig1) then
            x=x+1
            While IsActive(OEMTrig1)
               'Wait for OEMTrig to de-assert
            Wend
         End If
      next x
      CTPos=x
   DeactivateSignal(OUTPUT10)
End Function

'Rotation CCW

Function CCW()
   dim y as Integer
   dim CTPos as Integer 'Carrousel Tool Position Relative to OldTool Position
   CTPos=0
   ActivateSignal(OUTPUT11)
   Do until IsActive(OEMTrig1) 'Turns the AC Motor On
      Sleep(50)
   loop
   for y=0 to CCWPos
      If IsActive(OEMTrig1) then
      y=y+1
         While IsActive(OEMTrig1)
            'Wait for OEMTrig to de-assert
         Wend   
      End If            
   next y
   CTPos=y
   DeactivateSignal(OUTPUT11)
End Function

Main