Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: NinoR on June 29, 2023, 03:00:14 AM

Title: Lathe ATC turret VB
Post by: NinoR on June 29, 2023, 03:00:14 AM
Hello.

Im currently retrofitting cnc lathe machine with 6 position turret. Controller is CS-labs.

Its stopped for me with vb script M6start. I just copied script text in it, checked atc in general config but after putting T1 M6m (T0101 M6) nothing happens , just a beep without any message. VB script go through without any warning.

How to solve this issue?

Greetings Nino
Title: Re: Lathe ATC turret VB
Post by: TPS on June 29, 2023, 04:50:14 AM
without showing us your script it will be realy hard to help.
Title: Re: Lathe ATC turret VB
Post by: NinoR on June 29, 2023, 05:48:56 AM
Hello.

This is code.

Code: [Select]
'------------------------------------------------------------------------------
' CS-Lab s.c. - Auto toolchanger for lathe (rotary type of ATC)
' (C) 2011
' v1.2 - 2011-11-05
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' CONFIG
'------------------------------------------------------------------------------
Const OpenSensDelay = 800 ' Time Delay [ms] after ATC unlock
Const TimeLock = 1000 ' ATC locking time delay
Const TOOLCOUNT = 8 ' max Tool #

' Actual ATC position inputs (CSMIO-IP inputs)
Const InT1 = 16
Const InT2 = 17
Const InT3 = 18
Const InT4 = 19
Const InT5 = 20
Const InT6 = 21
Const InT7 = 22
Const InT8 = 23

' ATC sensors inputs
Const InOpenSensor = 25 ' ATC unlocked (rotating)
Const InCloseSensor = 24 ' ATC locked - safe

' digital outputs for ATC control (CSMIO outputs)
Const OutRun = 4 ' unlock and rotate
Const OutLock = 5 ' stop rotation and lock at current position

'------------------------------------------------------------------------------
' program variables - don't modify
'------------------------------------------------------------------------------
Dim ToolNew, ToolOld, ToolSlot As Integer
Dim ToolRdy As Boolean
Dim ATC_CloseRetry
Dim InToolSens(TOOLCOUNT)

'------------------------------------------------------------------------------
  ' MACRO START
'------------------------------------------------------------------------------
if(GetOEMLed(800)) Then
Message("System jest w trybie ESTOP - WYMIANA PRZERWANA")
Sleep(150)
WaitForMove
End
End If

  SetUserLED(1001, 1) ' User LED - toolchange in progress
 
  InToolSens(0) = InT1
  InToolSens(1) = InT2
  InToolSens(2) = InT3
  InToolSens(3) = InT4
  InToolSens(4) = InT5
  InToolSens(5) = InT6
  InToolSens(6) = InT7
  InToolSens(7) = InT8

' Get actual tool # and new tool #
ToolOld = GetCurrentTool()
ToolNew = GetSelectedTool()

' little trick for double slots ATC
If(ToolNew >= 10) Then
ToolSlot = ToolNew - 10
Else
ToolSlot = ToolNew
End If

If(ToolOld >= 10) Then
ToolOld = ToolOld - 10
End If

' The same position - no need to move
If (ToolSlot = ToolOld) Then
SetCurrentTool( ToolNew )
Message("ATC is on position "& ToolSlot & " and new tool is " & ToolNew)
WaitForMove
SetUserLED(1001, 0)
End
End If

If (ToolSlot > TOOLCOUNT) Then
SetCurrentTool( ToolOld )
SetUserLED(1001, 0)
DoOEMButton(1003)
DoOEMButton(1002)
Sleep(150)
Message("There is no tool T" & ToolNew & " in ATC")
Sleep(150)
End
End If


' T0 is a fake tool, no need to change
If (ToolSlot = 0) Then
ToolNew = 0
SetCurrentTool( ToolNew )
Message("Za³adowano narzêdzie nr: " & ToolNew)
WaitForMove
SetUserLED(1001, 0)
End
End If


