Hello Guest it is July 13, 2020, 05:29:02 AM

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

0 Members and 1 Guest are viewing this topic.

Offline cv580

*
  •  50 50
    • View Profile
How to setup Auto Zero button in latest version of Mach4
« on: March 18, 2018, 10:50:56 PM »
How do I set up a Auto Zero button in the latest version of Mach4?
I have tried the scripts from previous posts on this forum, but they bring up errors when I try to run them so I assume something is different in the latest version of Mach4 that does not allow auto zero script to work from the older version. Any help on this would be greatly appreciated.
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #1 on: March 18, 2018, 11:22:06 PM »
Hi,
no, more likely Mach is trying to home axes that have not been assigned or have home switches fitted and assigned.

Can you post a screen shot of the Home/Limits page and Motor Assignment page?

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 #2 on: March 19, 2018, 12:49:07 AM »
Craig,
There are no issues in the home/limits or motor assignment pages.
The errors I get are in the script editor when running the script and debugging the script. I got the script from a early post that was used on a early version of Mach4. The latest version of Mach won't even run the script 

Offline cv580

*
  •  50 50
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #3 on: March 19, 2018, 12:51:13 AM »
This is the script I am trying to make work

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
local inst = mc.mcGetInstance(mInst);  --Captures current instance of Mach 4

 --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?

 --Function to check to see if probe already grounded
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()

 --BEGIN
 --Get current Feed rate, G90/G91, G0/G1 states to return to later.
 --Mach4 stores these variables as 'Pound Variables'
 --See Mach4 Lua Scripting Manual Page 23
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

if checkProbe() then  --Check probe status
mc.mcCntlSetLastError(inst, "ERROR: Probe is already triggered.  Cannot continue.");
do return end  --"do return end" stops program. Not sure how this works
end --check if probe is grounded

mc.mcAxisSetPos(inst, 2, 0);  --"Zero Z" (0 is x, 1 y, and so on)
mc.mcCntlGcodeExecuteWait(inst, 'G01 G90 G31 Z-4 F4');  --G31. Machine will stop on probe strike or go to Z-4, store in #var 5063
local zProbeStrikePos = mc.mcCntlGetPoundVar(inst, 5063);  --Get Z strike position
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 strikeplate
mc.mcAxisSetPos(inst, 2, zAxisNewOffset);  --Sets DRO to current position
--mc.mcAxisSetMachinePos(inst, 2, zAxisNewOffset);  --Sets Machine to offset if anyone finds this necessary
mc.mcCntlGcodeExecuteWait(inst, 'G00 G91 Z1');  --Rapid move to 1 inch above current pos

local isProbeSafe = checkProbe();  --Checks to see if probe is safe
if isProbeSafe == true 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 --if
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #4 on: March 19, 2018, 01:47:39 AM »
Hi,
nice work but I don't think its going to work. When the controller detects a probe contact it will report back to Mach but it could take many milliseconds.
Mach then has to decide what to do and then instruct the controller, again with a delay of many milliseconds. The combined delay will mean most probably
that the probe gets crunched and certainly you will have NO accuracy.

How then does Mach probe, and probe accurately? You use a G31 command and the entire thing is handled by the motion controller which is near enough
to instantaneous.

Mach and Windows is not a realtime control system. It will respond to inputs in around 50ms, which is OK for buttons and on/off switches and things like that but anything
absolutely time critical it can't do. If the controller has been programmed to do whatever function is required all good, if not then you have to accept time delays
which usually wreck the function you are trying to perform.

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 #5 on: March 19, 2018, 01:53:42 AM »
Hi,
please hold up on my previous post, I see that you have used a G31 to get the critical data and so the delays I was talking about will not eventuate.

I apologise, I need to read a little more carefully.

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 #6 on: March 19, 2018, 10:57:07 AM »
What do I need to do to make this work?
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #7 on: March 20, 2018, 10:31:10 AM »
When you debug this in the editor using F5, then stepping through each line by using successive  f11's, what line does it fail on?

Offline cv580

*
  •  50 50
    • View Profile
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #8 on: March 20, 2018, 11:31:26 AM »
Not able to use F5 as I get (Error While Running Chunk) right away, then the run session ends.
When trying to debug I get (At Breakpoint Line 1) then (Failed reading from debugger socket)

Also get the (Error While Running Chunk) in the message screen when loading Mach if this file is in the Macro folder
Re: How to setup Auto Zero button in latest version of Mach4
« Reply #9 on: March 20, 2018, 11:47:09 AM »
replace these two lines (41 and 42) by typing in directly.  there appears to be a bad hidden character

local zAxisDifference = zProbeStrikePos -ZaxisCurrentPos
local zAxisNewOffset = strikePlateThickness - zAxisDifferemce