Machsupport Forum

Mach Discussion => VB and the development of wizards => Topic started by: kennethchristensen on April 16, 2019, 07:43:16 AM

Title: macro for 4 slot tool change hep
Post by: kennethchristensen on April 16, 2019, 07:43:16 AM
macro for 4 slot tool change

Hi I'm new to macros. and I'm trying to get my atc to work for my lathe. and i need some help
my atc macro. must control the following.
(output 8.) unlock rotates ccw
(output 9) rotate cw for lock
(input 23) lock contact
(input 22) tool 1
(input 21) tool 2
(input 20) tool 3
(input 19) tool 4
i have found a macro that i believe will work but nothing happens when i save it in m6start what am i missing? i have put atc on.
i am also missing the (lock input 23)

OldTool = GetOEMDRO (1200)
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

Call SetUserDRO (1200, NewTool)
SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If Not IsActive(Input22) Then
      NewTool = 1
      End If
   If Not IsActive(Input21) Then
      NewTool = 2
      End If
   If Not IsActive(Input20) Then
      NewTool = 3
      End If
   If Not IsActive(Input19) Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
      While IsMoving()
      Wend
   ActivateSignal(Output9) 
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output9)
      While IsMoving()
      Wend
End Sub 
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 16, 2019, 09:07:33 AM
how do you initiate toolchange

in lathe mode it is

M6 T0101 for example
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 16, 2019, 09:18:40 AM
how do you initiate toolchange

in lathe mode it is

M6 T0101 for example

i just change the tool nr. from 1-4.
or write m6 t0101 but nothing happens
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 16, 2019, 09:22:45 AM
add

msgbox ("M6 Start executed")

at the begin of the macro to see that the macro is called
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 16, 2019, 09:25:56 AM
do you have enabled in

Config -> General Config -> Tool Change -> Auto Tool Change
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 16, 2019, 09:37:25 AM
add

msgbox ("M6 Start executed")

at the begin of the macro to see that the macro is called

like this ?

msgbox ("M6 Start executed")
OldTool = GetOEMDRO (1200)
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

Call SetUserDRO (1200, NewTool)
SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If Not IsActive(Input22) Then
      NewTool = 1
      End If
   If Not IsActive(Input21) Then
      NewTool = 2
      End If
   If Not IsActive(Input20) Then
      NewTool = 3
      End If
   If Not IsActive(Input19) Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
      While IsMoving()
      Wend
   ActivateSignal(Output9) 
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output9)
      While IsMoving()
      Wend
End Sub 

Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 16, 2019, 09:40:35 AM
do you have enabled in

Config -> General Config -> Tool Change -> Auto Tool Change

yes it is on :)

Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 16, 2019, 09:50:34 AM
add

msgbox ("M6 Start executed")

at the begin of the macro to see that the macro is called

like this ?

msgbox ("M6 Start executed")
OldTool = GetOEMDRO (1200)
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

Call SetUserDRO (1200, NewTool)
SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If Not IsActive(Input22) Then
      NewTool = 1
      End If
   If Not IsActive(Input21) Then
      NewTool = 2
      End If
   If Not IsActive(Input20) Then
      NewTool = 3
      End If
   If Not IsActive(Input19) Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
      While IsMoving()
      Wend
   ActivateSignal(Output9) 
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output9)
      While IsMoving()
      Wend
End Sub 




yes
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 16, 2019, 09:53:43 AM
you can copy all your code to

Operator -> VB Scripter Window

and use the >|| button to step through to see what is going on
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 16, 2019, 11:04:07 AM
you can copy all your code to

Operator -> VB Scripter Window

and use the >|| button to step through to see what is going on


my mach 3 just crash when i do that 
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 16, 2019, 01:46:51 PM
ok, not good,
give me pls some more Information about your complete System.

Thomas
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 16, 2019, 05:21:24 PM
ok, not good,
give me pls some more Information about your complete System.

Thomas


hello
it is a Avon 5500 cnc Rebild
with a cismo ip- controller running mach 3 lates version.


i just downloadet march to a different pc. copied the macro in to vb skript same result, vb crashes.   
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 17, 2019, 01:36:07 AM
strange.

i have tested the code here on a
Version R3.043.066 and
Version R3.043.022

both with a CSMIO -IP S
and no Problem.

try to copy line by line to the VB scripter window
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 24, 2019, 08:46:51 AM

Hello again. I am sorry for the late reply.
I have caused the system to not break down.


when I run the code with T0101m6 I only get activated (output 9).

  I've tried to change

(If Not IsActive (Input22) Then
       NewTool = 1)

to

(If IsActive (Input22) Then
       NewTool = 1)

It should be right in my case.

But nothing happens spindel just keep rotating :(
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 24, 2019, 12:18:14 PM
try this code, now you should see in Status line witch TC place is detected by the Inputs

Code: [Select]
OldTool = GetCurrentTool()
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer

Message "OldTool: " & OldTool & " NewTool: " & Tool
Sleep(200)

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If IsActive(Input22) Then
      NewTool = 1
      End If
   If IsActive(Input21) Then
      NewTool = 2
      End If
   If IsActive(Input20) Then
      NewTool = 3
      End If
   If IsActive(Input19) Then
      NewTool = 4
      End If
  Message "NewTool= " & NewTool
  Sleep(200)
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
      While IsMoving()
      Wend
   ActivateSignal(Output9) 
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output9)
      While IsMoving()
      Wend
End Sub 
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 24, 2019, 03:40:20 PM
hi
i dont think the macro can detect the input.
i set input 22 to input 4 in my system witch is always aktive. an the macro cant detect that ether.
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 25, 2019, 02:40:16 AM
added some more debug info in this code. pls run this code and (assume you use Mach3 Standard
turn screenset) go to Diags. an use the History Button.
post the Textfile after running the macro.

Code: [Select]
OldTool = GetCurrentTool()
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer
debug = true

If debug = true Then
Message "OldTool: " & OldTool & " NewTool: " & Tool
Sleep(200)
End If

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
   If debug = true Then
Message "Output8 On"
Sleep(200)
   End If
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If IsActive(Input22) Then
      NewTool = 1
      End If
   If IsActive(Input21) Then
      NewTool = 2
      End If
   If IsActive(Input20) Then
      NewTool = 3
      End If
   If IsActive(Input19) Then
      NewTool = 4
      End If
  If debug = true Then
Message "NewTool= " & NewTool
Sleep(200)
  End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   If debug = true Then
Message "Output8 Off"
Sleep(200)
   End If
      While IsMoving()
      Wend
   ActivateSignal(Output9) 
   If debug = true Then
Message "Output9 On"
Sleep(200)
   End If
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output9)
   If debug = true Then
Message "Output9 Off"
Sleep(200)
   End If
      While IsMoving()
      Wend
End Sub 
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 02:45:56 AM
  I want to make sure my imput is working properly.
I want to try with a simple macro.


ActivateSignal(Output8) when (input 22) is on then DeActivateSignal(Output8)

is this correkt ?

ActivateSignal(Output8)
If IsActive(Input22) Then
DeActivateSignal(Output8)

End if

Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 02:48:36 AM
ok i will go out and Try it now
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 25, 2019, 02:54:40 AM
Code: [Select]
ActivateSignal(Output8)
While NOT IsActive(Input22)
Sleep(50)
Wend
DeActivateSignal(Output8)

would be the code for a simple test
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 03:48:55 AM
I have tried the test. And it won't read the input. :(
 but i get the input on the ip-a controller)
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 04:08:50 AM
are i missing a mach or a ipa config ?
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 04:14:23 AM
hmm
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 25, 2019, 04:35:58 AM
oh sh**t, missed that we are on a CSMIO Controller, sorry.
here the modified code:

Code: [Select]
OldTool = GetCurrentTool()
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer
debug = true

If debug = true Then
Message "OldTool: " & OldTool & " NewTool: " & Tool
Sleep(200)
End If

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

While Tool > MaxToolNum
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend

Call StartTool

While NewTool <> Tool
   Call CheckPins
   While IsMoving()
   Wend
Wend

Call StopTool

SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
   If debug = true Then
Message "Output8 On"
Sleep(200)
   End If
   'Code "G4 P4.0"    'Wait for the tool to rotate past the sensor
      While IsMoving()
      Wend
End Sub

Sub CheckPins
   If GetCsmioIn(91,6) = True Then
      NewTool = 1
      End If
   If GetCsmioIn(91,5) = True Then
      NewTool = 2
      End If
   If GetCsmioIn(91,4) = True Then
      NewTool = 3
      End If
   If GetCsmioIn(91,3) = True Then
      NewTool = 4
      End If
  If debug = true Then
Message "NewTool= " & NewTool
Sleep(200)
  End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   If debug = true Then
Message "Output8 Off"
Sleep(200)
   End If
      While IsMoving()
      Wend
   ActivateSignal(Output9) 
   If debug = true Then
Message "Output9 On"
Sleep(200)
   End If
      Code "G4 P1.0"    'Wait for the tool to rotate onto ratchet stop
      While IsMoving()
      Wend
   DeActivateSignal(Output9)
   If debug = true Then
Message "Output9 Off"
Sleep(200)
   End If
      While IsMoving()
      Wend
End Sub 

'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 25, 2019, 04:37:23 AM
here the document, how I/O's are handled:

https://en.cs-lab.eu/wp-content/uploads/2016/06/csmio-ip-a-artykul.pdf
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 05:49:11 AM
that is a different ball game  ;)
now it works almost as intended.


it is possible to get output 8 to stop faster.
Half of the time it jumps over the tool and locks on the next tool. no error ditekted 
 
perhaps a security system to lock.
 i have a micro swich on input23 which indicates the spindel is locked.

in the locked state, the tool number is on(input19-22) and Safety lock (input23) is on.
if not rotate again (outout 8 )
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 25, 2019, 06:08:47 AM
here a new Version.
-all debug code deleted (faster Operation)
-Input 23 now used to stop reverse run
-after finish re check and retry

Code: [Select]
OldTool = GetCurrentTool()
Tool = GetSelectedTool()
MaxToolNum = 4      'Max number of tools for the changer

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

If Tool > MaxToolNum Then
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
End If

doagain:

Call StartTool

While NewTool <> Tool
   Call CheckPins
Wend

Call StopTool

're check
Call CheckPins
If NewTool <> Tool Then
goto doagain
End If

SetCurrentTool(NewTool)

'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
End Sub

Sub CheckPins
   If GetCsmioIn(91,6) = True Then
      NewTool = 1
      End If
   If GetCsmioIn(91,5) = True Then
      NewTool = 2
      End If
   If GetCsmioIn(91,4) = True Then
      NewTool = 3
      End If
   If GetCsmioIn(91,3) = True Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   ActivateSignal(Output9)
   'wait for input 23   
   While GetCsmioIn(91,7) = True
Sleep(20)
   Wend
   DeActivateSignal(Output9)
End Sub 

'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 25, 2019, 06:13:30 AM
sorry

While GetCsmioIn(91,7) = True

Needs to be

While GetCsmioIn(91,7) = False
Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 25, 2019, 07:20:20 AM
it works

But the security lock needs an extra thing. :)

if I disassemble (input23) the spindle continues to drive up against the lock. it is OK
but it must stop after 3 sec. and activate a fault atc not locked (estop) otherwise i think the engine will burn :)
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 26, 2019, 02:24:38 AM
ok sorry for the delay.
here the code with a 3 second timeout for input23

Code: [Select]
Sub Main
'//Declarations
Dim StartTime, ActTime As Single
MaxToolNum = 4      'Max number of tools for the changer

OldTool = GetCurrentTool()
Tool = GetSelectedTool()

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

If Tool > MaxToolNum Then
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
End If

doagain:

Call StartTool

While NewTool <> Tool
Call CheckPins
Wend

Call StopTool

're check
Call CheckPins
If NewTool <> Tool Then
goto doagain
End If

SetCurrentTool(NewTool)
End Sub


'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
End Sub

Sub CheckPins
   If GetCsmioIn(91,6) = True Then
      NewTool = 1
      End If
   If GetCsmioIn(91,5) = True Then
      NewTool = 2
      End If
   If GetCsmioIn(91,4) = True Then
      NewTool = 3
      End If
   If GetCsmioIn(91,3) = True Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   ActivateSignal(Output9)
   'wait for input 23   or timeout
