Hello Guest it is April 18, 2024, 05:38:12 PM

Author Topic: Altering M6 but am confused  (Read 9314 times)

0 Members and 1 Guest are viewing this topic.

Re: Altering M6 but am confused
« Reply #20 on: September 16, 2016, 01:22:00 PM »
FYI,
  I was running
Mach build 2872
PMDX
 .36.171

I am going to upgrade it all to the latest.
Re: Altering M6 but am confused
« Reply #21 on: September 16, 2016, 01:23:31 PM »
BOB,
  I noticed that one of the revisions fixed underruns for short jog moves.  That may be related.
Re: Altering M6 but am confused
« Reply #22 on: September 16, 2016, 04:26:03 PM »
Yep, most likely related.  Short moves of any kind were fixed in the release after the one you were using.  Hopefully you have (or will soon) upgrade to the latest 0.46.221 plug-in release.  I also highly recommend subscribing to the "Announcements" section on the PMDX support forums (http://www.pmdx.com/PMDXForums).  That way you will receive an email notice when there is a new plug-in release ready.

Bob
Re: Altering M6 but am confused
« Reply #23 on: September 16, 2016, 04:50:36 PM »
Fixed and working.  I did update to the newest everything, PMDX and Mach4.  BOB, I could no longer duplicate the Underrun so that is solved.  I tested it fully for all scenarios and it works great as it.  I do have one concern which may be an issue.  I hope Daz can give me input on this.  Basically when I probe, it zeros the Z axis and rewrites the fixture table, I believe that I need to add code to toggle the height offset on, otherwise it writes to the fixture table without it on, then when activated by running program it will no longer have the table as Z.  That was why I was originally writing to the tool table with my previous version.

Do I
1)  "toggle the height offset G49" in M6 or
2)  "write the offsets into the "Work shift",  G92, or somewhere else.  or
3)  go back and write the measured tool lengths into the tool table as I originally started doing


Code: [Select]
function M6() -- this code is based on a CNC Router table where zero is always the machine top.
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
    local changetoo = mc.mcToolGetDesc(inst,selectedtool)
    local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
   --your machine info custom to you
    local touchplate = 0 -- this is the height above or below table surface for non flush touchplates.
    local longesttool = 6 -- this is the longest bit that you own that you could possibly use
    local zclearance = -11.375 -- this is the measurment from your collet to machine top "Zero"
    local probeclearance = .25 -- this is safe distance above touchplate where you want probe to start
   -- end of your machine info
    local undefinedtoolprobe = (zclearance + longesttool +touchplate + probeclearance )
    local undefinedprobetravel = (zclearance + longesttool + touchplate)
    local probestart = (zclearance + toollen + probeclearance +touchplate)

    if selectedtool == currenttool then
        mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required") 
    else
        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") --move z axis all the way up
        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X0.464 Y-99.808") -- Move XY to above fixed touchplate location
        wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
        if toollen ~= 0 then   -- if toollen is defined in tool table do this
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
            ProbeState = mc.mcSignalGetState(hsig)
                if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
                    repeat
                        mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                        wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
                        ProbeState = mc.mcSignalGetState(hsig)
                    until(ProbeState == 1)
                    mc.mcAxisSetPos(inst, 2, (0 - touchplate))
                    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                    mc.mcCntlSetLastError(inst, "ToolChange Finished")
                    mc.mcToolSetCurrent(inst, selectedtool)
                else
            mc.mcAxisSetPos(inst, 2, (0 - touchplate))
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            mc.mcCntlSetLastError(inst, "ToolChange Finished")
            mc.mcToolSetCurrent(inst, selectedtool)
                end
        else
            wx.wxMessageBox("Undefined tool proceed with caution")
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z"..undefinedprobetravel.." F8")
            ProbeState = mc.mcSignalGetState(hsig)
                if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
                    repeat
                        mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                        wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z"..undefinedprobetravel.." F8")
                        ProbeState = mc.mcSignalGetState(hsig)
                    until(ProbeState == 1)
                    mc.mcAxisSetPos(inst, 2, (0 - touchplate))
                    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                    mc.mcCntlSetLastError(inst, "ToolChange Finished")
                    mc.mcToolSetCurrent(inst, selectedtool)
                else
                mc.mcAxisSetPos(inst, 2, (0 - touchplate))
                mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                mc.mcCntlSetLastError(inst, "ToolChange Finished")
                mc.mcToolSetCurrent(inst, selectedtool)
                end
        end
    end

end

if (mc.mcInEditor() == 1) then
    M6()
end
Re: Altering M6 but am confused
« Reply #24 on: September 16, 2016, 04:52:51 PM »
Thanks Bob I just subscribed.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Altering M6 but am confused
« Reply #25 on: September 16, 2016, 05:53:25 PM »
Here you go a modal dialog for ya to fit in to speed up lowering you z - change to whatever............



