Hello Guest it is March 19, 2024, 07:52:05 AM

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

0 Members and 1 Guest are viewing this topic.

Re: Mach4 cnc program min/max values
« Reply #20 on: April 13, 2019, 07:57:45 PM »
Hi,
because the PLC script runs every 50ms (default) the code needs to be pretty quick and slick otherwise
it will block the rest of Mach.

For this reason the code I posted is pretty lean but at the same time detailed enough to make it readable.

Note these lines:
Quote
local workZMaxHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmax')
local workZMax=mc.mcRegGetValue(workZMaxHandle)-zOffset
local workZMaxHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMax')

Note that I have redefined the variable workZMaxHandle, first I used it to address the core register PathZmax
and then redefined it to address the instance register iRegs0/workZMax. I did this so the one variable is reused.
Note that I did it a second time with workZMinHandle. On the one hand it reduces the number of variables
that Lua has to keep a track of but on the other hand can be confusing for someone else to read.

If I were writing this code for myself I would streamline it even further, albeit at the expense of readability.

Code: [Select]
local zOffset=mc.mcCntlGetOffset(inst,mc.Z_AXIS,mc.MC_OFFSET_FIXTURE)
local regHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmax')
local MaxMin=mc.mcRegGetValue(regHandle)-zOffset
regHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMax')
mc.mcRegSetValue(regHandle,MaxMin)
regHandle=mc.mcRegGetHandle(inst,'core/inst/PathZmin')
MaxMin=mc.mcRegGetValue(regHandle)-zOffset
regHandle=mc.mcRegGetHandle(inst,'iRegs0/workZMin')
mc.mcRegSetValue(regHandle,MaxMin)

Here I reduced the number of variables to three, zOffset, regHandle, and MaxMin, with the last two being recycled at need.
Not as readable but will run a little faster.

Craig
« Last Edit: April 13, 2019, 08:08:16 PM by joeaverage »
'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 #21 on: April 13, 2019, 09:25:41 PM »
I home off the limit switch at the top of my mill's column, then move down from there and set my G54 off the top of my part held in the vice in this case.  I use tool height offsets, hence the G43's in the program.  I use tool #1 for indicating all 3 axis for part zero.  That's the only use for tool #1.  I always hit the home/limit switches at startup, move to the middle of my mills travels and do a tool change to tool one.  In my M06 macro i have a Z move that raises the mill head up 4" below the limit switch and change tools.  For the first tool change of the day it's just a M06 to tool #1, no G43.  Then I toggle tool height on in the offset panel and go to finding zero's for my part.  After that it's M06 tool changes with G43's.

I can actually hit the home/limit switches and repeat within a couple tenths of my indicated zeros most times unless I get swarf on the triggers that bump the switches, mostly only a problem on Y.  Z never has that problem and X rarely.

So after that, all upward Z moves are positive.   

Regards
Bob

Offline Bob49

*
  •  57 57
    • View Profile
Re: Mach4 cnc program min/max values
« Reply #22 on: April 13, 2019, 09:37:37 PM »
Hi Craig,

Been out trying to figure all this stuff out and get some working Z dro's for the work offset.  And I got them working after I fumbled around trying to find the registers to create those two.

And they seem to work.  I'll swap the code out yet tonight to your's below.

But I got one more question.  In my pea brain, I'm thinking the Z max value should reflect the highest Z+ value unless the current tool has exceeded that position.  Then whatever the tool is above the highest Z+ value in the program would be added to the highest Z+ value.  Am I thinking wrong?  The Z max value just continues to change even with the tool point inside the Z values in the program.  That's not making sense to me as I never get a hard value for Z max but I do for Z min.  Z min always reflects what the lowest Z value in the program is.  So likewise I think if the tool exceeded the lowest Z value in the program, that value would then change to reflect that until it came back in the Z range the program reflects.  Does this even make sense? 

Regards
Bob
Re: Mach4 cnc program min/max values
« Reply #23 on: April 13, 2019, 10:04:26 PM »
Hi,
the code I posted calculates the work coordinate maximum as the machine coordinate maximum minus the current
axis offset. The line of code that does the calculation is:

Quote
local MaxMin=mc.mcRegGetValue(regHandle)-zOffset

And the variable zOffset is defined:

Quote
zOffset=mc.mcCntlGetOffset(inst,mc.Z_AXIS,mc.MC_OFFSET_FIXTURE)

