Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started 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
-
how do you initiate toolchange
in lathe mode it is
M6 T0101 for example
-
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
-
add
msgbox ("M6 Start executed")
at the begin of the macro to see that the macro is called
-
do you have enabled in
Config -> General Config -> Tool Change -> Auto Tool Change
-
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
-
do you have enabled in
Config -> General Config -> Tool Change -> Auto Tool Change
yes it is on :)
-
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
-
you can copy all your code to
Operator -> VB Scripter Window
and use the >|| button to step through to see what is going on
-
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
-
ok, not good,
give me pls some more Information about your complete System.
Thomas
-
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.
-
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
-
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 :(
-
try this code, now you should see in Status line witch TC place is detected by the Inputs
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
-
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.
-
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.
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
-
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
-
ok i will go out and Try it now
-
ActivateSignal(Output8)
While NOT IsActive(Input22)
Sleep(50)
Wend
DeActivateSignal(Output8)
would be the code for a simple test
-
I have tried the test. And it won't read the input. :(
but i get the input on the ip-a controller)
-
are i missing a mach or a ipa config ?
-
hmm
-
oh sh**t, missed that we are on a CSMIO Controller, sorry.
here the modified code:
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
-
here the document, how I/O's are handled:
https://en.cs-lab.eu/wp-content/uploads/2016/06/csmio-ip-a-artykul.pdf
-
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 )
-
here a new Version.
-all debug code deleted (faster Operation)
-Input 23 now used to stop reverse run
-after finish re check and retry
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
-
sorry
While GetCsmioIn(91,7) = True
Needs to be
While GetCsmioIn(91,7) = False
-
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 :)
-
ok sorry for the delay.
here the code with a 3 second timeout for input23
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
'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:
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
-
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:)
-
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.
-
ok mistake found.
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
-
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. :)
-
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
-
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 ?
-
this would bo the complete code, with refernce check and X/Z move.
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.
-
ok thanks. i will try it out when I receive the drives. ;)