Code: [Select]
LowerZ = wx.wxDialog (wx.NULL, wx.wxID_ANY, "Touch Z", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxCAPTION + wx.wxCLOSE_BOX )
LowerZ:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )
mainSizer = wx.wxBoxSizer( wx.wxVERTICAL )
z_info = wx.wxStaticText( LowerZ, wx.wxID_ANY, " Undefined Tool Lower Z Then Click Continue or Cancel To Stop Probing!", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
z_info:Wrap( -1 )
mainSizer:Add( z_info, 0, wx.wxALIGN_CENTER_HORIZONTAL + wx.wxTOP + wx.wxBOTTOM + wx.wxRIGHT, 5 )
buttonSizer = wx.wxBoxSizer( wx.wxHORIZONTAL )
z_lower = wx.wxButton( LowerZ, wx.wxID_ANY, "Lower Z", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
buttonSizer:Add( z_lower, 0, wx.wxALL, 5 )
z_ok = wx.wxButton( LowerZ, wx.wxID_ANY, "Continue", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
buttonSizer:Add( z_ok, 0, wx.wxALL, 5 )
z_cancel = wx.wxButton( LowerZ, wx.wxID_ANY, "Cancel Probe", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
buttonSizer:Add( z_cancel, 0, wx.wxALL, 5 )
mainSizer:Add( buttonSizer, 1, wx.wxALIGN_CENTER_HORIZONTAL, 5 )
LowerZ:SetSizer( mainSizer )
LowerZ:Layout()
mainSizer:Fit( LowerZ )
LowerZ:Centre( wx.wxBOTH )

z_lower:Connect( wx.wxEVT_LEFT_DOWN, function(event)
--Lower Z Start
mc.mcSignalSetState (mc.mcSignalGetHandle (inst, mc.ISIG_JOGZN), 1)
event:Skip()
end )

z_lower:Connect( wx.wxEVT_LEFT_UP, function(event)
--Lower Z Stop
mc.mcSignalSetState (mc.mcSignalGetHandle (inst, mc.ISIG_JOGZN), 0)
event:Skip()
end )

z_ok:Connect( wx.wxEVT_LEFT_UP, function(event)
--Continue Probe
LowerZ:EndModal(0)
event:Skip()
end )

z_cancel:Connect( wx.wxEVT_LEFT_UP, function(event)
--Cancel Probe
LowerZ:EndModal(1)
event:Skip()
end )

ZProbe =  LowerZ:ShowModal()

if ZProbe == 0 then
wx.wxMessageBox("Continue with Probe")
else
wx.wxMessageBox("Quit Probing")
end

DazTheGas
New For 2022 - Instagram: dazthegas

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Altering M6 but am confused
« Reply #26 on: September 17, 2016, 04:12:29 AM »
Scrap the last post, had this problem before.... although in dev enviroment will work fine it wont work from a macro as the main thread (core) will not allow you to run a modal dialog!!

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Altering M6 but am confused
« Reply #27 on: September 18, 2016, 09:41:47 PM »
This is my working Code.   I tried to make it simple and self explanatory for those trying to adapt it to there machines. There are some lines that can be moved to the bottom to reduce the number of lines of code, as Daz did in Part 3 of his videos, maybe Rev 2 or I will leave it to Daz, I started to simplify it, but it left my else statements empty and I didn't know if it was acceptable to have and "Else", followed with an "End".  Also, I recommend reading all the comments next to the various lines of code as they may affect you based on your machine.

FYI,  I ran into an issue loading this code and any M6 code for that matter.  If I copy it into my directory, load Lua and Compile it.  It does not take effect, even if I restard Mach.  I had to delete the previous compiled version, the M6.mcc file, recompile it, and then it would take.  I ran a known good program and it skipped right over M6 without even calling it, couldn't manually run it in MDI either.  Ruined about 2 hours worth of work.  In anycase, I highly recommend that once you load it you use the MDI and verify that it did load.

My disclaimer, use at your own risk and test thoroughly.  Works for my machine, there are 4 scenarios in this code you need to test for.  1) regular bit change 2) bit too short which will prompt you to re-adjust bit, 3) 0 length in tool table, will probe and set length in tool table and 4) no bit in machine, with 0 length - this should prevent the z from traveling too far in the negative and or prevent the collet from hitting the table.  Also it should not matter if Offset is On or Off.

Please comment with any changes or operational problems that you experience and I will try to make future revisions for other users.  Though you get what you pay for so no promises. ::)

Code: [Select]
--(Revision 1.0) "Touch probe is at a fixed location" "tool table length is altered during probes"  Measurements I used are in inches
-- Rev 1.0 this code is based on a CNC Router table where zero is in a fixed location.  Mine is flush with the machine top.
--      In this version the tool table is altered every time by changing the bit length to whatever the probe measurement is.  You can leave your tool table lengths
--          blank and it will probe from a safe height the first time and enter the length for you, otherwise the length needs to be close to the length from the collet
--          to the end of the bit.
--  (if you do a tool change to an undefined tool or a tool with no length, it will automatically adjust and probe from a safe height)

