Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: Julie on February 16, 2015, 10:46:02 AM
-
Hi, all
I'm studying auto tool changer macro.
I have 3 tools, now it is setted the position of each tool in m6start.m1s like below code.
Select Case ToolNumber 'Here set the position of each tool.
Case Is = 1
Xpos = 12.00
YPos = 2.00
Case Is = 2
Xpos = 14.00
YPos = 2.00
Case Is = 3
Xpos = 16.00
YPos = 2.00
End Select
I would like to input coord's of tools location in Mach3 screen not in m6start.m1s.
So I created userDRO to input coord's at Screen4, and edited m6start.m1s like below codes.
But It ignores m6start.m1s and performs next code.
I don't know what's wrong.
Please anybody let me know what's wrong, or is there a better way to do this?
I'm sorry for bad english.
Thank you.
Sub Main() 'Define variables
OldTool = GetOEMDRO (1200)
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
tool = GetSelectedTool()
1xpos = GetOEMDRO (1205)
1ypos = GetOEMDRO (1206)
2xpos = GetOEMDRO (1207)
2ypos = GetOEMDRO (1208)
3xpos = GetOEMDRO (1209)
3ypos = GetOEMDRO (1210)
NewTool = tool
MaxToolNum = 3 'Maximum number of tools to use.
ToolDown = -50 'Height for the tool change.
ToolUp = 0.0 'Height the Z-axis for the tool change.
PosSec = 50.0 'Safe Position.
If NewTool = OldTool Then
Exit Sub
End If
While NewTool > MaxToolNum
NewTool = Question ("Place valid tool number (between 1 y 3)")
Wend
Code "G00 G53 Z" & ToolUp 'The z-axis is going to "machine zero"
While IsMoving()
Wend
Code "G53 y" & PosSec 'Going to safe position.
While IsMoving()
Wend
Code "G53 Z" & ToolDown 'Down to the height of tools
While IsMoving()
Wend
Call MovePos(OldTool) 'Going to the last position to relase the old tool.
While IsMoving()
Wend
ActivateSignal(Output1) 'Relase the tool.
Code "G4 P1.0"
Code "G53 Z" & ToolUp
While IsMoving()
Wend
Call MovePos(NewTool) 'Go to the new tool position.
While IsMoving()
Wend
Code "G53 Z" & ToolDown 'down the z-axis to hold the tool.
While IsMoving()
Wend
DeActivateSignal(Output1) 'hold the new tool.
Code "G4 P1.0"
Code "G53 y" & PosSec 'Returns to the safe position.
While IsMoving()
Wend
Code "G53 Z" & ToolUp 'Returns z-axis to "machine zero".
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )
End Sub
Sub MovePos(ByVal ToolNumber As Integer)
Select Case ToolNumber 'Here set the position of each tool.
Case Is = 1
Code "G00 G53 x" & 1xpos
Code "G00 G53 y" & 1ypos
Case Is = 2
Code "G00 G53 x" & 2xpos
Code "G00 G53 y" & 2ypos
Case Is = 3
Code "G00 G53 x" & 3xpos
Code "G00 G53 y" & 3ypos
End Select
End Sub
Main
-
Have you selected the TYPE of tool changes in Config ?? there are 3 options
None Ignores the M6start
Manual Uses M6start , M6end
Auto Uses only M6start
-
Thanks for reply.
I checked "autotool changer" in Config.
And it works well when the position of each tool is writted in m6start.m1s.
Different point is using of userDRO and variables for the position of each tool.
-
This should at least get you moving with a tool change. I fixed the errors that prevented the M6Start from running.
Sub Main() 'Define variables
OldTool = GetOEMDRO (1200)
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
tool = GetSelectedTool()
xpos1 = GetOEMDRO (1205)
ypos1 = GetOEMDRO (1206)
xpos2 = GetOEMDRO (1207)
ypos2 = GetOEMDRO (1208)
xpos3 = GetOEMDRO (1209)
ypos3 = GetOEMDRO (1210)
NewTool = tool
MaxToolNum = 3 'Maximum number of tools to use.
ToolDown = -50 'Height for the tool change.
ToolUp = 0.0 'Height the Z-axis for the tool change.
PosSec = 50.0 'Safe Position.
If NewTool <> OldTool Then
Exit Sub
End If
If NewTool > MaxToolNum Then
NewTool = Question ("Place valid tool number (between 1 y 3)")
Else
End If
CODE "G90" 'Makes sure you are not in INC mode
Code "G00 G53 Z" & ToolUp 'The z-axis is going to "machine zero"
While IsMoving()
Wend
Code "G53 y" & PosSec 'Going to safe position.
While IsMoving()
Wend
Code "G53 Z" & ToolDown 'Down to the height of tools
While IsMoving()
Wend
Call MovePos(OldTool) 'Going to the last position to relase the old tool.
While IsMoving()
Wend
ActivateSignal(Output1) 'Relase the tool.
Code "G4 P1.0"
Code "G53 Z" & ToolUp
While IsMoving()
Wend
Call MovePos(NewTool) 'Go to the new tool position.
While IsMoving()
Wend
Code "G53 Z" & ToolDown 'down the z-axis to hold the tool.
While IsMoving()
Wend
DeActivateSignal(Output1) 'hold the new tool.
Code "G4 P1.0"
Code "G53 y" & PosSec 'Returns to the safe position.
While IsMoving()
Wend
Code "G53 Z" & ToolUp 'Returns z-axis to "machine zero".
Call SetUserDRO (1200,NewTool)
SetCurrentTool( NewTool )
End Sub
Sub MovePos(ByVal ToolNumber As Integer)
Select Case ToolNumber 'Here set the position of each tool.
Case Is = 1
Code "G00 G53 x" & xpos1 ' YOU may want to do combined moves of XY
Code "G00 G53 y" & ypos1 ' Code"G00 G53 X" &xpos1 &"Y"&ypos1
Case Is = 2
Code "G00 G53 x" & xpos2 'Same here
Code "G00 G53 y" & ypos2
Case Is = 3
Code "G00 G53 x" & xpos3 'Same Here
Code "G00 G53 y" & ypos3
End Select
End Sub
Main
-
After I modified code as your reply, it didn't prevent m6start.m1s.
But I got 2 error message.
And X axis and y axis is not moving, only z axis is moving.
Error1) Coding like Below.
Code "G00 G53 x" & xpos1
Code "G00 G53 y" & ypos1
Error Message : "No characters found in reading real value, Block = G00 G53 y"
Error2) Coding like below.
Code "G00 G53 X" & xpos1 & " Y" & ypos1
Error Message : "Unknown word where unary operation could be, Block = G00 G53 XY"
Variables are defined as below
xpos1 = GetOEMDRO (1205)
ypos1 = GetOEMDRO (1206)
xpos2 = GetOEMDRO (1207)
ypos2 = GetOEMDRO (1208)
xpos3 = GetOEMDRO (1209)
ypos3 = GetOEMDRO (1210)
-
both errors mean that there are NO real values in the Xpos1 and ypos1 variables either the script is wrong OR the DROS are not correct OR you did not enter info into the dro.Remember you HAVE to hit enter after inputting values into a DRO. OR you do not have save dros on close selected in Gen Config and the value when restartng Mach3 are NIL (empty).
ALSO you need to change this line of code.
If NewTool <> OldTool Then
To This
If NewTool = OldTool Then
I changed it for testing and forgot to change it back.
(;-) TP
-
Finally, I did it.
The cause of error was the position of definition varibles.
I defined varibles below "Sub MovePos" function. Now it works very well.
I was able to succeed because of your help.
Thank you so much. b^.^
-
Good Job. There is great joy when a thought actually becomes a working function/
(;-) TP
-
What type of changer is this? I am guessing the tool simply drops down into the holder and new tool raises directly up and out?.. what would you add to make the tool slide in and out of a slot type tool rack?,