' unlock and rotate ATC
RunATC
Sleep( OpenSensDelay )
' check ATC open sensor
If (Not GetCsmioIn(InOpenSensor)) Then
LockATC
SetCurrentTool( 0 )
SetUserLED(1001, 0)
DoOEMButton(1021)
DoOEMButton(1002)
Sleep(150)
Message("ATC locked - toolchange failed.")
Sleep(150)
End
End If

' wait to ATC will be on the desired position
ToolRdy = false
While(Not ToolRdy)
If(GetCsmioIn((InToolSens(ToolSlot - 1)))) Then
ToolRdy = true
End If
Wend


' stop rotation and lock ATC
LockATC
ATC_CloseRetry = 0
' Check lock sensor, retry lock if needed
While(Not GetCsmioIn(InCloseSensor) And ATC_CloseRetry < 4)
LockATC
ATC_CloseRetry = ATC_CloseRetry + 1
Wend

' double check for succesful ATC lock
If (Not GetCsmioIn(InCloseSensor)) Then
SetCurrentTool( 0 )
SetUserLED(1001, 0)
DoOEMButton(1021)
DoOEMButton(1002)
Sleep(150)
Message("ATC lock alert. Check ATC.")
Sleep(150)
End
End If
 
SetCurrentTool( ToolNew )
Message("Succesful loaded tool T" & ToolNew)
Sleep(150)
WaitForMove
SetUserLED(1001, 0)
End
' -----------------------------------------------------------------------------
Public Function GetCsmioIn (n As Integer) As Boolean
Dim reg As Integer

If(n < 16) Then
reg = 90
Else
reg = 91
n = n - 16
End If