--  ****** you must define "Local touchplate, longesttool, zclearance, and probeclearance" below based on your machine**********
--  *** my fixture offsets for G54, 55 etc is the distance from the collet to the worksurface, same as the zclearance and stays constant**

--  ****Note, My touchplate is flush with my top, because if this I have not tested the math for a touchplate.
--            A Neg number may be needed where expecting a positive make sure you test for your setup)



function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)
    local changetoo = mc.mcToolGetDesc(inst,selectedtool)
    local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
   --your machine info custom to you
    local touchplate = 0 -- this is the height above or below table surface for non flush touchplates.
    local longesttool = 6 -- this is the longest bit that you own that you could possibly use
    local zclearance = -11.375 -- this is the measurment from your collet to the fixed touchplate
    local probeclearance = .25 -- this is safe distance above touchplate where you want probe to start
   -- end of your machine info
    local undefinedtoolprobe = (zclearance + longesttool +touchplate + probeclearance )
    local undefinedprobetravel = (zclearance + longesttool + touchplate)
    local probestart = (zclearance + toollen + probeclearance +touchplate)

    if selectedtool == currenttool then
        mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")  
    else
        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0") --move z axis all the way up
        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 X0.464 Y-99.808") -- Move XY to above fixed touchplate location change to match your machine
        mc.mcCntlGcodeExecuteWait(inst, "G49") -- Cancels any current offsets
        if toollen ~= 0 then   -- if toollen is defined in tool table do this
            wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F5") -- change "F#" to vary probing speed
            ProbeState = mc.mcSignalGetState(hsig)
                if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
                    repeat
                        mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                        wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F5")-- change "F#" to vary probing speed
                        ProbeState = mc.mcSignalGetState(hsig)
                    until(ProbeState == 1)
                    local zoffset = mc.mcAxisGetPos (inst, 2) - touchplate
                    mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
                    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                    mc.mcCntlSetLastError(inst, "ToolChange Finished")
                    mc.mcToolSetCurrent(inst, selectedtool)
                else
            local zoffset = mc.mcAxisGetPos (inst, 2) - touchplate
            mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            mc.mcCntlSetLastError(inst, "ToolChange Finished")
            mc.mcToolSetCurrent(inst, selectedtool)
                end
        else
            wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
            wx.wxMessageBox("Tool Length is not Defined in Tool Table, Continue to Probe for Length")
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z"..undefinedprobetravel.." F5")-- change "F#" to vary probing speed
            ProbeState = mc.mcSignalGetState(hsig)
                if ProbeState == 0 then -- if probe is not sensed this prevents a false zero from being utilized.
                    repeat
                        mc.mcCntlSetLastError(inst, "ERROR: Touch Probe was not detected")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                        wx.wxMessageBox("ERROR: Touch Probe was not detected reset tool")
                        mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..undefinedtoolprobe.."\n G91 G31 Z"..undefinedprobetravel.." F5")-- change "F#" to vary probing speed
                        ProbeState = mc.mcSignalGetState(hsig)
                    until(ProbeState == 1)
                    local zoffset = mc.mcAxisGetPos(inst, 2) - touchplate
                    mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
                    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                    wx.wxMessageBox("Toolchange Finished, Ensure Tool Table Description matches Tool")
                else
                local zoffset = mc.mcAxisGetPos(inst, 2) - touchplate
                mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
                mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                wx.wxMessageBox("Toolchange Finished, Ensure Tool Table Description matches Tool")
                mc.mcToolSetCurrent(inst, selectedtool)                
                end
        end
    end
mc.mcCntlGcodeExecuteWait(inst, "G43") --Turns on Offsets
--wx.wxMessageBox("Toolchange completed successfully, press OK to Continue")  -- Enable this to insert a pause before resuming a running program
end

if (mc.mcInEditor() == 1) then
    M6()
end
Re: Altering M6 but am confused
« Reply #28 on: September 18, 2016, 09:56:34 PM »
BTW it may be obvious to most, or not, but this tool change function is based upon you putting the bit back into the collet at approximately the same location every time. Either by the manufacturers line, or a line that you mark on you bit as Daz shows in his video, IE sharpie.  If you are not consistant, within "half" of the tollerance you define in the program you run the risk of pushing the bit into your touch plate as it rapids down before the probe.  I have it set at .25, if I insert the bit .2 "in" too far into the router it will probe fine.  if for some reason I put it in .2 "out" the next time, then now it is now .4 from the previous set bit length and will rapid too far.  if you do the opposite the probe may not touch.

This is another disclaimer
Re: Altering M6 but am confused
« Reply #29 on: September 19, 2016, 12:11:13 PM »
Oh BTW there is a downside to the program. If you stop the m6 for whatever reason before it probes, it will get stuck in a loop looking for a good probe and you will need to exit out to Mach4 and cancel the application running in the backgound.  Worth it though.