But note that the zOffset variable does not include tool offset. I'm less sure about g92 and head offsets.
I guess the way is to experiment by substituting values into the Z axis machine diagnostics page and see what happens
to the output. My inclination is for the ZMax and ZMin be in work coordinates but WITHOUT any tool length offset.
That may or may not make sense to you. If it does not then by all means substract the current tool length from
MaxMin variable as you desire.

This is Machs great strength, you can modify it to suit your expectation.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 cnc program min/max values
« Reply #24 on: April 13, 2019, 10:32:41 PM »
Hi,
a little experimentation shows that variable MaxMin is not affected by g92, Head offset, Work Offset or Tool Offset.
If you wish those to be included then the calculation will need those additional terms.

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 #25 on: April 13, 2019, 10:42:34 PM »
Hi Craig

"My inclination is for the ZMax and ZMin be in work coordinates but WITHOUT any tool length offset."

That's how I think it should work.  When I was messing with it earlier I wasn't seeing tool height values in the differences I was getting.  But that did occur to me that I might find that.

I've given up for the evening, plan to mess around more with it tomorrow.  It's one of those things I'd like to use in Mach that I just ignored not understanding what it was telling me.  Probably come back and re read all this in the morning before heading to the shop.  But experimenting with stuff is right down my alley. 

Thanks for the help and the code, I enjoyed doing that in spite of not really knowing for sure what I was doing.  Might have more question though.

Regards
Bob
Re: Mach4 cnc program min/max values
« Reply #26 on: April 13, 2019, 11:03:01 PM »
I home off the limit switch at the top of my mill's column, then move down from there and set my G54 off the top of my part held in the vice in this case.

So after that, all upward Z moves are positive.   

Regards
Bob
OK. that is "typical", I do the same here.
As you say, "all upward Z moves are positive" … in your WORK coordinates. But in Machine coordinates you cannot go above Z0.00.
The Z Max extents dro shows Z+3" … in MACHINE coordinates.
I don't see how that is possible. Why would that NOT throw a soft limit warning ?
Home the Z at the top.
Z neg to the material 2" and zero the G54 z offset.
Now run the part which has a 3" z+ and it will crash as it will go 1" zpos in machine cords. and shows this in the extents dro z max.
Now, come down 4" instead to set the z offset and the entire 3" of z travel is well within the z Machine cords and shows so in the Z extent dros as they are both NEG.
Guys, please help me get around this understanding, and I'll go back to lurking. :)

thanks



Offline Bob49

*
  •  57 57
    • View Profile
Re: Mach4 cnc program min/max values
« Reply #27 on: April 13, 2019, 11:50:09 PM »
I don't use soft limits, and have about 20" of Z travel if the vise is removed.  Maybe less, spindle end to table that is.  Insert a tool and it's reduced of course.  So at the Z home switch, from the tool tip to the part is maybe 12", just a guess here right now as I wasn't paying much attention to that today.  Plenty of room to move around.

I've not worked all that out on the min/max travels dro's yet.  That's my goal for tomorrow, come to a good understanding of that those dro's are telling me.  And quit ignoring them as I know they can be helpful.

Regards
Bob
Re: Mach4 cnc program min/max values
« Reply #28 on: April 14, 2019, 12:04:36 AM »
Thanks Bob.
Something definitely weird going on there.
I put your example file here at -4" Z work offset from home.
All looks normal here.
Hope you don't mind the interrupt, I'm just trying to keep up  ;)
Cheers,
Russ

Offline Bob49

*
  •  57 57
    • View Profile
Re: Mach4 cnc program min/max values
« Reply #29 on: April 14, 2019, 12:17:39 AM »
Don't mind at all, always trying to learn.  Keep in mind the two shots I showed of that panel I set the coordinates as work coordinates, not machine coordinates.  So the Z3.00 in the "current" dro's was 3" above my part in the vise.  And I didn't have tool #2 in the spindle, I still had tool #1 loaded with it's tool height offset active.  Think there's just under 1.5" difference between the two with tool #2 being shorter.  Sorry I forgot to mention that prior.

Tomorrow I'm going through my startup and then will load tool #2 and see what I see on the min/max dro's.  That way I won't have to do any math due to the different tools.  But that shouldn't have any bearing on the Z totals if I'm at or below Z3.0 in my work offset.  At least that's what I'm hoping.

Regards
Bob