Hello Guest it is July 05, 2020, 04:25:23 AM

Author Topic: How to setup Auto Zero button in latest version of Mach4  (Read 3683 times)

0 Members and 1 Guest are viewing this topic.

Offline cv580

*
  •  50 50
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #10 on: March 20, 2018, 12:34:32 PM »
Replaced line 41 and 42 as per your post, made no difference, still getting the same errors
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #11 on: March 20, 2018, 01:11:15 PM »
When you load mach it re-compiles all scripts and macros so if you have checkProbe() defined in any other file that contains an error mach will not compile correctly.

Move any files with the code you are trying to debug to a directory outside of your mach directory.  Start mach.  If you still get an error like the 'failure while running chunk something else is wrong.  If not then:

From Operator->edit/debug scripts select any m???.mcs file.  Then when in the editor select file->new.  With notepad cut and paste the code into this new file and hit F7.  Now you should get where the offending line of code is. 

HTH

RT


Offline cv580

*
  •  50 50
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #12 on: March 20, 2018, 07:44:42 PM »
RT
Moved the script file to another directory as you suggested, opened the file with the edit/debug,  F7 just gave me a output directory nothing else, tried F5 and managed to crash Lua and ended up with a whole bunch of error screens in the process. Thanks for your time trying to help me out with this.

I don't think I will waste anymore time trying to make this work, I know other people have tried to make a auto zero button in Mach4 but had no success either, appears to be too much flaky script that seems impossible for the non programmer type (like myself) to understand fully to make it work.  The machine has been down for almost 4 weeks now trying to get it to do all the same things with Mach4 that it was doing before with Mach3.
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #13 on: March 20, 2018, 07:50:15 PM »
Hi cv580,
if you don't mind me saying it seems that there is a lot of code in your script with every line a potential fault.

Would you be offended if I cut it down to size and got it to work? I think I could make it much simpler, it may
lose some of its elegance but 'working' beats 'elegant but broken' everytime!

Craig
My wife left with my best friend...
     and I miss him!

Offline cv580

*
  •  50 50
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #14 on: March 20, 2018, 08:21:19 PM »
Craig
I would not be offended at all if you cut it down and get it to work! Any help you can provide would be most appreciated.

cv580

Offline Chaoticone

*
  • *
  •  5,629 5,629
  • Precision Chaos
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #15 on: March 21, 2018, 12:58:42 AM »
Just curious, have you tried the touch button in the wx4 or wx6 screen sets? You can use the TouchOff module to auto zero X Y or Z independently using a touch plate or probe. Find circle, square, rectangle centers, X,Y and Z simultaneously using corners, set Z zero to top or bottom of material, angle of material (G68). No programming required.

https://www.youtube.com/watch?v=VA49atQNzmg
« Last Edit: March 21, 2018, 01:01:43 AM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline cv580

*
  •  50 50
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #16 on: March 21, 2018, 02:04:19 AM »
I have looked at the touch button option, it is not user friendly for a touch screen monitor as the touch/probe page always need to be resized (enlarged) with a mouse to access the Z axis touch button which is hidden until the page is resized.

Is there a way to bring this button or make a button for the z touch to put onto the program run screen?
I have tried to find z touch button with screen editor but no luck.

Or is there a way to have the touch/probe screen permanently full size when using the touch button instead of having to resize it every time when using the touch button feature?

No mouse or keyboard on my machine just touch screen monitor  
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #17 on: March 21, 2018, 03:08:57 AM »
Hi,
you don't want to use the Touch Off module because the buttons aren't big enough? All the hard work has been done but for the lack of a mouse or track ball
you'd ditch it????

Anyway:
Code: [Select]
local mInst = 0;  --Sets current controller instance to 0, if running multiple controller instances, this will need to change
local rc = 0;  --Clear rc
local hSig = 0;  --Clear hSig

You don't need to reset these, they are created anew each time it runs and they are garbage collected once they go out of scope. Redundant. Lua uses a stack for local
variables not a fixed memory location.

Code: [Select]
--SETUP OF VARIABLES
local probe = mc.ISIG_PROBE;  --Set input here, mc.<INPUT_NAME>; input needs to be mapped in Mach4
local strikePlateThickness = 0.060;  --What is the thickness of the strikeplate, or how much do you want to offset 0?

Why bother, you're just getting cute, there is nothing wrong with mc.ISIG_PROBE  There might be a case for a strike plate thickness variable. I'm not going to bother,
I want to get this code down short and sweet, if you want to come back later and pretty it up OK but in the first instance get it to go!

Code: [Select]
function checkProbe ()

