Hello Guest it is March 28, 2024, 09:09:19 PM

Author Topic: M6 Tool Change Code Question  (Read 806 times)

0 Members and 1 Guest are viewing this topic.

Re: M6 Tool Change Code Question
« Reply #10 on: November 22, 2022, 08:36:42 PM »
Oh no well that stinks, I was kind of hopping I could do it the same way mach 3 worked but I guess not.

I tried putting them on at one point but electrical issues popped up. I have never had the the time to go back and take everything back apart and work on it. We couldn't afford to purchase one at my school so I built one years ago. It has been a huge hit and runs all of the time. I wish I would have been smart back in the day and grabbed two old windows xp machines to keep one as a backup. 

Thank you for all the help I truly appreciate it! I've been trying to get it to work for a few weeks now and finally gave up and jumped on here hopping someone could help me.
Re: M6 Tool Change Code Question
« Reply #11 on: November 22, 2022, 08:48:33 PM »
Hi,
don't give up, you can still do what you want but because you cannot home regularly then you'll have to program your way around it.
Thats exactly what mach3 did under the hood, and you can replicate it if you wish.

The alternative is to fit Home switches......$50 and your done.

Craig.
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: M6 Tool Change Code Question
« Reply #12 on: November 22, 2022, 09:15:21 PM »
Programing around my limitations would be great but I'm a novice with programming in Lua so I don't think I can do that.

As far as the machine goes I want to work on it over the summer when I have time for it to be apart. It has been running great for many years but it is time for some upgrades. I must say the students love it. When they write and run their first program it is a magical experience for most of them.  You can see their eyes light up as they watch it in pure amazement. If it's running any anyone comes in they can't help but stop and watch.

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: M6 Tool Change Code Question
« Reply #13 on: November 30, 2022, 02:06:18 AM »
Read the comments in the code below.  Mabey they will help you.  But as Craig said, home switches will help even more!  :) 

Code: [Select]
function m6()

local inst = mc.mcGetInstance('m6 macro script')
local selectedTool = mc.mcToolGetSelected(inst)
selectedTool = math.tointeger(selectedTool)
local currentTool = mc.mcToolGetCurrent(inst)
currentTool = math.tointeger(currentTool)
local SpindleDwell = 20000
local xstart = mc.mcAxisGetPos (inst, 0)
local ystart = mc.mcAxisGetPos (inst, 1)

if selectedTool == currentTool then
mc.mcCntlSetLastError(inst, "Current tool == Selected tool so there is nothing to do")
else
--Remove this line if you would not like the Z axis to move

mc.mcCntlGcodeExecuteWait(inst, "G90 G0 Z0.0");--Move the Z axis all the way up  -- Added the Wait variant of the API call.
mc.mcCntlGcodeExecuteWait(inst, "M5 G4 P"..SpindleDwell) --Turn off spindle          -- Added the Wait variant of the API call.
mc.mcCntlSetLastError(inst, "Change to tool " .. tostring(selectedTool) .. " and press start to continue") --Message at beginning of tool change
mc.mcCntlToolChangeManual(inst, true) --This will pause the tool change here and wait for a press of cycle start to continue 

-- mc.mcCntlToolChangeManual() uses mcFileHoldAquire() behind the scenes.  You should be able to jog you machine anywhere you want now.

-- The antidote is Cycle Start at this point.  So you could run any script from a button you choose.  This script may contain something like:

-- mc.mcCntlGcodeExecuteWait() with G31 to probe.
-- mc.mcCntlGetPoundVar() to read the probed positon G code #vars
-- mc.mcAxisSetPos() on the Z axis to set the current offset based on your tool probe. 
-- once the script is complete, press cycle start and the M6 script will continue from the next line of code

mc.mcCntlSetLastError(inst, "Current tool == " .. tostring(selectedTool) .. "   Previous Tool == " .. tostring(currentTool)) --Message that shows after Cycle Start
mc.mcToolSetCurrent(inst, selectedTool)
mc.mcCntlGcodeExecuteWait(inst, "G90 G0 Z0") -- Move Z to a safe location.  Change the position acordingly.
mc.mcCntlGcodeExecuteWait(inst,"G90 G0 X"..xstart.."Y"..ystart)  -- Move to start location.
mc.mcCntlGcodeExecuteWait(inst, "M3 G4 P"..SpindleDwell)  -- Turn spindle on and wait for dwell (You should really setup the spindle ramp times instead of using a dwell here.)
end
end

if (mc.mcInEditor() == 1) then
m6()
end

Steve
Re: M6 Tool Change Code Question
« Reply #14 on: December 03, 2022, 07:07:24 PM »
Thank you, I will give it a shot on Monday.