554,132 active members*
3,861 visitors online*
Register for free
Login
Results 1 to 13 of 13
  1. #1
    Registered
    Join Date
    Jan 2018
    Posts
    106

    Mach4 Macro M6 weird behavior , Help plz!

    Hello group ! i am really puzzled with Mach4 M6 Macro

    Went forward following the AutoTool setter video on Youtube from Mach Support

    Pasted the coding who is provided in the video description into the M6 macro in my machine profile , did setup the tool changing position over my fixed plate and it goes down touching the fixed plate and sets the Tool lenght of every tools in the Tool Table

    Fine it works !!!




    Closing Mach4

    Now i want to change the M6 macro using the coding for Automated Tool Change in the Mach4 Docs Scripting Manual to make the automated tool change , wrote the tools locations in the ToolChangePositions.csv in the Modules folder and the ToolChangePositions.Lua is there , followed the Scripting Manual.

    I opened the ZeroBraneStudio and it cleared the debugging

    Attachment 473146



    i open Mach4 , Homing , type in the MDI M6T2 to change the tool and it does exactly the same thing it did from the script taken from the Mach Support AutoTool Setter .... Not at all doing what the ATC script written in M6 is supposed to do.



    closed Mach4 and went to see the M6 macro and it was the new code i saved ...



    open again Mach4 , tried M6 and does the same script from the Mach Support video , closed Mach



    Then i went to erase allll the coding into the M6 macro , saved , opened Mach and tried M6 and it still made the same movements , i had erased M6.mcc too , why would it react to the command if the macro M6 is empty in the Machine's profile? where is the M6 script hidden?



    Rebooted the computer and it still does the M6 AutoToolSet script from the Mach Support video....



    i am so pretty puzzled !! whats happening ! Help !

  2. #2
    Registered
    Join Date
    Jan 2018
    Posts
    106

    Re: Mach4 Macro M6 weird behavior , Help plz!

    this is weird !!!

    i have 3 profiles



    my Router had the ATC script
    my Plasma had the same ATC script
    the Mach4 Plasma example that i was not using had the Macro who was operating the simple touch down


    i renamed it other than M6



    Loaded my Router profile and tried M6T2 and it started the movement to the tool location ......... so now reading the correct script






    Why ????? Why was it reading the macro of a different profile ?????


    Mach4 is cool but a can of worms !

    now trying to change tools and it goes not perfect now ....

    Got CurrentTool2 in
    at Homed position
    write command M6T4
    It goes to the Tool2 position , goes down , release the Drawbar and back up would be a drop off tool good
    Then goes to T3 position and turns off the Drawbar relay but doesnt get back up
    The Current Tool is still #2 on the screen




    some work to be done on the script ....


    we can see some more action in the videos


    Current Tool #2 , asking for T3 , drops T2 and picks T3 not going up , Current Tool stays T2



    Current Tool #2 , asking for T1 in MDI , drops T2 and picks T3 again , not T1 , Current Tool stays T2





    And i noticed compared to Mach3 it doesnt reminds the coordinates when closing the Mach4 , it made me "Crash it" a bit . Even when homed , X-0 i closed Mach , opened it back , press Homing and X crashed himself because he was already just next to the stoppers












    now the Script is this






    ---modified by cncprint.blogspot.com
    ---Roman Batz 03.09.2019
    local inst = mc.mcGetInstance()
    package.path = wx.wxGetCwd() .. "\\Modules\\?.lua"

    if (package.loaded.ToolChangePositions == nil) then
    tcp = require "ToolChangePositions"
    end

    function m6()
    ------ Get and compare current and next tools ------
    local SelectedTool = mc.mcToolGetSelected(inst)
    local CurrentTool = mc.mcToolGetCurrent(inst)
    if (SelectedTool == CurrentTool) then
    mc.mcCntlSetLastError(inst, "Next tool = Current tool")
    do return end
    end

    ------ Get current machine state ------
    local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
    local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
    local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)

    ------ Get Position data for current tool ------
    ToolData = tcp.GetToolData(CurrentTool)
    if (ToolData ~= nil) then
    Num1 = ToolData.Tool_Number
    XPos1 = ToolData.X_Position
    YPos1 = ToolData.Y_Position
    ZPos1 = ToolData.Z_Position
    else
    mc.mcCntlEStop(inst)
    mc.mcCntlSetLastError(inst, "ERROR: Tool number out of range!")
    do return end
    end

    ------ Get position data for next tool ------
    ToolData = tcp.GetToolData(SelectedTool)
    if (ToolData ~= nil) then
    Num2 = ToolData.Tool_Number
    XPos2 = ToolData.X_Position
    YPos2 = ToolData.Y_Position
    ZPos2 = ToolData.Z_Position
    else
    mc.mcCntlEStop(inst)
    mc.mcCntlSetLastError(inst, "ERROR: Tool number out of range!")
    do return end
    end

    ------ Move to current tool change position ------
    local GCode = ""
    GCode = GCode .. "G00 G90 G53 Z0.0\n"
    GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos1, YPos1)
    GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1 + 1.0) -- Ab +1 mm über Ablagehöhe wird mit G01 verfahren, hier Wert einstellen.
    GCode = GCode .. string.format("G01 G90 G53 Z%.4f F15.0\n", ZPos1)
    mc.mcCntlGcodeExecuteWait(inst, GCode)

    ------ Release drawbar ------
    local DrawBarOut = mc.OSIG_OUTPUT4 -- Set your output in Mach4 here
    local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
    mc.mcSignalSetState(hsig, 1)

    ------ Move to next tool change position ------
    GCode = ""
    GCode = GCode .. "G00 G90 G53 Z0.0\n"
    GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2)
    GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos2 +1) -- Ab +1 mm Move over the storage height with G01, set the value here
    GCode = GCode .. string.format("G01 G90 G53 Z%.4f F250.0\n", ZPos2)
    mc.mcCntlGcodeExecuteWait(inst, GCode)

    ------ Clamp drawbar ------
    mc.mcSignalSetState(hsig,0)
    GCode = ""
    GCode = GCode .. "G04 P2000\n" --Wartezeit 2000 milisekunden, nur optional
    mc.mcCntlGcodeExecuteWait(inst, GCode)
    mc.mcSignalSetState(hsig1,0)
    ---------------- Here the script stops -----------------

    ------ Move to Safe Z UP & in front of last change position ------
    mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n") ------------------------ Not moving back up the Z
    mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Y200\n") --Drive here to a safe distance from the tool changer with X = last tool. before!
    ------ Reset state ------
    mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
    mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
    mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)

    ------ Set new tool ------
    mc.mcToolSetCurrent (inst, SelectedTool)
    mc.mcCntlSetLastError(inst, string.format("Tool change - Tool: %.0f", SelectedTool)) --------------- New Current Tool is not set , stays #2

    end

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



  3. #3
    Member
    Join Date
    Nov 2013
    Posts
    2017

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hi,
    why do you have a macro m6666?

    If you code an m6 in your gcode job Mach will search for the nominated macro, m6, not m6666 or any other name.

    You also need to understand how Mach searches for macros.

    In the first instance it searches for the macro in the macros folder of your current profile. If it does not find it there it will search up the file tree. If it does not find it anywhere
    in the file tree it will revert to its in-built macro, if there is one.

    So your description of Mach using the macro but from a different profile is because it could NOT find the macro in your current profile.

    Second issue you need to understand is that Mach lexical parser converts all text to lowercase, strips out leading zeros and whitespace. thus when you write:
    M 6
    Mach will in fact search for:
    m6.
    Mostly it will find the macro that you had in mind but you should get into the habit of writing all gcode and macros in lowercase, without leading zeros and without whitespace otherwise
    you will have troubles such as this, namely Mach not being able to find a particular macro because you named it funny.

    Craig

  4. #4
    Registered
    Join Date
    Jan 2018
    Posts
    106

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hello , the M6666 is the M6 script who was in another profile and when i renamed it to M6666 i did not delete it . When trying to use M6 with the profile i was using it actually was using the M6 in the other profile , for unknown reason !! Was not using the M6 in my profile Macro folder so it was very weird !


    i finally been able to make it work by erasing anything that have a M6 written anywhere and really used the script from the Scripting Manual and made it work now , the automatic tool change is now working ! i banged my head in my computer screen for two full days it was draining .....



    i also used the AutoToolSetter who is also a M6 ...... to populate the ToolOffsets Table and tried to just rename it M7 to be able to use it without killing the ATC script and seems like its working but it went pretty wonky , in some ways it behaves weird , im calling T2 while my Current Tool is T3 and it blocks by saying "Current tool == Selected tool so there is nothing to do" . sometimes it doesnt wanna cooperate and just setting it back to M6 it goes better ...

    its nerve racking .... But finally works now



    Now the script who works fine with the ATC is

    ---modified by cncprint.blogspot.com
    ---Roman Batz 03.09.2019
    local inst = mc.mcGetInstance()
    package.path = wx.wxGetCwd() .. "\\Modules\\?.lua"


    if (package.loaded.ToolChangePositions == nil) then
    tcp = require "ToolChangePositions"
    end


    function m6()
    ------ Get and compare current and next tools ------
    local SelectedTool = mc.mcToolGetSelected(inst)
    local CurrentTool = mc.mcToolGetCurrent(inst)
    if (SelectedTool == CurrentTool) then
    mc.mcCntlSetLastError(inst, "Next tool = Current tool")
    do return end
    end

    ------ Get current machine state ------
    local CurFeed = mc.mcCntlGetPoundVar(inst, 2134)
    local CurFeedMode = mc.mcCntlGetPoundVar(inst, 4001)
    local CurAbsMode = mc.mcCntlGetPoundVar(inst, 4003)

    ------ Get Position data for current tool ------
    ToolData = tcp.GetToolData(CurrentTool)
    if (ToolData ~= nil) then
    Num1 = ToolData.Tool_Number
    XPos1 = ToolData.X_Position
    YPos1 = ToolData.Y_Position
    ZPos1 = ToolData.Z_Position
    else
    mc.mcCntlEStop(inst)
    mc.mcCntlSetLastError(inst, "ERROR: Tool number out of range!")
    do return end
    end

    ------ Get position data for next tool ------
    ToolData = tcp.GetToolData(SelectedTool)
    if (ToolData ~= nil) then
    Num2 = ToolData.Tool_Number
    XPos2 = ToolData.X_Position
    YPos2 = ToolData.Y_Position
    ZPos2 = ToolData.Z_Position
    else
    mc.mcCntlEStop(inst)
    mc.mcCntlSetLastError(inst, "ERROR: Tool number out of range!")
    do return end
    end

    ------ Move to current tool change position ------
    local GCode = ""
    GCode = GCode .. "G00 G90 G53 Z-60.0\n"
    GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos1, YPos1)
    GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1 + 1.0) -- Ab +1 mm über Ablagehöhe wird mit G01 verfahren, hier Wert einstellen.
    GCode = GCode .. string.format("G01 G90 G53 Z%.4f F250.0\n", ZPos1)
    mc.mcCntlGcodeExecuteWait(inst, GCode)


    ------ Release drawbar ------
    local DrawBarOut = mc.OSIG_OUTPUT4 -- Hier euren Output in Mach4 einstellen
    local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
    mc.mcSignalSetState(hsig, 1)

    ------ Move to next tool change position ------
    GCode = ""
    GCode = GCode .. "G00 G90 G53 Z-120.0\n"
    GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2)
    GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos2 +1) -- Ab +1 mm über Ablagehöhe wird mit G01 verfahren, hier Wert einstellen
    GCode = GCode .. string.format("G01 G90 G53 Z%.4f F250.0\n", ZPos2)
    mc.mcCntlGcodeExecuteWait(inst, GCode)

    ------ Clamp drawbar ------
    mc.mcSignalSetState(hsig, 0)

    ------ Move Z to home position ------
    mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z-60.0\n")

    ------ Reset state ------
    mc.mcCntlSetPoundVar(inst, 2134, CurFeed)
    mc.mcCntlSetPoundVar(inst, 4001, CurFeedMode)
    mc.mcCntlSetPoundVar(inst, 4003, CurAbsMode)

    ------ Set new tool ------
    mc.mcToolSetCurrent(inst, SelectedTool)
    mc.mcCntlSetLastError(inst, string.format("Tool change - Tool: %.0f", SelectedTool))

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

  5. #5
    Member
    Join Date
    Nov 2013
    Posts
    2017

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hi,

    the M6666 is the M6 script who was in another profile and when i renamed it to M6666 i did not delete it . When trying to use M6 with the profile i was using it actually was using the M6 in the other profile , for unknown reason !! Was not using the M6 in my profile Macro folder so it was very weird !
    As I tried telling you you must use 'm6'.....NOT 'M6', Mach uses all lowercase. It will produce some odd faults that are very hard to spot if you use uppercase, I know because I've been caught out exactly the same way.

    Craig

  6. #6
    Member
    Join Date
    Nov 2013
    Posts
    2017

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hi,
    another thing that is worth considering is that when you create a macro it will be named m6.mcs for instance. The .mcs is Lua source code and once its compiled it becomes m6.mcc which
    signifies the compiled file. Often only the .mcs file is listed by Windows as being the only human readable version, disguising the fact that there is a second file, which Mach can and will
    use if it gets the chance.

    If you are deleting a macro delete both files.

    Sometimes if you edit a source file the edits will not be compiled so the source file, ie the one you expect Mach to use, is different to the .mcc file it actually uses. Suggestion is to
    delete the .mcc file and therefore Mach will compile a fresh file and will use the latest edits in the source file.

    Craig

  7. #7
    Registered
    Join Date
    Jan 2018
    Posts
    106

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Well , i am not writing in the editor upper cases but when pointing out something when writing a text i like to put a upper case to make it noticeable when reading


    I learned about the .mcc sometimes i was editing some things and didnt really work when just saving and kinda got me turn in a circle and then at some point , recompiled and the things i played around with appeared and ****ed me up . Some things work , some dont when not deleted the .mcc ....

    Now i delete it most of the time i edit something and it helps me going forward . It's my first time with Lua , i just migrate from Mach3 to 4 since last week


    Oh! i just found the Compile button in the editor or just F7 as a keyboard shortcut , will use it all the time now !

  8. #8
    Member
    Join Date
    Nov 2013
    Posts
    2017

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hi,
    but when pointing out something when writing a text i like to put a upper case to make it noticeable when reading
    I understand and do the same thing, but the best policy for minimum confusion is to write exactly as you would code it.

    Now i delete it most of the time i edit something and it helps me going forward . It's my first time with Lua , i just migrate from Mach3 to 4 since last week
    Lua is quite a learning curve, but well worth it, it's so much more flexible and stable the Visual Basic in mach3.

    Craig

  9. #9
    Registered
    Join Date
    Jan 2018
    Posts
    106

    Re: Mach4 Macro M6 weird behavior , Help plz!

    i am still wondering how to just write another line to just tell the machine to "Go there" lol , i am so getting lost in coding

    what the hell are these things hahah

    GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2)

    mc.mcCntlGcodeExecuteWait(inst, GCode)

  10. #10
    Junior Member
    Join Date
    Jul 2013
    Posts
    16

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Quote Originally Posted by joeavaerage View Post
    Hi,


    I understand and do the same thing, but the best policy for minimum confusion is to write exactly as you would code it.



    Lua is quite a learning curve, but well worth it, it's so much more flexible and stable the Visual Basic in mach3.

    Craig
    That said, it was a strange choice of language to use and NOT the best by far. Not quite as bad as Python, but a close second.

  11. #11
    Member
    Join Date
    Nov 2013
    Posts
    2017

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hi,

    That said, it was a strange choice of language to use and NOT the best by far
    Initially I was tempted to agree but have come to realise Lua has certain advantages that many other supposedly better languages lack.
    Smurph, one of the leading developers of Mach4 has said that 'Lua has a syntax that only a mother could love'. So even Smurph regards
    the language as somewhat syntactically challenging....but...it has some distinct advantages:

    Firstly Lua is fast, very fast, for a scripting language, an order of magnitude faster than Python say.
    Secondly Lua is very lightweight, ie the C code that IS Lua is very small indeed, something like one tenth the code burden of Javascript for instance.

    A classic example of this is the string manipulation functions. In Javascript the string functions are fully POSIX compliant and require about 5M of code.
    Lua string functions on the other hand appear somewhat limited but can in fact execute all POSIX string functions but requires less than 100k of code.

    Lua can be written to accommodate a number of different paradigms, I mostly use straight out procedural code, but Lua can be pushed into object and functional
    oriented code. Once you get your head around the table structure and you realise how easy it is to code a state machine for example you'll come to appreciate
    that what looks to be so simple and lightweight can yet be SO flexible.

    I suppose the other point is that Mach4 is a CNC software solution. Lua was chosen to add the scripting ability so that users could customise Mach4 to their needs,
    but is still only a CNC solution. Its not a software development environment....if you want to develop software then of course there are better choices than Lua....but Lua
    is NOT for developing software but rather for adding a fast, lightweight, flexible scripting language to add to Machs code base. Lua does that well.

    Craig

  12. #12
    Junior Member
    Join Date
    Jul 2013
    Posts
    16

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Quote Originally Posted by joeavaerage View Post
    Hi,



    Initially I was tempted to agree but have come to realise Lua has certain advantages that many other supposedly better languages lack.
    Smurph, one of the leading developers of Mach4 has said that 'Lua has a syntax that only a mother could love'. So even Smurph regards
    the language as somewhat syntactically challenging....but...it has some distinct advantages:

    Firstly Lua is fast, very fast, for a scripting language, an order of magnitude faster than Python say.
    Secondly Lua is very lightweight, ie the C code that IS Lua is very small indeed, something like one tenth the code burden of Javascript for instance.

    A classic example of this is the string manipulation functions. In Javascript the string functions are fully POSIX compliant and require about 5M of code.
    Lua string functions on the other hand appear somewhat limited but can in fact execute all POSIX string functions but requires less than 100k of code.

    Lua can be written to accommodate a number of different paradigms, I mostly use straight out procedural code, but Lua can be pushed into object and functional
    oriented code. Once you get your head around the table structure and you realise how easy it is to code a state machine for example you'll come to appreciate
    that what looks to be so simple and lightweight can yet be SO flexible.

    I suppose the other point is that Mach4 is a CNC software solution. Lua was chosen to add the scripting ability so that users could customise Mach4 to their needs,
    but is still only a CNC solution. Its not a software development environment....if you want to develop software then of course there are better choices than Lua....but Lua
    is NOT for developing software but rather for adding a fast, lightweight, flexible scripting language to add to Machs code base. Lua does that well.

    Craig
    Honestly i think it is the way the language is used in Mach4 that winds me up. For example the developers seem unable to to use a Boolean (True, False), which is the buidling block of even the most basic compter languages.

    Mach4 Lua Screen Load Script:
    machEnabled = 0
    machWasEnabled = 0

    Why not
    machEnabled = false
    machWasEnabled = false

    and all the way through the scipting they seem to have a huge aversion to using boolean vars.

    Then things like in the example turret change script.

    functionm6()
    ------Getandcomparenextandcurrenttools------
    localSelectedTool=mc.mcToolGetSelected(inst)
    localCurrentTool=mc.mcToolGetCurrent(inst)
    if(SelectedTool==CurrentTool)then
    mc.mcCntlSetLastError(inst,"Nexttool=Currenttool")
    doreturnend <--------------
    end

    It's a simple function, so why does the scope of the return command have to be change/isolated? Issue a return command in a function, the it exits the function. Obviously I understand that if the scope of a section of code in that function had been had been reduced by a do ... end then it could have effect on the scope of the return command, but in this instance it is just not necessary. Well if it is then the developers should explain why.

    All in all Mach4 has been a great disapointment, having to learn another programming langauge to get it to function in a basic manner is frankly ridiculous.

    Then if you have a Motion Controller you can't use a dev machine to program the LUA code and you have to stand at the machine to develop.

    Then theres plugins... which are touted and being available and easy to use/program... they are not. You are not actually able to add your own Plugins. It seems Plugins and there mysterious workings have been restricted to a couple of hand picked users on the forums. e.g. The DazTheGaz Lua XBox360 doesn't work properly on Win7, ok I'll just write my own Plugin and make sure it woks... nope. Voodoo witch-doctor says no go.

    I dunno



  13. #13
    Member
    Join Date
    Nov 2013
    Posts
    2017

    Re: Mach4 Macro M6 weird behavior , Help plz!

    Hi,

    For example the developers seem unable to to use a Boolean (True, False), which is the buidling block of even the most basic compter languages.
    Lua is type free, all variables are numbers (in a table) but can be interpreted as numbers OR text. There is no Boolean variable type in Lua. Its exactly that sort of simplicity
    that allows Lua to run as fast as it does and have such a low code burden. Fast and lightweight trumps your user preference for Booleans. Lua is not so much a computer
    language but rather a scripting tool, so you don't have to write C/C++ which is highly typed and requires you manage memory. Lua is (nearly) type free and is self memory managed,
    a vastly simpler proposition to C/C++

    having to learn another programming langauge to get it to function in a basic manner is frankly ridiculous.
    Mach4 is ready to go out of the box for any standard 3 or 4 axis mill/router. You might want to enable a feature or turn another off but there is no need to program anything.

    You are not actually able to add your own Plugins. It seems Plugins and there mysterious workings have been restricted to a couple of hand picked users on the forums.
    To write a plugin, and anyone may if they wish, but will require that you sign a N(on) D(isclosure)A(ggreement) with New Fangled Solutions because you will require access to sensitive
    intellectual property. Would you not expect a commercial software company to so protect their IP? If you want to write a plugin then have at it. The vast majority of users seem to think that
    they have to do so but in fact Lua scripting can achieve all that they require....so there is no need to delve into C/C++ plugins.

    Craig

Similar Threads

  1. odd stalling behavior - CRP pro 48x48 with mach4
    By Fabrik8r_K in forum Avid CNC
    Replies: 5
    Last Post: 08-03-2018, 05:27 PM
  2. Getting weird machine movement/behavior
    By Kosh in forum Avid CNC
    Replies: 8
    Last Post: 06-22-2016, 01:46 AM
  3. 4th axis weird behavior
    By Gerry Kmack in forum Tormach Personal CNC Mill
    Replies: 3
    Last Post: 01-24-2016, 09:37 PM
  4. Weird behavior and crashes...
    By subnoize in forum MadCAM
    Replies: 15
    Last Post: 07-14-2014, 10:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •