Hello Guest it is April 24, 2024, 12:26:04 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Gerber Baby

Pages: 1 2 »
1
Mach4 General Discussion / Auto Tool Zero Script
« on: April 26, 2015, 03:09:08 PM »
Hey guys!  I know a lot of you have been looking for this!  Hopefully this will help some of you and I'd be happy to help you adjust it.  

I DO NOT HAVE A MACHINE SO AT THE MOMENT THIS SCRIPT IS UNTESTED!!!
I'm pretty sure it will work though. I have tested everything I can in the simulator, but as the simulator does not support G31 I cannot test a few lines.  If any of you guys would want to volunteer that would be awesome.

Just copy and past the script into the button.  I have included the MCS files for the button, or if you want to use it as a macro.  If you wish to use it as a macro you will need to rename it "m10.mcs".

Do note Mach4 may seem to lock up during movement, as it's receiving the "GCodeExecuteWait" command.  That can be easily changed, but I didn't know how the "GCodeExecute" command would work on a real machine.

At any rate it should get a lot of you started on your own scripts.

Code: [Select]
--[[
AUTO TOOL ZERO FUNCTION
Author: GB Ward, Create! 2015
Rev: 0.1
Date: 4/25/15
Mach4 4.0.1, Build 2336

License:
Public Domain

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

Mach4 CNC Controller Lua Scripting Guide
Newfangled Solutions 2014
http://www.machsupport.com/wp-content/uploads/2014/05/Mach4%20Scripting%20Manual.pdf

"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
http://www.machsupport.com/forum/index.php?action=dlattach;topic=27396.0;attach=38035

McLua mc scripting reference - poppabear, Mach4 Forums
http://www.machsupport.com/forum/index.php?action=dlattach;topic=27141.0;attach=37937

]]

    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

2
Mach4 General Discussion / Re: G31.1, G31.2, G31.3 working?
« on: April 26, 2015, 02:58:04 PM »
Not sure the answer to your primary question, but MachGUI does not shut down when there is an unresolved G31.  Mine does that too.  Your options are to let the G31 finish or sometimes Reset, Enable/Disable takes care of it for me.

3
Mach4 General Discussion / Re: Getting current GCode States
« on: April 26, 2015, 12:22:32 AM »
Thanks guys.  Happy to be here.  Let me know if you see a list of the pound vars, b/c I'm kind of wandering around in the dark on that one.  This thread has the best list I've seen so far: http://www.machsupport.com/forum/index.php/topic,27264.20.html

Also, here's the link to the LUA Scripting Manual if anybody wants it:
http://www.machsupport.com/help-learning/product-manuals/

4
Mach4 General Discussion / Re: Having trouble with Lua Script
« on: April 25, 2015, 11:19:55 AM »
Yeah.  Didn't work on my machine either.  Looks like mc.mcCntlMdiExecute() doesn't work in macros.  It does work with buttons though.  Use mc.mcCntlGcodeExecute(); instead like so:

Code: [Select]
function m1000()

local mInst = 0;
local rc = 0;
local inst = mc.mcGetInstance(mInst);

mc.mcCntlGcodeExecute(inst, "G00 X5 Y5 \nZ5");

end

if (mc.mcInEditor() == 1) then
    m1000()
end

If you need it to wait for the Gcode without moving on (sometimes Gcode begins to run the next line without finishing the previous) try mc.mcCntlGcodeExecuteWait();

5
Mach4 General Discussion / Re: Having trouble with Lua Script
« on: April 24, 2015, 10:46:32 AM »
Also not sure how your M1002 function is going to work unless it's supposed to do nothing.   The end  command directly follows the m1002 declaration

6
Mach4 General Discussion / Re: Getting current GCode States
« on: April 24, 2015, 10:36:27 AM »
Hey guys, answered my own question.  These things are stored as # variables.  I found the Mach 4 Scripting Manual today in the manuals section where the Mach 4 is downloaded , which seems to be new unless I missed it previously.

2134 stores last feed rate
4001 stores G00 or G01 and results as 00 or 10
4003 stores G90 or G91 and results as 910 or 900

How to set variables (excerpt):
Code: [Select]
local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)


7
Mach4 General Discussion / Re: Having trouble with Lua Script
« on: April 24, 2015, 10:14:35 AM »
Yeah, the code I gave you is incorrect.  Somehow I managed to not include the controller instance.  I tested all that code before I sent it to you I guess I copied the wrong one.  Also the GCode command string needs to be in quotes.

Code: [Select]
mc.mcCntlMdiExecute(inst, "G00 X5");  --moves x to 5, and does basic Gcode anything.
Also, if you need to run a command with multiple lines of code, you would add the \n

Code: [Select]
mc.mcCntlMdiExecute(inst, "G00 G90 X0.0 Y0.0\nZ0.0");

8
Mach4 General Discussion / Getting current GCode States
« on: April 23, 2015, 09:42:37 PM »
Is there an easier way to see if am in G90, G0, etc without calling

mc.mcCtrlGetModalGroup();

and then doing clumsy Lua string manipulation to find if they are in the returned string?

I just really want to be able to know if I am in certain G-code modes so I can set it back later after zeroing my tools. 


9
Mach4 General Discussion / Re: Having trouble with Lua Script
« on: April 23, 2015, 08:01:33 PM »
READ:
http://www.machsupport.com/forum/index.php/topic,27141.0.html
http://www.machsupport.com/forum/index.php/topic,28484.0.html

Snippets:

Always do this first
Code: [Select]
local mInst = 0;
local rc = 0;
local inst = mc.mcGetInstance(mInst);
--always start with the above code

move x to 5

Code: [Select]
mc.mcCntlMdiExecute(G00 X5);  --moves x to 5, and does basic Gcode anything.
Deactivate Output 1

Code: [Select]
hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1);  -- ports output 1
mc.mcSignalSetState(hsig, 0); --sets OUTPUT_1 to false

waiting for input, function really needs to go at top near variable declarations
Code: [Select]
function Input2IsFalse ()
    hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2);  --set hsig variable to handle input 2
    sigState = mc.mcSignalGetState(hsig);
    if sigState == 1 then
        return false;
    else
        return true;
    end
end --Input2IsFalse

while Input2IsFalse() do
--nothing
end  --waits until input2 is true

activate output 2
Code: [Select]
hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2);
mc.mcSignalSetState(hsig, 1);

DRO... I haven't figured out how to edit screen elements yet.  



Message:
Code: [Select]
mc.mcCntlSetLastError(inst, "ready to go");


10
Mach4 General Discussion / Re: Probing with G31
« on: April 23, 2015, 07:52:58 PM »
Ok, I'll stop going crazy then and build a small interface.  Thanks!

Pages: 1 2 »