Hello Guest it is March 28, 2024, 09:23:57 AM

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

0 Members and 1 Guest are viewing this topic.

Re: Altering M6 but am confused
« Reply #10 on: September 15, 2016, 10:05:58 AM »
I am working with my machine also and my code did loop to the point that I could not shut it down.  Opps.  I came in to resolve the SetPos and will have a revised code posted shortly and will post the results if I can get it hashed out.  Hopefully the only issue with my revised version will be the manual Z jog that I have no Idea about how to accomplish.
Re: Altering M6 but am confused
« Reply #11 on: September 15, 2016, 04:39:52 PM »
OK, this is what I have so far and I am stuck again.

  The main concept works, but there are still issues that I need help with.  I may need to reinstall because I now run into the issue where my Fixture offset for Z gets deleted when restarted.  This may not be the correct way, but the Z offset is the distance from my table to the router collet,  its the only way I could get the math to work the tool table bit length.  if there is a correct way, please let me know.  For reference, my Z height offset is set at -11.375

Problems
1) Initial M6 works because the machine has to move, if I do another m6 without first jogging the machine, I get an PMDX underrun error and have to restart the software.  If I jog the machine away so it has to move between M6 commands it does what it is supposed to, to the extent I have tested it.  Worst case I can check the location and skip the movements, but it doesnt seem correct to me.

2) If an z offset is enabled such a the bit or fixture while the m6 command is active it uses this value for the probe value and thus records the wrong bit length. I have not tried it with a program yet to see if that is going to occur, but I would like to find a way to prevent it in the event.  I figured I could check the state, if it is enabled, turn if off, then turn it back on, but there may be an easier way.

Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)

  [color=blue] -- local currentheightoffset = mc.mcCntlGetOffset (inst , 2) basis for controlling event that tool offset is active
        --local HOState = mc.mcCntlGetPoundVar(inst, 4008)
        --if (HOState == 49) then
        --mc.mcCntlMdiExecute(inst, "G43")
        --else
        --mc.mcCntlMdiExecute(inst, "G49")
        --end[/color]

    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
        local changetoo = mc.mcToolGetDesc(inst,selectedtool)

        wx.wxMessageBox("Please change to tool "..selectedtool.." which is a "..changetoo.."")
        toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
        if toollen ~= 0 then
            local probestart = (-11 + toollen)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
            ProbeState = mc.mcSignalGetState(hsig)
                if ProbeState == 0 then
                    repeat
                        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)
                    local zoffset = mc.mcAxisGetPos(inst, 2)
                    mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
                    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
                    --mc.mcToolSetCurrent(inst, selectedtool)
                    mc.mcCntlSetLastError(inst, "ToolChange Finished")
                else
            local zoffset = mc.mcAxisGetPos(inst, 2)
            mc.mcToolSetData (inst, mc.MTOOL_MILL_HEIGHT, selectedtool, zoffset)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            --mc.mcToolSetCurrent(inst, selectedtool)
            mc.mcCntlSetLastError(inst, "ToolChange Finished")
                end
        else
            wx.wxMessageBox("No tool length currently defined Lower Z to above touch plate, hit enter to start probe")
[color=red] --need a way to lower Z manually here and have not verified this portion of code--[/color]
           mc.mcCntlGcodeExecuteWait(inst," G91 G31 Z-.5 F25")
            ProbeState = mc.mcSignalGetState(hsig)
                repeat
                   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")
                until(ProbeState ~= 0)
            mc.mcAxisSetPos(inst, 2, toolz)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            --wx.wxMessageBox("Please turn on spindle and click ok to continue") --can be removed if required
            --mc.mcToolSetCurrent(inst, selectedtool)
            mc.mcCntlSetLastError(inst, "ToolChange Finished")end
    end
    mc.mcToolSetCurrent(inst, selectedtool)
end

if (mc.mcInEditor() == 1) then
    M6()
end
Re: Altering M6 but am confused
« Reply #12 on: September 15, 2016, 10:22:42 PM »
Quote
1) Initial M6 works because the machine has to move, if I do another m6 without first jogging the machine, I get an PMDX underrun error and have to restart the software.  If I jog the machine away so it has to move between M6 commands it does what it is supposed to, to the extent I have tested it.
This sounds like the there may be an issue in the SmartBOB with *very* short moves during probing.  I'll have to try that here.  When you run the M6 the 2nd time, is the tool still in contact with the touch plate?  Or has it backed off a little bit?  A lot?

If you do get the "motion underrun" error, you *should* be able to click on the Mach4 "Enable" button and continue running the machine (like, say, jogging the Z axis away from the touch plate).  Does that not work for you?  If you click on the "History" button in the lower left of the Mach4 screen, do you see any other messages?


Your fixture offset may be getting clobbered because of this call:

            mc.mcAxisSetPos(inst, 2, toolz)

The variable "toolz" is not declared anywhere, nor is it ever assigned a value.  I'm not that familiar with Lua so I don't know what it does with undeclared variables and variables to which nothing has yet been assigned.  It may initialize them to zero, or they may have some random value.  And mcAxisSetPos() sets the position by changing the fixture offset, as I mentioned in an earlier post.  However, that function only gets called when "toollen" is zero, and I don't know if that part of your code is every run.

Bob

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Altering M6 but am confused
« Reply #13 on: September 16, 2016, 02:58:49 AM »
Just out of curiosity what version of Mach4 are you running??