StartTime = Timer

   
   While GetCsmioIn(91,7) = False
Sleep(20)
ActTime = Timer
If ActTime > StartTime + 3 Then
MsgBox "Timeout Input23!!"
DoButton(3)
Sleep(300)
Exit Sub
End If
   Wend
   DeActivateSignal(Output9)
End Sub 

'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function

IMHO i think for a save TC on a lathe some more things are necessary.

1. homing Limit Switches
   machine should have homing Limits to have the possibillity to drive TC to a defined Position
   (in machine coords) to be save for rotate the TC

here some code witch check' that X and Y axis are referenced
Code: [Select]
'X-Axis not in reference
If GetOEMLED(807) Then
DoButton(3)
Sleep(500)
Message ("X-Axis not referenced -> Abort !!")
Exit Sub
End If

'Z-Axis not in reference
If GetOEMLED(809) Then
DoButton(3)
Sleep(500)
Message ("Z-Axis not referenced -> Abort !!")
Exit Sub
End If

2. drive Z and X axis to a defined Position (in machine coords)

here some code:
Code: [Select]
Message "ATC X-Axis to TC position"
Code "G90 G53 G0 X2"
While IsMoving()
Sleep(15)
Wend

Message "ATC Z-Axis to TC position"
Code "G90 G53 G0 Z2"
While IsMoving()
Sleep(15)
Wend







Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 26, 2019, 04:22:45 AM
hi there must be a small error in the last post on input 23

the most frustrating ting i have with my system, is every time i rum VB code, with an error. VB locks down  and i need to restart my hole system. 

it dossent lave much for troubleshooting.

I have deliberately failed to include the x-z axis movement as I cannot test it yet.

my drives are on the way:)


Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 26, 2019, 04:31:55 AM
you mean the last code with the timeout included?
do you get any message in the statusline?

very hard to test here without the real Hardware.
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 26, 2019, 04:37:33 AM
ok mistake found.

Code: [Select]
Public NewTool As Integer

Sub Main
'//Declarations
Dim StartTime, ActTime As Single
MaxToolNum = 4      'Max number of tools for the changer

OldTool = GetCurrentTool()
Tool = GetSelectedTool()

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

If Tool > MaxToolNum Then
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
End If

doagain:

Call StartTool

While NewTool <> Tool
Call CheckPins
Wend

Call StopTool

're check
Call CheckPins
If NewTool <> Tool Then
GoTo doagain
End If

SetCurrentTool(NewTool)
End Sub


'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
End Sub

Sub CheckPins
   If GetCsmioIn(91,6) = True Then
      NewTool = 1
      End If
   If GetCsmioIn(91,5) = True Then
      NewTool = 2
      End If
   If GetCsmioIn(91,4) = True Then
      NewTool = 3
      End If
   If GetCsmioIn(91,3) = True Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   ActivateSignal(Output9)
   'wait for input 23 or timeout
StartTime = Timer

   
   While GetCsmioIn(91,7) = False
Sleep(20)
ActTime = Timer
If ActTime > StartTime + 3 Then
MsgBox "Timeout Input23!!"
DeActivateSignal(Output9)
DoButton(3)
Sleep(300)
Exit Sub
End If
   Wend
   DeActivateSignal(Output9)
End Sub 

'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function



Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 26, 2019, 04:57:54 AM
nice it registered the error. but the relay is still on until i hit the ok one the message box. it must somehow deactivate relay 9 again. without having to press ok first. :)
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 26, 2019, 05:06:16 AM
Code: [Select]
Public NewTool As Integer

Sub Main
'//Declarations
Dim StartTime, ActTime As Single
MaxToolNum = 4      'Max number of tools for the changer

OldTool = GetCurrentTool()
Tool = GetSelectedTool()

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

If Tool > MaxToolNum Then
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
End If

doagain:

Call StartTool

While NewTool <> Tool
Call CheckPins
Wend

Call StopTool

're check
Call CheckPins
If NewTool <> Tool Then
GoTo doagain
End If

