Hello Guest it is June 13, 2024, 10:25:57 AM

Author Topic: Setting Auto Zero button help  (Read 4015 times)

0 Members and 1 Guest are viewing this topic.

Setting Auto Zero button help
« on: November 11, 2017, 06:57:49 PM »
Hey guys.
I think ive actually put this in the wrong section can the moderators please move if necessary.

This has probably come up a million times before but I cannot find it in the forum.
Im just setting up Mach 4 on a new machine ive got. This will be just a simple 3 Axis Router with no Tool Changer running the latest Mach4 version.  I would like to use the wxmach.set screen which has the “Auto Tool Zero” button on it. I like this screen because it’s a little more simple than the wx4.set and the others.
I have almost everything set up fine. I have changed my “Go to Zero” button script to work how I would like but im really struggling to understand the following.
In wx4.set I can use the “touch” button to probe down to get my work zero. I would like to add the same script or function to my wxMach.set screen on the “Auto tool zero” button.
As I understand I need to add a script to this like I did in Mach 3. My questions are..
-Does anyone have a script I can use (just a simple drive down wait for probe input, set probe position with plate offset, and drive back up).
-Where in the screen do I need to copy and paste the script into?
The “left up script” or the “screen load script”?
Or does anyone have an easy way of making the “Auto Tool Zero” button work with a macro or something and how do I set it. I have done a lot of reading and im still stuck (maybe I need more sleep)  As I think by default this button has nothing assigned to it in the wxMach.set screen.
My probe input is working fine.
Any help very much appreciated thank you.
« Last Edit: November 11, 2017, 07:00:00 PM by Peter Knell »

Offline DazTheGas

  •  778 778
  • DazTheGas
    • View Profile
Re: Setting Auto Zero button help
« Reply #1 on: November 12, 2017, 05:55:50 AM »
If you are just wanting to probe to get your Z height then you could just execute some gcode from the Left Up Script


Code: [Select]
local inst = mc.mcGetInstance()
mc.mcCntlGcodeExecute(inst,"G91 G31 Z-15 F10")

New For 2022 - Instagram: dazthegas
Re: Setting Auto Zero button help
« Reply #2 on: November 12, 2017, 06:23:29 PM »
Thank you for trying to help Daz. After the gcode execute is there something i can add to make it automatically update and zero the z work coordinates?
Thanks again very much appreciated.
Re: Setting Auto Zero button help
« Reply #3 on: November 12, 2017, 06:41:52 PM »
I did find this script on the forum. I have been reading as much as poss but all this programming does click with me i dodnt think haha.
If i add this to the Left up Script it should work as long as ive set up the Variables and my probe input yes?
Thanks so much for helping.

Author: GB Ward, Create! 2015
Rev: 0.1
Date: 4/25/15
Mach4 4.0.1, Build 2336

Public Domain

Mach4 Core API Version 1.01 (C:\Mach4Hobby\Docs\Mach4CoreAPI.chm)

Mach4 CNC Controller Lua Scripting Guide
Newfangled Solutions 2014

"Motion plugin probing procedure." (C:\Mach4Hobby\Docs\probing.txt)

Down and Dirty "mcLua scripting, quick ref guide"
poppabear, Mach4 English Forums, under "Mach4 Toolbox" board.

Pound Var List - poppabear, Mach4 Forums

McLua mc scripting reference - poppabear, Mach4 Forums


    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

    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
            return false
    end  --checkProbe()

    --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.");
        mc.mcCntlSetLastError(inst, "Z Axis now referenced.");
    end --if

Offline cv580

  •  53 53
    • View Profile
Re: Setting Auto Zero button help
« Reply #4 on: March 19, 2018, 11:01:16 AM »
Did you get this to work? I am trying to do the same as you but have not been able to get the above script to work. Any help you can provide would be greatly appreciated!
Re: Setting Auto Zero button help
« Reply #5 on: March 19, 2018, 05:35:44 PM »
Sorry i can be no help.
I gave up as i had parts i needed machining and never got back to it. I ended up just using wx4.set sadly.
Im wanting to eventually use the Router.set so have set up my Go To Zero but sorry i cannot be of any help. This is the problem with Mach4 you need to invest a lot of time learning if you want to customize, but i still love Mach4 i just need more time on my hands haha.
Let me know if you nut it out. Cheers