1
Mach4 General Discussion / Need help with M6 Macro, translating from Mach3 to Mach4
« on: September 20, 2018, 03:51:03 PM »
Ok, so my brain is not working like it used to. I haven't even heard of Lua before today. I have a macro from Mach3 that does exactly what I need it to, however since I'm runing a pokeys57u on my lathe, and want all of the features... I'm going to need to resort to Mach4.
Can someone please help me out?
Here is a Macro I found for Mach3 to control the PCturn Turret, using the factory internal encoder setup. I have everything wired up and mechanically ready to test.
The thread is short, but http://www.machsupport.com/forum/index.php/topic,16685.0.html is my source.
****************************************************************************************************************************************************
'M6Start.M1s
'Input1 is an optical sensor used to count tool positions
'Input2 is from a microswitch used to determine tool 0 position
'OUTPUT6 drives the tool changer forward, de activating it allows the tool changer to rotate back against the ratchet pawl at low power and is the default
'Un comment the Open statement, various write# statements and the close# function to write a logfile for diagnostic purposes
'Close #1
'Open "M6start_log.txt" For Output As #1 'open a file to write logs to
NewTool = GetSelectedTool()
'NewTool = 2
'Write #1, "NewTool ", NewTool
OldTool = GetCurrentTool()
'Write #1, "OldTool ", OldTool
MaxToolNum = 6 'Max number of tools for the changer
CurrPos = OldTool
While (NewTool > MaxToolNum)
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
'there is nothing to do so we just exit
If (NewTool = OldTool) And (NewTool > 0) Then
'Write #1, "New tool number is the same as old tool number. Nothing to do "
Exit Sub
End If
'If OldTool is 0 that means we dont know where the tool changer is currently positioned and need to reference to the microswitch for tool 1 position.
'need to establish tool 0 position from microswitch
If (OldTool = 0) Then
'Write #1, "Old tool number is zero, looking for reference position"
ActivateSignal(OUTPUT5)' Set toolchanger for full speed move
'Write #1, "Activated Output 5 to enable toolchanger motor"
ActivateSignal(OUTPUT6)' rotate tool changer forward
'Write #1, "Activated Output 6 to set forward direction"
While Not IsActive(INPUT2)
Wend
' Input 2 must Now be active so the microswitch has been triggered at position 1
CurrPos = 1
'Write #1, "Reference position found "
' Decide whether to just stop for the normal toolchange process
If ( CurrPos <> NewTool) Then
DeActivateSignal(OUTPUT6)
DeActivateSignal(OUTPUT5)
Else
' Or if we actuallly wanted tool 1 then stop and lock
DeActivateSignal(OUTPUT5) 'stop rotating forward, rotate backward now
'Write #1, "DeActivateSignal Output 5 toolchanger reverse "
SetCurrentTool(NewTool) 'sets up the current tool variable as the start point for a future tool change
'Write #1, "Setting CurrentTool to NewTool value ", NewTool
Sleep(2500) 'Allow a time interval for the toolchanger to settle back against the ratchet pawl
'Write #1, "Waited 2.5 seconds for toolchanger to lock "
DeActivateSignal(OUTPUT6) 'Disable toolchanger motor
'Write #1, "DeActivateSignal Output 6 toolchanger stop "
End If
End If
If (CurrPos <> NewTool) Then 'write the start condition to a variable
If IsActive(INPUT1) Then
PreviousSensorState = "Active"
Else
PreviousSensorState = "Inactive"
End If
'Write #1, "PreviousSensorState =", PreviousSensorState
ActivateSignal(OUTPUT5)' Set toolchanger for full speed move
'Write #1, "ActivateSignal Output 6 toolchanger go"
ActivateSignal(OUTPUT6) 'start rotating forward
'Write #1, "ActivateSignal Output 5 toolchanger forward "
While CurrPos <> NewTool
'Some logic to ensure that we only count on the leading edge of a slot in the toolchanger optical disk
If IsActive(INPUT1) Then
SensorState = "Active"
Else
SensorState = "Inactive"
End If
'Write #1, "SensorState =", SensorState
If SensorState <> PreviousSensorState Then
If SensorState = "Inactive" Then
CurrPos = CurrPos +1
If CurrPos = 7 Then
CurrPos = 1
'Write #1, "CurrPos reached 7, reset to 1 "
End If
End If
'Write #1, "CurrPos =", CurrPos
PreviousSensorState = SensorState
End If
If CurrPos = NewTool Then
DeActivateSignal(OUTPUT5) 'stop rotating forward, rotate backward now
'Write #1, "DeActivateSignal Output 5 toolchanger reverse "
SetCurrentTool(NewTool) 'sets up the current tool variable as the start point for a future tool change
'Write #1, "Setting CurrentTool to NewTool value ", NewTool
Sleep(1500) 'Allow a time interval for the toolchanger to settle back against the ratchet pawl
'Write #1, "Waited 1.5 seconds for toolchanger to lock "
DeActivateSignal(OUTPUT6) 'Disable toolchanger motor
'Write #1, "DeActivateSignal Output 6 toolchanger stop "
End If
sleep(200) ' just slows the iterations down a bit
'Write #1, "Waited 0.2 second "
Wend
'Write #1, "should be job done "
'Close #1
End If
If you don't know what is going on above, but know Lua somehow... I have a 6 position turret. There are 2 "encoders" in it. One pulses each tool, and the other pulses on tool 1. A single output turned on advances the tool. When the output is turned off, it will automatically lock into place.
Any help would be greatly appreciated! Thanks!
-Bob
Can someone please help me out?
Here is a Macro I found for Mach3 to control the PCturn Turret, using the factory internal encoder setup. I have everything wired up and mechanically ready to test.
The thread is short, but http://www.machsupport.com/forum/index.php/topic,16685.0.html is my source.
****************************************************************************************************************************************************
'M6Start.M1s
'Input1 is an optical sensor used to count tool positions
'Input2 is from a microswitch used to determine tool 0 position
'OUTPUT6 drives the tool changer forward, de activating it allows the tool changer to rotate back against the ratchet pawl at low power and is the default
'Un comment the Open statement, various write# statements and the close# function to write a logfile for diagnostic purposes
'Close #1
'Open "M6start_log.txt" For Output As #1 'open a file to write logs to
NewTool = GetSelectedTool()
'NewTool = 2
'Write #1, "NewTool ", NewTool
OldTool = GetCurrentTool()
'Write #1, "OldTool ", OldTool
MaxToolNum = 6 'Max number of tools for the changer
CurrPos = OldTool
While (NewTool > MaxToolNum)
NewTool = Question ("Enter New Tool Number up to " & MaxToolNum)
Wend
'there is nothing to do so we just exit
If (NewTool = OldTool) And (NewTool > 0) Then
'Write #1, "New tool number is the same as old tool number. Nothing to do "
Exit Sub
End If
'If OldTool is 0 that means we dont know where the tool changer is currently positioned and need to reference to the microswitch for tool 1 position.
'need to establish tool 0 position from microswitch
If (OldTool = 0) Then
'Write #1, "Old tool number is zero, looking for reference position"
ActivateSignal(OUTPUT5)' Set toolchanger for full speed move
'Write #1, "Activated Output 5 to enable toolchanger motor"
ActivateSignal(OUTPUT6)' rotate tool changer forward
'Write #1, "Activated Output 6 to set forward direction"
While Not IsActive(INPUT2)
Wend
' Input 2 must Now be active so the microswitch has been triggered at position 1
CurrPos = 1
'Write #1, "Reference position found "
' Decide whether to just stop for the normal toolchange process
If ( CurrPos <> NewTool) Then
DeActivateSignal(OUTPUT6)
DeActivateSignal(OUTPUT5)
Else
' Or if we actuallly wanted tool 1 then stop and lock
DeActivateSignal(OUTPUT5) 'stop rotating forward, rotate backward now
'Write #1, "DeActivateSignal Output 5 toolchanger reverse "
SetCurrentTool(NewTool) 'sets up the current tool variable as the start point for a future tool change
'Write #1, "Setting CurrentTool to NewTool value ", NewTool
Sleep(2500) 'Allow a time interval for the toolchanger to settle back against the ratchet pawl
'Write #1, "Waited 2.5 seconds for toolchanger to lock "
DeActivateSignal(OUTPUT6) 'Disable toolchanger motor
'Write #1, "DeActivateSignal Output 6 toolchanger stop "
End If
End If
If (CurrPos <> NewTool) Then 'write the start condition to a variable
If IsActive(INPUT1) Then
PreviousSensorState = "Active"
Else
PreviousSensorState = "Inactive"
End If
'Write #1, "PreviousSensorState =", PreviousSensorState
ActivateSignal(OUTPUT5)' Set toolchanger for full speed move
'Write #1, "ActivateSignal Output 6 toolchanger go"
ActivateSignal(OUTPUT6) 'start rotating forward
'Write #1, "ActivateSignal Output 5 toolchanger forward "
While CurrPos <> NewTool
'Some logic to ensure that we only count on the leading edge of a slot in the toolchanger optical disk
If IsActive(INPUT1) Then
SensorState = "Active"
Else
SensorState = "Inactive"
End If
'Write #1, "SensorState =", SensorState
If SensorState <> PreviousSensorState Then
If SensorState = "Inactive" Then
CurrPos = CurrPos +1
If CurrPos = 7 Then
CurrPos = 1
'Write #1, "CurrPos reached 7, reset to 1 "
End If
End If
'Write #1, "CurrPos =", CurrPos
PreviousSensorState = SensorState
End If
If CurrPos = NewTool Then
DeActivateSignal(OUTPUT5) 'stop rotating forward, rotate backward now
'Write #1, "DeActivateSignal Output 5 toolchanger reverse "
SetCurrentTool(NewTool) 'sets up the current tool variable as the start point for a future tool change
'Write #1, "Setting CurrentTool to NewTool value ", NewTool
Sleep(1500) 'Allow a time interval for the toolchanger to settle back against the ratchet pawl
'Write #1, "Waited 1.5 seconds for toolchanger to lock "
DeActivateSignal(OUTPUT6) 'Disable toolchanger motor
'Write #1, "DeActivateSignal Output 6 toolchanger stop "
End If
sleep(200) ' just slows the iterations down a bit
'Write #1, "Waited 0.2 second "
Wend
'Write #1, "should be job done "
'Close #1
End If
If you don't know what is going on above, but know Lua somehow... I have a 6 position turret. There are 2 "encoders" in it. One pulses each tool, and the other pulses on tool 1. A single output turned on advances the tool. When the output is turned off, it will automatically lock into place.
Any help would be greatly appreciated! Thanks!
-Bob