hSig, rc = mc.mcSignalGetHandle(inst, probe);  --Load hReg with probe state
state = mc.mcSignalGetState(hSig);  --Get Signal State
if (state == 1) then  --if hReg true ('if probe is activated then')
return true
else
return false
end
end  --checkProbe()

Do you really need a separate function to do this...it means a new local stack and context switch overhead and you use it only twice in the whole script.
I can write it in one line so why bother complicating this thing?

Code: [Select]
return false
This is I suspect will result in a syntax error, 'false' may have meaning in C or C++ but in Lua  0 means false any other number like 1 means true.

Code: [Select]
local CurrFeedRate = mc.mcCntlGetPoundVar(inst, 2134);  --Gets current Feed Rate, #var 2134
local CurrFeedMode = mc.mcCntlGetPoundVar(inst, 4001);  --Gets current G0/G1 state, #var 4001
local CurrPositionMode = mc.mcCntlGetPoundVar(inst, 4003);  --Gets current G90/G91 state, #var 4003
local zProbeStrikePos = 0;  --clear variable

Whats the point of these, you are collecting and storing this info but nowhere later in the script is it being used. Meanwhile you risk syntax/logic errors and for no
gain. Redundant.

Code: [Select]
local zProbeStrikePos = 0;  --clear variable
As per above, this variable is created anew in a stack, no need to clear it.

Code: [Select]
local zAxisCurrentPos = mc.mcAxisGetPos(inst, 2);  --Get Current Z position, sometimes the probe will continue past strike point.
local zAxisDifference = (zProbeStrikePos – ZaxisCurrentPos);  --Gets overshoot, returns positive
local zAxisNewOffset = strikePlateThickness – zAxisDifference;  --Subracts overshoot from known thickness of strikeplat

I use a solid probe when making circuit boards. If there was any significant overrun at the probe event I would know and yet there is not. Do you have any
evidence that allowing for overrun is actually required? I'm not going to bother because I know from personal experience that its not required. Save the extra
coding and the syntax/logic errors that could creep in and upset what should be simple code.

I have some code written and am testing it out. I can't test it on my machine so it may be a bit ragged. Will post when complete.

Craig
My wife left with my best friend...
     and I miss him!
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #18 on: March 21, 2018, 04:08:10 AM »
Hi,
on my laptop without a probe attached, maybe you can test it
Code: [Select]
[code]function autozero()
local inst = mc.mcGetInstance()
local probeHand, rc = mc.mcSignalGetHandle(inst,mc.ISIG_PROBE)
local probeState=mc.mcSignalGetState(probeHand)
if probeState==1 then
    wx.wxMessageBox('Probe already active...cannot proceed')
    return
end
mc.mcCntlGcodeExecuteWait(inst, 'G01 G90 G31 Z-4 F40');
local zProbeStrikePos = mc.mcCntlGetPoundVar(inst, 5063);
mc.mcAxisSetPos(inst, 2, 0.060);
mc.mcCntlGcodeExecuteWait(inst, 'G00 G91 Z1');  --Rapid move to 1 inch above current pos
probeState=mc.mcSignalGetState(probeHand)
if probeState == 1 then
    wx.wxMessageBox("Probe is still activated! Check to make sure probe is not damaged or still contacting strike plate.");
else
    mc.mcCntlSetLastError(inst, "Z Axis now referenced.");
end
end
if mc.mcInEditor()==1 then
    autozero()
end

Couple of things I should point out. You see I have written this as a function and looks very much like a macro. I do this when I'm writing new code so I can put
it in a separate folder within my profile and I can run it with the debugger in the editor. Having it in a separate file means I don't pollute my macro folder with
buggy code. Once I've manually stepped through it and run a few tests then I will put in into its final location.

Here again I follow a somewhat iidiosyncratic policy of putting the function in the screen load script, usually near the top. Then I will put a function call on the button, not
the script itself. It means that when I go to find the script and edit it or have to delete it because its that buggy I can find it easily. If I were to attach the script
direct to the button the script will be buried in the screen script somewhere....I find it so much more convenient to put it at the top of the screen load script.
If it works out really well by all means put it direct on the button. This script is for my purposes only temporary to help you out so when we're done with it I'll delete
it knowing exactly where it will be.

Let us know if it works...

Craig[/code]
My wife left with my best friend...
     and I miss him!
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #19 on: March 21, 2018, 07:12:36 AM »
Hi,
I see an error, when I was testing I upped the probe feed speed to 40, my installation has native units of mm so I had to increase the speed or
be there all night waiting for it to complete.

You'll need to edit it back to F4.

Craig

My wife left with my best friend...
     and I miss him!