Hello Guest it is March 28, 2024, 07:30:03 PM

Author Topic: Mach4 cnc program min/max values  (Read 5871 times)

0 Members and 1 Guest are viewing this topic.

Offline Bob49

*
  •  57 57
    • View Profile
Re: Mach4 cnc program min/max values
« Reply #30 on: April 14, 2019, 03:06:47 PM »
Finally got out in the shop to play around again.  Did my usual startup routine, changed to tool #1, found x0, y0 and z0.  Changed to tool #2, first one in that program, and applied a g43 to it.  Brought it down to Z3.0 and the difference was what I expected it to be, take off the tool height for that tool and there's the z+ travel of the program.   

And why my brain wasn't working well with this last night was due to the fact tool #1 was in the spindle with it's tool height applied.  Tool #1 isn't in the program.  If I'd have taken the tool out and left the spindle with no tool, it would have worked moving the spindle end at least to Z3.0 or below in my G54 offset.  That didn't dawn on me then.

That all didn't dawn on me till late last night.  Once it did things got clearer.  And today things worked like I thought they would.  So I think the main reason the Z max has never made sense to me is I must have been thinking tool height was accounted for in that reading.  Never once did I subtract the current tool height to see what the reading would be.

Once again, I want to thank Craig for taking time out of his life to help me with this and putting that code together.  And thanks to the rest of you for the comments and things that got me to thinking on what I was struggling with.  I might try at some point to see if I can get the tool height applied to the Z max value, let Mach do the math for me there.  I'll have to study on doing that though.  I got no clue right now how to put that code in the script.

Thanks to all again
Bob
Re: Mach4 cnc program min/max values
« Reply #31 on: April 14, 2019, 05:14:09 PM »
Hi,
easy, I added a toggle button to the DRO block. With ToolLegthComp ON (green and blinking) tool length
is compensated, ie subtracted from zOffset. Note the button is connected to Output#63

Then in the PLC script tests the state of Output#63 and compensate or not as the case may be.

Code: [Select]
--*****************************************************************************
local zOffset=mc.mcCntlGetOffset(inst,mc.Z_AXIS,mc.MC_OFFSET_FIXTURE)
local toolCompHandle=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT63)
local toolComp=mc.mcSignalGetState(toolCompHandle)
local toolNum=mc.mcToolGetCurrent(inst)
local toolLength=mc.mcToolGetData(inst,mc.MTOOL_MILL_HEIGHT,toolNum)
if (toolComp==0) then
zOffset=zOffset-toolLength
end
local workZMaxHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmax')
local workZMax=mc.mcRegGetValue(workZMaxHandle)-zOffset
local workZMaxHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMax')
mc.mcRegSetValue(workZMaxHandle,workZMax)
local workZMinHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmin')
local workZMin=mc.mcRegGetValue(workZMinHandle)-zOffset
local workZMinHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMin')
mc.mcRegSetValue(workZMinHandle,workZMin)
--**********************************************************************************

Note that I don't use tool lengths so it may be that the compensation is applied wrongly, ie negatively whereas
your expectation is for positive compensation. Please test it before use.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline Bob49

*
  •  57 57
    • View Profile
Re: Mach4 cnc program min/max values
« Reply #32 on: April 14, 2019, 09:24:12 PM »
Got that new code in the PLC and fought with my pc a while.  Had to restore Mach to yesterdays config to get Mach to launch.  Must have done something I wasn't aware of but it's going again.

Followed your lead and made the button and added the text.  Dropped in the code and gave it a try.  I had to change the minus to a plus as the math was adding the tool height instead of subtracting it.  New math I guess.  But then I found the tool height was getting added to the z min while subtracting form the z max.  Kinda guessed that might happen with only one identifier for both readings.

So I knew I needed a different identifier for the z max value being fed to the dro.  You can see what I ended up with in the attached code.  Only one caveat remains and that is the tool needs to be at the highest programed Z value to read Z max correctly.  Otherwise it changes with the tool position even if it's below the highest programmed Z.  Hope that makes sense.

Thanks for the help once again Craig
Regards
Bob

Code: [Select]
local zOffset=mc.mcCntlGetOffset(inst,mc.Z_AXIS,mc.MC_OFFSET_FIXTURE)
local toolCompHandle=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT63)
local toolComp=mc.mcSignalGetState(toolCompHandle)
local toolNum=mc.mcToolGetCurrent(inst)
local toolLength=mc.mcToolGetData(inst,mc.MTOOL_MILL_HEIGHT,toolNum)
local zMaxOffset=zOffset
if (toolComp==0) then
zMaxOffset=zOffset+toolLength
end
local workZMaxHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmax')
local workZMax=mc.mcRegGetValue(workZMaxHandle)-zMaxOffset
local workZMaxHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMax')
mc.mcRegSetValue(workZMaxHandle,workZMax)
local workZMinHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmin')
local workZMin=mc.mcRegGetValue(workZMinHandle)-zOffset
local workZMinHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMin')
mc.mcRegSetValue(workZMinHandle,workZMin)
Re: Mach4 cnc program min/max values
« Reply #33 on: April 15, 2019, 12:47:51 AM »
Hi Bob,
kool.

By far and away the greatest strength of Mach4 is its ability to be customized. This is a fairly simple example of that strength.
I get a personal sense of satisfaction about programming some new behavior that suits my work flow and that satisfaction
is the best incentive to learn new stuff to extend the boundaries.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'