Hello Guest it is March 28, 2024, 09:45:26 AM

Author Topic: Button for Auto Z-Zeroing Tool  (Read 2152 times)

0 Members and 1 Guest are viewing this topic.

Button for Auto Z-Zeroing Tool
« on: March 18, 2017, 08:52:03 PM »
I am relatively new to CNC and certainly a novice at coding...

I have watched Daz's M6 tool change videos several times and believe I have grasped the concepts.  Thank you for posting those  :)

I have a gantry mill with an ER collet and want to automate z-zeroing my tools.  I do not use M6.  I use separate gcodes at each tool change.  This is a hobby, so production efficiency is not needed.

With that, I want to create a Button on my main screen which will run an auto Z-zeroing sequence.  All of my tool lengths are 1.75 - 2 inches and I do not want to use the tool table.
I would rather provide enough space below my longest tool and the height sensor which will cover me.

My basic work process today:
Reference all axis Home, Load gcode into M4, manually set Work Coord X0 Y0, install tool and manually set Work Coord Z0, run gcode, when complete I change the tool for the next procedure, manually re-zero Work Coord Z for new tool, return to Work Coord X0 Y0, load new gcode and run, repeat as necessary...

This is what I came up with for the coding.  It is fairly basic.  If anyone has suggestions, sees any glaring mistakes, or if I missed a step, please let me know.  I appreciate it!

Code: [Select]
local inst = mc.mcGetInstance();

-- set height of Z axis at start of probe in Machine coordinates
local probestart = -2.5

-- move Z to safe location = Z0 in Machine Coords
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 Z0")

-- move to probe location in Machine coordinates
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 X3 Y0")

-- Move to probe start position, begin probe move, save Z Work coordinate value
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 Z"..probestart)
mc.mcCntrlGcodeExecuteWait(inst, "G91 G31 Z-1 F2")
local toolz = mc.mcAxisGetPos(inst,2)

-- Move to tool change location in Machine coordinates
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 Z0")
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 X12")
wx.wxMessageBox("Change Tool and Press OK to Continue")

-- Move back to probe location and probe again, set new Work Z coord to previous measurement = toolz
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 X3 Y0")
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 Z"..probestart)
mc.mcCntrlGcodeExecuteWait(inst, "G91 G31 Z-1 F2")
mc.mcAxisSetPos(inst,2,toolz)

-- Move to Machine Coord Z0 and return to Work Coord X0 Y0
mc.mcCntrlGcodeExecuteWait(inst, "G90 G53 G0 Z0")
mc.mcCntrlGcodeExecuteWait(inst, "G90 G54 G0 X0 Y0")

wx.wxMessageBox("Tool Change Complete")
« Last Edit: March 18, 2017, 08:58:16 PM by da40flyer »
Re: Button for Auto Z-Zeroing Tool
« Reply #1 on: March 20, 2017, 12:45:48 PM »
Found a typo...  should be "mc.mcCntlGcodeExecuteWait"
Re: Button for Auto Z-Zeroing Tool
« Reply #2 on: March 20, 2017, 02:04:09 PM »
Modified a few other issues.  1st test seemed to work properly...

Code: [Select]
local inst = mc.mcGetInstance();

-- set height of Z axis at start of probe in machine coordinates
local probestart = -2.5

-- move Z to safe location = Z0 in Machine Coords
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 Z0 F60")

-- move to probe location in machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 X1 Y0 F60")

-- Move to probe start position, begin probe move, save Z work coordinate value
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 Z"..probestart)
mc.mcCntlGcodeExecuteWait(inst, "G01 G91 G31 Z-1 F10")
local toolz = mc.mcAxisGetPos(inst,2)

-- Move to tool change location in machine coordinates
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 Z0 F60")
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 X4 F60")
wx.wxMessageBox("Change Tool and Press OK to Continue")

-- Move back to probe location and probe again, set new Work Z coord to previous measurement = toolz
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 X1 Y0 F60")
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 Z"..probestart)
mc.mcCntlGcodeExecuteWait(inst, "G01 G91 G31 Z-1 F10")
mc.mcAxisSetPos(inst,2,toolz)

-- Move to machine coord Z0 and return to Work coord X0 Y0
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G53 Z0 F60")
mc.mcCntlGcodeExecuteWait(inst, "G01 G90 G54 X0 Y0 F60")

wx.wxMessageBox("Tool Change Complete")