Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rae_gordon on September 12, 2016, 05:33:08 PM

Title: Altering M6 but am confused
Post by: rae_gordon on September 12, 2016, 05:33:08 PM
I am attempting to create my own M6 code based on the videos provided but have run into some issues.  First off the reason I am altering the existing code is I don't want to perform 2 probes since I always reference the vacuum table as Z 0.0.   Because if this I only want my machine to go to a predefined spot, prompt to change bits, and Zero to the touch plate which is currently embedded flush with the work surface.  My main confusion is the commands for mcaxisgetpos and mcaxissetpos and how they relate to what I am doing.  I feel I have a good handle on it most of it, but after 8 hours of reading forums I figured it was time to eat my pride and ask for help.

Here is what I have so far, any help or corrections would be appreciated.

function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local TouchPlateThickness = 0.0;                     --What is the offset for the touch plate to the table top.  I dont have this figured in yet.

    if selectedtool == currenttool then
    return
    mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
    mc.mcCntlGcodeExecute (inst,"M05") --make sure spindle is not running
    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 number "..selectedtool.." "..changetoo.." and press ok to continue")
    currenttool = selectedtool --not sure if this goes in this location or is required elsewhere????
    toollen = mc.mcToolGetData(inst, mc.MTOOL_MILL_HEIGHT)
    if toollen == 0 then
    return
    wx.wxMessageBox("No tool length currently defined")
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0 \n G91 G31 Z-6 F25")
    mc.mcAxisSetPos(inst, 2, 0.0) ???
    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
    else
    local probestart = -6 + toollen
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n G91 G31 Z-1 F25")
    mc.mcAxisSetPos(inst, 2, 0.0) ???
    mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
    mc.mcToolSetCurrent(inst, selectedtool)
    mc.mcCntlSetLastError(inst, "ToolChange Finished")
    end
end


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

Title: Re: Altering M6 but am confused
Post by: bob_at_pmdx on September 13, 2016, 02:17:15 AM
This code doesn't look like it should compile.  There are mis-matched if/end blocks and you have code after "return" lines that will never be executed.  I don't know if something got changed when you pasted the code here.

