Hello,
I write this post in English because la_coterie seems to be the one who can help me
I need more informations as I will try to get things working this Week-end (and because I'm lazy at work

).
What I'd like is :
- I launch Mach3
- I turn my CNC on
- I Manually reference all axis X, Y, Z, in machine coordinates, using my homing switches (in fact, I will use my tool sensor as Z homing switch, as it's fixed on the mill table, and sense without any tool in the spindle)
- I put the part to mill in the vice, then set X and Y offset zero if changed(that doesn't change machine coordinates zero, that's it ?), I doesn't core of Z axis
- I put the first tool in the spindle, that's where it become more complex :
a - the spinde goes to a preset position where it is easy to change the tool (position in G53, I can go full up in Z because I got my Z "real" homing without tool)
b - A message appear on the screen, asking me to put the tool number X in the spindle then click ok
c - I manually change the tool in the spindle, then click ok
d - It goes X and Y above the tool sensor in G0 and G53
e - It goes Z down at, say, 50% of maximum Z velocity, until tool sensor clicks
f - It goes back something like 5mm
g - Then if sense the tool once again, at a slower speed (maybe 5 or 10% of max Z axis velocity)
h - This set the OFFSET (still not changing machine Z coordinates), at a predefined value (I got to measure Z distance between my tool sensor or the top of the vice, that's it ?), making Z OFFSET zero at the top of the vice AT THE END OF THE TOOL.
i - The Z axis goes up at max (Z = 0 in machine coordinates, in fact)
j - Maybe got to replace the spindle at the exact some location as before tool change (considering tool length change has been handled in offset Z zero change) ?
- Milling can start
- At each tool change, the same actions from a to j repeats
- When milling is finished, the spindle goes to a G53 preset location (for an easy access to the vace and milled part)
That's what I would be proud of
Now, what I need to do (correct me if I'm wrong) :
- Configure my tool sensor to be both probe input and Z homing input
- Set Z homing position (in homing/limits screen) so that when it touch the homing sensor, Z = 0 at full upper spindle position
- Calculate Z distance between the tool sensor and top of vice
- Produce the code in VB to get the actions I want for M30 and tool change macros
- Get the code in the right location
- Setup Mach to call the macro at tool change (including first tool)
I need you to :
- Help me write the VB scripts
- Tell me where to put the scripts so that they are called right
M30 Script a dit:
' Declare some import functions
Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
' Defines clear positions for stop
ClearPositionX = XXXX 'Set the clear position in X.
ClearPositionY = XXXX 'Set the clear position in Y.
ClearPositionZ = XXXX 'Set the clear position in Z.
' And here we go !
Code "M5 M9" 'Turn of spindle and coolant
Code "G90 G53 G0 Z" &ToolChangePositionZ 'Goes max up in Z
While IsMoving()
Sleep 100
Wend
Code "G90 G53 G0 X" &ToolChangePositionX " Y"&ToolChangePositionY 'Goes at clear location in X and Y
While IsMoving()
Sleep 100
Wend
' Finished !
I know I don't need to repeat G90 G53 G0, but last time, playing with these G-Code, I had problems with Mach getting back to G54 without telling me ...
Tool Change Script a dit:
' Declare some import functions
Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
' Set some variables (depending on mill configuration)
ToolChangePositionX = XXXX 'Set the tool change position in X (in G53).
ToolChangePositionY = XXXX 'Set the tool change position in Y (in G53).
ToolChangePositionZ = XXXX 'Set the tool change position in Z (in G53).
ToolSensorPositionX = XXXX 'Set the tool sensor position in X (in G53).
ToolSensorPositionY = XXXX 'Set the tool sensor position in Y (in G53).
ToolSensorMargin = XXXX 'Set the back in Z between fast and slow probing.
ZGapBetweenSensorAndTopVice = XXXX 'Set the Z distance between tool sensor and the top of the vice
'Get current values for data that will be changed
If GetOEMLED(48) = 0 'Get if current mode is absolute or incremental
CurrentIncrOrAbs = "G91"
Else
CurrentIncrOrAbs = "G90"
End If
CurrentOffset = ???? 'Get current offset
CurrentFeed = GetOemDRO(818) 'Get the current feedrate.
ProbeFeed = GetUserDRO(1152) 'You could put a probing feedrate here instead.
SlowProbeFeed =ProbeFeed / 10
PreviousX = GetOEMDRO(800) 'X position before tool change
PreviousY = GetOEMDRO(801) 'Y position before tool change
PreviousZ = GetOEMDRO(802) 'Z position before tool change
' And here we go !
If GetOemLed (825)=0 Then
Code "G90 G53 G0 Z" &ToolChangePositionZ
While IsMoving()
Sleep 100
Wend
Code "G90 G53 G0 X" &ToolChangePositionX " Y" &ToolChangePositionY
While IsMoving()
Sleep 100
Wend
Code "M1" 'M1 will stop program until cycle start is pressed, but i'd prefer a messagebox to be shown
'From now on, the new tool is in the spindle
Code "G90 G53 X" &ToolSensorPositionX " Y" &ToolSensorPositionY 'Goes above the sensor location
While IsMoving()
Sleep 100
Wend
Code "G31 Z-200 F" &ProbeFeed 'Probe with fast probing speed
While IsMoving()
Wend
Code "G91 G53 G0 Z" &ToolSensorMargin 'Goes a little bit above the sensor for the slow speed probing
While IsMoving()
Sleep 100
Wend
Code "G31 G53 G91 Z-200 F" &SlowProbeFeed 'Probe with slow probing speed
While IsMoving()
Wend
'Here we are exactly at tool tip on sensor Z
Code "G" &CurrentOffset 'Back to part offset
Call SetDro (2, ZGapBetweenSensorAndTopVice ) 'Set offset Z=0 at top of vice
Code "G4 P0.5" 'Pause for Dro to update.
Code "G53 G90 G0 Z" &ToolChangePositionZ 'Goes back to a safe Z
While IsMoving()
Sleep 100
Wend
Code "G" &CurrentOffset "G90 G0 X" &PreviousX " Y" &PreviousY 'Goes back to previous X and Y positions
While IsMoving()
Sleep 100
Wend
Code "Z" &PreviousZ 'Goes to back to previous Z position
While IsMoving()
Sleep 100
Wend
' And finally replace old modal modes
Code &CurrentIncrOrAbs ' Replace old value for G90 or G91
Code "F" &CurrentFeed
Else ' GetOemLed (825) != 0
Code "(Tool sensor is grounded, check connection and try again)" 'Is it possible to pop a MessageBox instead ?
Exit Sub
End If
' Finished !
In bold where I specifically need help.
Best regards.