If(GetInBit(reg, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
Exit Function
End Function
' -----------------------------------------------------------------------------
Sub RunATC ()
Call SetCsmioOut(OutLock, false)
Sleep(150)
Call SetCsmioOut(OutRun, true)
Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Sub LockATC ()
Call SetCsmioOut(OutRun, false)
Sleep(150)
Call SetCsmioOut(OutLock, true)
Sleep(TimeLock)
Call SetCsmioOut(OutLock, false)
Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Public Sub SetCsmioOut (ByVal n As Integer, ByVal state As Boolean)
If(state) Then
SetOutBit(90, n)
Else
ResetOutBit(90, n)
End If
End Sub
' -----------------------------------------------------------------------------
Sub WaitForMove ()
While IsMoving()
Sleep(15)
Wend
End Sub                                                 

grettings Nino
Title: Re: Lathe ATC turret VB
Post by: TPS on June 29, 2023, 06:13:03 AM
are the in/outputnumber in the config aeria of the script corresponding to you hardware?
the script is for a 8 place ATC, you wher talking from a 6 place ATC.
how does your ATC hardware look like?
Title: Re: Lathe ATC turret VB
Post by: NinoR on June 29, 2023, 06:41:42 AM
Its actually for 6 tools, im currently at work and i posted online version of script.
I changed only tool count to 6, deleted const int7 and 8 and set in&out pins to my setting.

Hardware is 6 poz rotary switch, lock sw NO+NC, motor fwd/rew and brake.

Electricaly everything works, i get every input and output correct.

As i mentioned, if i run vb , go through without errors. When i want to control it through mdi T1M6 nothing happens.

Greetings Nino
Title: Re: Lathe ATC turret VB
Post by: TPS on June 29, 2023, 06:44:23 AM
pls post the script you are using, if you are back home.
Title: Re: Lathe ATC turret VB
Post by: NinoR on June 29, 2023, 11:23:54 AM
Hello.

Here is my code. It is connected trough csmio IO module , module nr0 (register 100).

Code: [Select]
'------------------------------------------------------------------------------ NINO_version_0
' CS-Lab s.c. - Auto toolchanger for lathe (rotary type of ATC)
' (C) 2011
' v1.2 - 2011-11-05
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' CONFIG
'------------------------------------------------------------------------------
Const OpenSensDelay = 800 ' Time Delay [ms] after ATC unlock
Const TimeLock = 1000 ' ATC locking time delay
Const TOOLCOUNT = 6 ' max Tool #

' Actual ATC position inputs (CSMIO-IP inputs)
Const InT1 = 0
Const InT2 = 1
Const InT3 = 2
Const InT4 = 3
Const InT5 = 4
Const InT6 = 5
' Const InT7 =
' Const InT8 =

' ATC sensors inputs
Const InOpenSensor = 6 ' ATC unlocked (rotating)
Const InCloseSensor = 7 ' ATC locked - safe

' digital outputs for ATC control (CSMIO outputs)
Const OutRun = 0 ' unlock and rotate
Const OutLock = 1 ' stop rotation and lock at current position

'------------------------------------------------------------------------------
' program variables - don't modify
'------------------------------------------------------------------------------
Dim ToolNew, ToolOld, ToolSlot As Integer
Dim ToolRdy As Boolean
Dim ATC_CloseRetry
Dim InToolSens(TOOLCOUNT)

'------------------------------------------------------------------------------
  ' MACRO START
'------------------------------------------------------------------------------
if(GetOEMLed(800)) Then
Message("System jest w trybie ESTOP - WYMIANA PRZERWANA")
Sleep(150)
WaitForMove
End
End If

  SetUserLED(1001, 1) ' User LED - toolchange in progress
 
  InToolSens(0) = InT1
  InToolSens(1) = InT2
  InToolSens(2) = InT3
  InToolSens(3) = InT4
  InToolSens(4) = InT5
  InToolSens(5) = InT6
  InToolSens(6) = InT7
  InToolSens(7) = InT8

' Get actual tool # and new tool #
ToolOld = GetCurrentTool()
ToolNew = GetSelectedTool()

' little trick for double slots ATC
If(ToolNew >= 10) Then
ToolSlot = ToolNew - 10
Else
ToolSlot = ToolNew
End If

If(ToolOld >= 10) Then
ToolOld = ToolOld - 10
End If

' The same position - no need to move
If (ToolSlot = ToolOld) Then
SetCurrentTool( ToolNew )
Message("ATC is on position "& ToolSlot & " and new tool is " & ToolNew)
WaitForMove
SetUserLED(1001, 0)
End
End If

If (ToolSlot > TOOLCOUNT) Then
SetCurrentTool( ToolOld )
SetUserLED(1001, 0)
DoOEMButton(1003)
DoOEMButton(1002)
Sleep(150)
Message("There is no tool T" & ToolNew & " in ATC")
Sleep(150)
End
End If


' T0 is a fake tool, no need to change
If (ToolSlot = 0) Then
ToolNew = 0
SetCurrentTool( ToolNew )
Message("Za³adowano narzêdzie nr: " & ToolNew)
WaitForMove
SetUserLED(1001, 0)
End
End If


' unlock and rotate ATC
RunATC
Sleep( OpenSensDelay )
' check ATC open sensor
If (Not GetCsmioIn(InOpenSensor)) Then
LockATC
SetCurrentTool( 0 )
SetUserLED(1001, 0)
DoOEMButton(1021)
DoOEMButton(1002)
Sleep(150)
Message("ATC locked - toolchange failed.")
Sleep(150)
End
End If

' wait to ATC will be on the desired position
ToolRdy = false
While(Not ToolRdy)
If(GetCsmioIn((InToolSens(ToolSlot - 1)))) Then
ToolRdy = true
End If
Wend


' stop rotation and lock ATC
LockATC
ATC_CloseRetry = 0
' Check lock sensor, retry lock if needed
While(Not GetCsmioIn(InCloseSensor) And ATC_CloseRetry < 4)
LockATC
ATC_CloseRetry = ATC_CloseRetry + 1
Wend

' double check for succesful ATC lock
If (Not GetCsmioIn(InCloseSensor)) Then
SetCurrentTool( 0 )
SetUserLED(1001, 0)
DoOEMButton(1021)
DoOEMButton(1002)
Sleep(150)
Message("ATC lock alert. Check ATC.")
Sleep(150)
End
End If
 
SetCurrentTool( ToolNew )
Message("Succesful loaded tool T" & ToolNew)
Sleep(150)
WaitForMove
SetUserLED(1001, 0)
End
' -----------------------------------------------------------------------------
Public Function GetCsmioIn (n As Integer) As Boolean
Dim reg As Integer

If(n < 16) Then
reg = 100
Else
reg = 101
n = n - 16
End If

If(GetInBit(reg, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
Exit Function
End Function
' -----------------------------------------------------------------------------
Sub RunATC ()
Call SetCsmioOut(OutLock, false)
Sleep(150)
Call SetCsmioOut(OutRun, true)
Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Sub LockATC ()
Call SetCsmioOut(OutRun, false)
Sleep(150)
Call SetCsmioOut(OutLock, true)
Sleep(TimeLock)
Call SetCsmioOut(OutLock, false)
Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Public Sub SetCsmioOut (ByVal n As Integer, ByVal state As Boolean)
If(state) Then
SetOutBit(100, n)
Else
ResetOutBit(100, n)
End If
End Sub
' -----------------------------------------------------------------------------
Sub WaitForMove ()
While IsMoving()
Sleep(15)
Wend
End Sub                                                 

Greetings Nino
Title: Re: Lathe ATC turret VB
Post by: Graham Waterworth on June 29, 2023, 04:38:22 PM
Lathes do NOT use T1 M6 they use T0101

Title: Re: Lathe ATC turret VB
Post by: TPS on June 30, 2023, 02:15:22 AM
made some changes, marked with TPS
Code: [Select]
'------------------------------------------------------------------------------ NINO_version_0
' CS-Lab s.c. - Auto toolchanger for lathe (rotary type of ATC)
' (C) 2011
' v1.2 - 2011-11-05
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
' CONFIG
'------------------------------------------------------------------------------
Const OpenSensDelay = 800 ' Time Delay [ms] after ATC unlock
Const TimeLock = 1000 ' ATC locking time delay
Const TOOLCOUNT = 6 ' max Tool #

' Actual ATC position inputs (CSMIO-IP inputs)
Const InT1 = 0
Const InT2 = 1
Const InT3 = 2
Const InT4 = 3
Const InT5 = 4
Const InT6 = 5
' Const InT7 =
' Const InT8 =

' ATC sensors inputs
Const InOpenSensor = 6 ' ATC unlocked (rotating)
Const InCloseSensor = 7 ' ATC locked - safe

' digital outputs for ATC control (CSMIO outputs)
Const OutRun = 0 ' unlock and rotate
Const OutLock = 1 ' stop rotation and lock at current position

'------------------------------------------------------------------------------
' program variables - don't modify
'------------------------------------------------------------------------------
Dim ToolNew, ToolOld, ToolSlot As Integer
Dim ToolRdy As Boolean
Dim ATC_CloseRetry
Dim InToolSens(TOOLCOUNT)

'------------------------------------------------------------------------------
  ' MACRO START
'------------------------------------------------------------------------------
If(GetOEMLed(800)) Then
Message("System jest w trybie ESTOP - WYMIANA PRZERWANA")
Sleep(150)
WaitForMove
End
End If

  SetUserLED(1001, 1) ' User LED - toolchange in progress
 
  InToolSens(0) = InT1
  InToolSens(1) = InT2
  InToolSens(2) = InT3
  InToolSens(3) = InT4
  InToolSens(4) = InT5
  InToolSens(5) = InT6
'TPS  InToolSens(6) = InT7
'TPS  InToolSens(7) = InT8

' Get actual tool # and new tool #
ToolOld = GetCurrentTool()
ToolNew = GetSelectedTool()

' little trick for double slots ATC
If(ToolNew >= 10) Then
ToolSlot = ToolNew - 10
Else
ToolSlot = ToolNew
End If

If(ToolOld >= 10) Then
ToolOld = ToolOld - 10
End If

' The same position - no need to move
If (ToolSlot = ToolOld) Then
SetCurrentTool( ToolNew )
Message("ATC is on position "& ToolSlot & " and new tool is " & ToolNew)
WaitForMove
SetUserLED(1001, 0)
End
End If

If (ToolSlot > TOOLCOUNT) Then
SetCurrentTool( ToolOld )
SetUserLED(1001, 0)
DoOEMButton(1003)
DoOEMButton(1002)
Sleep(150)
Message("There is no tool T" & ToolNew & " in ATC")
Sleep(150)
End
End If


' T0 is a fake tool, no need to change
If (ToolSlot = 0) Then
ToolNew = 0
SetCurrentTool( ToolNew )
Message("Za³adowano narzêdzie nr: " & ToolNew)
WaitForMove
SetUserLED(1001, 0)
End
End If


' unlock and rotate ATC
RunATC
Sleep( OpenSensDelay )
' check ATC open sensor
If (Not GetCsmioIn(InOpenSensor)) Then
LockATC
SetCurrentTool( 0 )
SetUserLED(1001, 0)
DoOEMButton(1021)
DoOEMButton(1002)
Sleep(150)
Message("ATC locked - toolchange failed.")
Sleep(150)
End
End If

' wait to ATC will be on the desired position
ToolRdy = false
While(Not ToolRdy)
If(GetCsmioIn((InToolSens(ToolSlot - 1)))) Then
ToolRdy = true
End If
Wend


' stop rotation and lock ATC
LockATC
ATC_CloseRetry = 0
' Check lock sensor, retry lock if needed
While(Not GetCsmioIn(InCloseSensor) And ATC_CloseRetry < 4)
LockATC
ATC_CloseRetry = ATC_CloseRetry + 1
Wend

' double check for succesful ATC lock
If (Not GetCsmioIn(InCloseSensor)) Then
SetCurrentTool( 0 )
SetUserLED(1001, 0)
DoOEMButton(1021)
DoOEMButton(1002)
Sleep(150)
Message("ATC lock alert. Check ATC.")
Sleep(150)
End
End If
 
SetCurrentTool( ToolNew )
Message("Succesful loaded tool T" & ToolNew)
Sleep(150)
WaitForMove
SetUserLED(1001, 0)
End
' -----------------------------------------------------------------------------
Public Function GetCsmioIn (n As Integer) As Boolean
Dim reg As Integer

If(n < 16) Then
reg = 100
Else
reg = 101
n = n - 16
End If

If(GetInBit(reg, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
Exit Function
End Function
' -----------------------------------------------------------------------------
Sub RunATC ()
Call SetCsmioOut(OutLock, false)
Sleep(150)
Call SetCsmioOut(OutRun, true)
Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Sub LockATC ()
Call SetCsmioOut(OutRun, false)
Sleep(150)
Call SetCsmioOut(OutLock, true)
Sleep(TimeLock)
Call SetCsmioOut(OutLock, false)
Sleep(150)
End Sub
' -----------------------------------------------------------------------------
Public Sub SetCsmioOut (ByVal n As Integer, ByVal state As Boolean)
If(state) Then
SetOutBit(100, n)
Else
ResetOutBit(100, n)
End If
End Sub
' -----------------------------------------------------------------------------
Sub WaitForMove ()
While IsMoving()
Sleep(15)
Wend
End Sub                                                 


Title: Re: Lathe ATC turret VB
Post by: NinoR on June 30, 2023, 02:48:05 AM
Thank you for your help. I found a problem   ??? I was setting machine in mill profile with turn screenset instead in turn profile. I moved settings to turn and its started working.
#beginersproblems

Greetings Nino