OK,
I have it working.
For the Emco5cnc ATC this macro now works.
First of all one has to Home the ATC in Mach3 Manual screen >> Home All.
Then , in Mach3 Auto, load the G-code to be executed.
The macro looks if the Homing has been done and sets a two variables.
One that homing has been done and one to make sure that Mach3 knows that the ATC homing position
is the Tool #1 position.
The hint to use SetVar helped me a lot.
Jos
' Based on Boxford 160TCL Toolchanger Macro.
' Modified for the EMCO5cnc Automatic Tool Changer.
' ATC has a steppermotor and an optical slot @ INPUT1
' Works by turning CW to just past the tool position
' and then CCW into a stop.
' Axis setup as rotary e.g. move 360 = 1 full turn.
If IsLoading() Then
' Do Nothing, program loading
Else
' Dim Variables
Dim Num_Tools As Integer
Dim CW_Steps_Per_Tool As Integer
Dim CCW_Steps As Integer
Dim HoldingDRO As Integer
Dim Requested_Tool As Integer
Dim Current_Tool As Integer
Dim CW_Feed As Integer
Dim CCW_Feed As Integer
Dim moves As Integer
Dim total_move As Integer
' First check if Homing has been done
If GetVar(300) = 1 Then ' Has homing been done?
GoTo Main ' Yes, is Homed, jump to Main
Else
End If
' If Not, check if ATC is homed.
If IsActive(INPUT1) Then ' Look for ATC Home pulse
SensorState = "Active"
Else
Message " Input 1 is NOT Active, Home first."
Code "M30" ' End G-code execution
End
End If
If SensorState = "Active" Then
SetVar(300,1) 'Is Homed
Setvar(301,1) 'Set Current Tool as #1
End If
Main
' set up some vars
Num_Tools = 6
CW_Move_Per_Tool = 62 '360/Num_Tools , not used
CCW_Move = 15
Requested_Tool = GetSelectedTool()
Current_Tool = GetVar(301)
CW_Feed = 700
CCW_Feed = 700
Current_Feed = GetOEMDRO(818)
' start tool change
Message ("Requested Tool No=" & Requested_Tool)
If Requested_Tool > Num_Tools Then
Message "Requested Tool No. too high, program stopped."
Code "M30"
End
End If
If Requested_Tool < 1 Then
Message "Requested Tool No. too low, program stopped."
Code "M30"
End
End If
If Requested_Tool = Current_Tool Then
' do nothing
Else
' lets do some changing
If Requested_Tool > Current_Tool Then moves = Requested_Tool -Current_Tool
If Requested_Tool < Current_Tool Then moves = (Num_Tools - Current_Tool) +Requested_Tool
total_move = (moves * CW_Move_Per_Tool)+(CCW_Move/2)
Code "G91 G94" 'incremental & Feed per minute
Code "G0 A" & total_move '& "F" & CW_Feed
Code "G0 A" & "-" & CCW_Move '& "F" & CCW_Feed
While IsMoving()
Wend
SetCurrentTool Requested_Tool
SetVar(301,Requested_Tool) 'Store Current Tool
Code "G90" ' back to absolute movement
Code "F" & Current_Feed
End If
End If
' end of tool change