DazTheGas
New For 2022 - Instagram: dazthegas

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Altering M6 but am confused
« Reply #14 on: September 16, 2016, 03:33:02 AM »
As a quick attempt to clean up the code this is what I feel is a more clean approach, its not tested but should give you something to go on.

Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local changetoo = mc.mcToolGetDesc(inst,selectedtool)
    local toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT, selectedtool)
    local probestart = (-11.5 + toollen ) -- math here needs to be the -travel distance between collet and touchplate + toollen + probe depth


    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 do this
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-.5 F8")
    mc.mcAxisSetPos(inst, 2, 0)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            mc.mcCntlSetLastError(inst, "ToolChange Finished")
        else -- if toollen is not defined do this
    wx.wxMessageBox("No tool length currently defined Lower Z to above touch plate, hit enter to start probe")
--need a way to lower Z manually here and have not verified this portion of code--
-- This can be done with a modal dialog I can sort later --
-- Do not run this part until dialog is sorted --
    mc.mcCntlGcodeExecuteWait(inst,"G91 G31 Z-.5 F8")
    mc.mcAxisSetPos(inst, 2, 0)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            mc.mcCntlSetLastError(inst, "ToolChange Finished")
end
    end
    mc.mcToolSetCurrent(inst, selectedtool)
end

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

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Altering M6 but am confused
« Reply #15 on: September 16, 2016, 09:28:31 AM »
Quote
Your fixture offset may be getting clobbered because of this call:

            mc.mcAxisSetPos(inst, 2, toolz)

Bob, I don't believe this to be an issue since I have not finished this portion of the code and have yet to run an instance where this portion is utilized.  Saying that, I don't  know if there would be any adverse effects to it just being in there. 

This sounds like the there may be an issue in the SmartBOB with *very* short moves during probing.  I'll have to try that here.  When you run the M6 the 2nd time, is the tool still in contact with the touch plate?  Or has it backed off a little bit?  A lot?

If you do get the "motion underrun" error, you *should* be able to click on the Mach4 "Enable" button and continue running the machine (like, say, jogging the Z axis away from the touch plate).  Does that not work for you?  If you click on the "History" button in the lower left of the Mach4 screen, do you see any other messages?
[/quote]

after each probe instance, the Z goes all the way back up to the top zero location.  I believe the underrun only occurs when this line is initiated and I am already in this location.  If it has to jog to get here the underrun does not occur.  At least that is what I believe.  I am curious if you would get an underrun if you initiate a move to say 0,0,0 while at 0,0,0?

[/quote]
 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
[/quote]

Re: Altering M6 but am confused
« Reply #16 on: September 16, 2016, 09:33:41 AM »
Gaz,
  Thanks for the Code, my first impression is that there is no reason for me to write to the tool file every time which is what I was doing.  I will rewrite and post my results though I am still going to keep it complicated.
Re: Altering M6 but am confused
« Reply #17 on: September 16, 2016, 11:20:01 AM »
First:
Quote
If you do get the "motion underrun" error, you *should* be able to click on the Mach4 "Enable" button and continue running the machine (like, say, jogging the Z axis away from the touch plate).  Does that not work for you?  If you click on the "History" button in the lower left of the Mach4 screen, do you see any other messages?
When you get the underrun, have you tried the above and can you restore operation?  Do you see any other messages in the History window?

Quote
I am curious if you would get an underrun if you initiate a move to say 0,0,0 while at 0,0,0?
If the Z axis *really* is at 0 (in machine coordinates, aka the "G53" in your command), then sending a "G90 G53 G0 Z0.0" command to Mach4 will not generate any motion from the motion planner.  And I have tried having Mach4 generate *very* moves, including moves of only 1 step, and I cannot cause an underrun.  At least on my PC.

Quote
after each probe instance, the Z goes all the way back up to the top zero location.  I believe the underrun only occurs when this line is initiated and I am already in this location.  If it has to jog to get here the underrun does not occur.  At least that is what I believe. 
Do you *always* get the underrun error on the 2nd M6 if you run two M6 commands back to back?  Or does it only happen sometimes?

If you can replicate underrun error, please enable our plug-in's debug log as described here:

        http://faq.pmdx.com/content/3/3/en/how-to-capture-a-debug-log-file-and-send-to-pmdx.html

After you enable the log, exit Mach4 and re-start it.  Then run the consecutive M6 cycles, or whatever you have to do to cause the underrun  Then disable to debug log as described in the FAQ, create a profile package and send that to me.  You can post the profile here on this forum, or you can email it directly to me at bob at (fill in my company name here).com.

When you post or email the profile package please also include:
- any GCode file or MDI commands that you are using to make the M6 calls
- What version of Windows you are running (XP, 7, 8, 8.1, 10) and whether it is 32-bits or 64-bits.
- Are you running any other programs on your PC at the same time Mach4 is running?

Bob
Re: Altering M6 but am confused
« Reply #18 on: September 16, 2016, 12:06:59 PM »
Ok, this is my newest version, It looks good and allows me to call a non defined bit and still auto zero.  may take a while for the bit to there based on the longest bit you enter.  Will try it on my machine


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 #19 on: September 16, 2016, 12:20:42 PM »
Bob,
  I changed my code completely but I will do the same tests with this code.  Also I know I am running an older version of firmware and will get you that information after lunch.

If I remember correctly I did get the underrun and could jog, but since my probe state was not qualified it was stuck in the M6 command because it was never finished.  At least that is what I remember.

I rebooted my computer and low and behold it is doing windows updates, so will get more info after lunch.