SetCurrentTool(NewTool)
End Sub


'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
End Sub

Sub CheckPins
   If GetCsmioIn(91,6) = True Then
      NewTool = 1
      End If
   If GetCsmioIn(91,5) = True Then
      NewTool = 2
      End If
   If GetCsmioIn(91,4) = True Then
      NewTool = 3
      End If
   If GetCsmioIn(91,3) = True Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   ActivateSignal(Output9)
   'wait for input 23 or timeout
StartTime = Timer

   
   While GetCsmioIn(91,7) = False
Sleep(20)
ActTime = Timer
If ActTime > StartTime + 3 Then
DeActivateSignal(Output9)
MsgBox "Timeout Input23!!"
DoButton(3)
Sleep(300)
Exit Sub
End If
   Wend
   DeActivateSignal(Output9)
End Sub 

'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function




Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 26, 2019, 06:01:38 AM
it works like a charme  8)
the macros you posted on axis movement. i only need to juse one ?
and put it before pressent macro. is this correkt ?
Title: Re: macro for 4 slot tool change hep
Post by: TPS on April 26, 2019, 06:16:41 AM
this would bo the complete code, with refernce check and X/Z move.

Code: [Select]
Public NewTool As Integer

Sub Main
'//Declarations
Dim StartTime, ActTime As Single
MaxToolNum = 4      'Max number of tools for the changer

OldTool = GetCurrentTool()
Tool = GetSelectedTool()

If OldTool = Tool Then
Message ("Selected Tool already loaded")
Exit Sub
End If

If Tool > MaxToolNum Then
Tool = Question ("Enter New Tool Number up to " & MaxToolNum)
End If

'X-Axis not in reference
If GetOEMLED(807) Then
DoButton(3)
Sleep(500)
Message ("X-Axis not referenced -> Abort !!")
Exit Sub
End If

'Z-Axis not in reference
If GetOEMLED(809) Then
DoButton(3)
Sleep(500)
Message ("Z-Axis not referenced -> Abort !!")
Exit Sub
End If

Message "ATC X-Axis to TC position"
Code "G90 G53 G0 X2"
While IsMoving()
Sleep(15)
Wend

Message "ATC Z-Axis to TC position"
Code "G90 G53 G0 Z2"
While IsMoving()
Sleep(15)
Wend


doagain:

Call StartTool

While NewTool <> Tool
Call CheckPins
Wend

Call StopTool

're check
Call CheckPins
If NewTool <> Tool Then
GoTo doagain
End If

SetCurrentTool(NewTool)
End Sub


'//// Subroutines /////////

Sub StartTool
   ActivateSignal(Output8)
End Sub

Sub CheckPins
   If GetCsmioIn(91,6) = True Then
      NewTool = 1
      End If
   If GetCsmioIn(91,5) = True Then
      NewTool = 2
      End If
   If GetCsmioIn(91,4) = True Then
      NewTool = 3
      End If
   If GetCsmioIn(91,3) = True Then
      NewTool = 4
      End If
End Sub

Sub Stoptool
   DeActivateSignal(Output8)
   ActivateSignal(Output9)
   'wait for input 23 or timeout
StartTime = Timer

   
   While GetCsmioIn(91,7) = False
Sleep(20)
ActTime = Timer
If ActTime > StartTime + 3 Then
DeActivateSignal(Output9)
MsgBox "Timeout Input23!!"
DoButton(3)
Sleep(300)
Exit Sub
End If
   Wend
   DeActivateSignal(Output9)
End Sub 

'CSMIO Eingang lesen
Function GetCsmioIn (ByVal adr As Integer, ByVal n As Integer) As Boolean
If(GetInBit(adr, n)) Then
GetCsmioIn = true
Else
GetCsmioIn = false
End If
End Function


IMPORTANT:

it will move first X than Z axis!

the values of this two code lines:

   Code "G90 G53 G0 X2"

   Code "G90 G53 G0 Z2"

are in machine coord's and maybe Need to be adjusted.



Title: Re: macro for 4 slot tool change hep
Post by: kennethchristensen on April 29, 2019, 03:11:00 AM
ok thanks. i will try it out when I receive the drives.  ;)