Hello Guest it is May 07, 2024, 09:06:02 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - jewe

Pages: 1
1
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

Pages: 1