For example, you have (I've changed the indentation to better show the content of the "if" clause):

Code: [Select]
function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local TouchPlateThickness = 0.0;                     --What is the offset for the touch plate to the table top.  I dont have this figured in yet.

    if selectedtool == currenttool then
        return
        mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
    else
      .... more code here
The mc.mcCntlSetLastError() will never execute because it is after the "return".  Any lines of code between a "return" and an "end" (end of code block) will not be executed.  So move the mc.mcCntLSetLastError() line between the "if" and the "return" so that it looks like this:
Code: [Select]
    if selectedtool == currenttool then
        mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
        return
    else
      .... more code here
There are other instances of this further down in the code, including one section of code that performs a probe inside the "if toollen == 0" block.  After moving that mc.mcCntlSetLastError() to before the "return", that prove code should probably be deleted (all the code after the "return" and before the "else").

If the indentation of your original source file is the same as what showed up in your forum post, I suggest changing the indentation so the contents of every "if/end" or "if/else/end" block is immediately visible.  My quick guess is that you need one more "end" just before the "if mc.mcInEditor" line.

Now to your questions:

(1) The line "currenttool = selectedtool" is not needed.  There is nothing below that line that uses "currenttool", it all uses "selectedtool".

(2) I don't see any calls to mc.mcAxisGetPos().

(3) The calls to mc.mcAxisSetPos() tell Mach4 that the where ever Z axis currently is should be called "0.0".  It does this by changing the fixture offset for the currently selected fixture.  And the Z axis *should* be at the point where the new tool touched the touch plate, presuming that the G31 probe command moved far enough for that to happen.

Bob
Title: Re: Altering M6 but am confused
Post by: DazTheGas on September 13, 2016, 02:41:11 AM
Quote
The mc.mcCntlSetLastError() will never execute because it is after the "return".  Any lines of code between a "return" and an "end" (end of code block) will not be executed.  So move the mc.mcCntLSetLastError() line between the "if" and the "return" so that it looks like this:

Never noticed that cheers Bob, although looking at it further because its an "if" or "else" statement then the return is not actually required.


rae_gordon - I understand what you are trying to do using a fixed reference point for zero and will dig out the code for you to play with that I  did for a friend who does just the same thing and sets his wcs to his bed.

DazTheGas
Title: Re: Altering M6 but am confused
Post by: rae_gordon on September 13, 2016, 10:21:15 AM
I haven't tried to compile the project yet, I was just attempting to write and understand what I was doing but was at a standstill due to a lack of what the commands were actually performing. I actually just added the second if statement, and thought that Return was part of the format based upon Daz's M6 sample Code.  Bob, your description of  mc.mcAxisSetPos() clears alot of confusion for me.  All the references I found of the commands tell me what the format should be, but I haven't found a references that give descriptions of what the actually do.  I need to get a Lua guide for reference.

The reason for my nested IF statement and what looks like a duplicate code is I frequently use long bits, 6" or greater for foam cutting.  In the event that I don't have a bit defined, it is likely to be a shorter standard length router bit but didn't want to risk slamming a longer bit into the copper plate that I have surfaced into the table.  Of course I would never put the wrong bit in the router (again).  Because of extreme variety of length I am hesitant to use a guess length as Daz uses in his M6 code. Pondering more on this, I see additional merits for a spring loaded touch plate so that I could rapid , touch, backup, then zero, and not have to wait the eternity it would take to hit the touch plate by stating at the highest height.  Maybe have an Estop if the plate bottoms out.


Daz, I am going to wait for your sample code before I proceed further with what I have in the event that I am on the wrong path.  while I wait for that I am going to re-explore touch plates.

Thanks
Title: Re: Altering M6 but am confused
Post by: DazTheGas on September 13, 2016, 11:49:50 AM
One thing to remember when your writting a macro is the ability you have to step through the code live (debug) and see whats going on, start with a small piece of code IE moving to a safe Z then moving to the position over your touchplate, once you have that then you can move on to creating your toolchange.

DazTheGas
Title: Re: Altering M6 but am confused
Post by: rae_gordon on September 13, 2016, 01:07:47 PM
Thanks Daz,
  I actually had your original M6 profile working for a while but didn't have the touch plate fixed  nor the time to work the bugs, mainly I would forget that it ran 2 touch cycles so user error would kick in and I would change the bit on the first touch cycle. so I shelved it while I completed a job run.  I pondered the idea of altering your code so that it would go ahead and do the first probe without user intervention, but I don't like the idea of the chance that the router may be running when it does the probe.  I had problems where I was fusing my solid state Relays and the router would not turn off.  I believe I solved that problem by utilizing a contactor relay, but time will tell and you never know when goblins may visit my Gcode.  In the mean time I ended up putting collars on my router bits and using that as a stop for setting the bit when I reinserted it, unfortunately the collars are not balanced and with the longer bits it was notable.  Because of this I would have to put the collar on before I removed a bit from the machine, and removed the collar after reinserting.  That worked as a poor mans bit changer, but user error usually showed up,such as forgetting to put the collar on.  


Title: Re: Altering M6 but am confused
Post by: rae_gordon on September 13, 2016, 01:10:25 PM
If for some reason you dont have the sample code available I will continue to edit what I have.  I don't think I am far away from my goal, but there is always a better way.
Title: Re: Altering M6 but am confused
Post by: rae_gordon on September 14, 2016, 06:11:25 PM
This is my new code am I am going to try it out on my machine tomorrow.  I have a looping section in there that seems to work, does anyone see any problems with running something like that.  Also there is a section below that I need help with where I want to be able to manually jog the Z axis while in the M6 macro.  Is there a way to do this then continue the macro.



function M6()
    local inst = mc.mcGetInstance();
    local selectedtool = mc.mcToolGetSelected(inst)
    local currenttool = mc.mcToolGetCurrent(inst)
    local hsig = mc.mcSignalGetHandle(inst, mc.ISIG_PROBE)

    if selectedtool == currenttool then
        mc.mcCntlSetLastError(inst, "ToolChange Activated But Not Required")
        do return end
    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 = -6 + toollen
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z"..probestart.."\n 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 F25")
                until(ProbeState ~= 0)
            mc.mcAxisSetPos(inst, 2)
            mc.mcCntlGcodeExecuteWait(inst,"G90 G53 G0 Z0.0")
            mc.mcToolSetCurrent(inst, selectedtool)
            mc.mcCntlSetLastError(inst, "ToolChange Finished")
        else
            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--???
           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 F25")
                until(ProbeState ~= 0)
            mc.mcAxisSetPos(inst, 2)
            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()
Title: Re: Altering M6 but am confused
Post by: DazTheGas on September 15, 2016, 04:54:31 AM
I would hold off from running this code for now as at a quick glance there are quite a few problems that will arise but should have time today or tomorrow to go through it live on machine.

1.  the "do return end" is not needed (was a mistake on my part originally)
2.  the "repeat - until" could give you a constant loop, if it doesnt hit on first run then it will go straight back to 0 and do the same again.
3.  mc.mcAxisSetPos(inst, 2) will not set anything as correct format is mc.mcAxisSetPos(inst, AxisNumber, AxisPos) so you are missing what you are setting too.

DazTheGas
Title: Re: Altering M6 but am confused
Post by: Stuart on September 15, 2016, 05:52:28 AM
It's that cheeky so and so again  :)

If the OP and DTG would be kind enough to post the code when it is proven I and I suspect others would be extremely grateful for you endeavours

Stuart
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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.
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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
Title: Re: Altering M6 but am confused
Post by: bob_at_pmdx 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
Title: Re: Altering M6 but am confused
Post by: DazTheGas on September 16, 2016, 02:58:49 AM
Just out of curiosity what version of Mach4 are you running??

DazTheGas
Title: Re: Altering M6 but am confused
Post by: DazTheGas 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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]

Title: Re: Altering M6 but am confused
Post by: rae_gordon 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.
Title: Re: Altering M6 but am confused
Post by: bob_at_pmdx 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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

Title: Re: Altering M6 but am confused
Post by: rae_gordon 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.
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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.
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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.
Title: Re: Altering M6 but am confused
Post by: bob_at_pmdx 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon on September 16, 2016, 04:52:51 PM
Thanks Bob I just subscribed.
Title: Re: Altering M6 but am confused
Post by: DazTheGas 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
Title: Re: Altering M6 but am confused
Post by: DazTheGas 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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
Title: Re: Altering M6 but am confused
Post by: rae_gordon 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.