Mach 4 lua capabilities

I’m going to start working through porting my mach 3 macros over to mach 4. I use the 2010 screenset and the m6 macro is the only thing I want from it in mach 4, everything else I’ve made should be easy to do.
In the setup portion of the m6 macro you first measure the z height of the stock and then the bit moves over to a fixed position and records the difference between the two and does that.
When m6 is called during a job, the spindle stops and moves to the tool change position. Swap tools and then moves to the permanent plate to touch. Recall the saved difference between the plates and use that variable to set the new tools height.

I’ve never used lua but it looks much better than vb. At least it looks more like what I expect to be a programming language.

I’m sure it’s possible to do this setup but are variables able to be stored long term and then recalled for a macro later on? I found some videos from 7 years ago about an m6 macro that almost does this except that it doesn’t seem to to the setup portion that allows you to use 2 plates. One moveable and one fixed to get the difference variable stored. It seems to only use 1 fixed plate and I need to use the surface of the material as the first touch position.

You can store values in a “register” in Mach 4. Basically scripts can drop values in there and other scripts (or the same one) can recall that value later and even do things like do math on it.

I’m not really an expert but that should get you something to do some research on.

1 Like

That’s what I needed to know. Thanks. I’ll play around until it makes sense

1 Like

Let me know how it goes. I’ve been doing some lua hacking/learning myself for fun. I’ve actually been working on an M6 script too that works in a similar way.

For sure. If I get somewhere with it, I’ll post it all. The window editor is better in mach4 for sure. It still has some terrible aspects to it though. Touchy and no undo action either.
Having that manual m6 macro is one of the best things for my setup. Being able to load a file with all operations and knowing I’ll get through it without being off on cuts is reassuring.

I also created a rotary touch setup when using my rotary in mach3 that I’ll have to make again. It allows you to mount a rod. Probe both sides by stepping over the rod and setting the center as y0. Then mount the material to touch off and know you’re on the spot. M6 setup then does the same routine to get tool changes working. With rotary I never end up with my original material touch position and changing tools without that m6 setup is much harder.

I’m pretty certain we automated all of this for rotary in Mach 4. Before you embark on building something yourself for rotary check out what we have done.

Ok. That’s good to hear. I will look at that and hopefully it works with my custom one.

The thing to remember is Lua will NOT stop executing when you hit the e-stop.

It will continue to run to the end of the script unless you poll that signal and self terminate.

Huge difference between Mach3 and Mach4 scripting.

Wow, ok. Interesting. So poll every step just in case of errors? That would also mean that if you give it a coordinate to move to and it’s in the middle of that movement it doesn’t stop on estop?

I’ll have to get some basic things working and think through safety before trying too many things. I would hate to crash while testing and break something

No, the Mach4 core will stop but things like scripts for tool changes will suddenly execute all the way through with lightening speed.

Since you have an ATC and if you don’t do the checks then all of the moves will return with no errors. Thus to the script the tool change was successful.

Now you have the wrong tool in the spindle.

Also, if you are actuating the draw bar then when you hit the e-stop or stop button during a tool change the stupid thing will just drop your tool. :roll_eyes:

Sounds fun. I don’t have an atc myself. That would be awesome but the cost needs to go into building my shop instead.

I’m just trying to create an m6 that allows you to manually change and touch off a permanent location to determine the difference and then start the next section.

So could you build in checks at each step and then exit the script if it reads that the app has occurred?

It just wants to play fetch

1 Like

Yeah, and sadly Lua is an engine that just makes the C/C++ objects available, no exception handling or anything like what you get with a professional developer language like VB, Java or Rust.

So you have to ask for the error codes back and check if they are positive and then if not check what they mean from a table.

Then you have to check the signal if you didn’t get an error code back. Then you perform whatever you need for that signal. So if you do it right it’s;

  1. Ask for signal handle
  2. Check the error code to make sure you got the handle for the signal
  3. Ask for the signal state using the handle
  4. Check if you got an error code
  5. If not act on the signal state you got back

So some signals are not available on e-stop or Cycle Stop and will give you an error when you ask for it YAY!

Some will not error out but will tell you when things are not moving for some reason and you should stop (aka, cycle pause).:roll_eyes:

Blah, blah, blah… I really hate the scripting interface to be honest. But from what I have learned is the guy who knew it and coded it left and they can’t find anybody to fix the bugs in the system.

I open bugs and they (newfangled) just closes them. They won’t even comment on them. Very frustrating.

When I asked for the full plugin API they said they only offer that to companies writing motion controllers. I said COOL! I am a company writing motion controllers… They never answer me back.

ModBus is also broken and they will just close your ticket if you file one. No response, no comment. So in ModBus you DO NOT have floats or 32 bit INTs.

Can you tell I am less than pleased with Newfangled?

Oh! You have to do the get signal, check loop for each signal so like cycle stop, cycle pause, e-stop are all separate. You have to do all three to find out if the machine is truly stopped.

Lastly, cycle pause? :rofl: You can’t pause a Lua script… Just throw the e-stop and die. I guess you could also just disable the pause button during scripts…

Wow. I was reading through the lua programming guide from them and started thinking about being able to make some robust things. Then you just say that it actually doesn’t, cleanly at least.

Crazy that they can’t find a dev capable but maybe the code base is huge and not documented. Nobody wants to take on that mess these days.

Modbus was always something I wanted to work with because of interfacing different devices capable of handling many complex external procedures and returning to do work internally again. I can think of many things that would be great for. Many pneumatic systems for holding in different areas at different times. Interfacing with robot arms for material handling. Anything really.

Did they already give up on this software after they made this replacement? They abandoned mach 3 because it’s easy to steal. Now they do the same with this. I wonder if management there isn’t anyone wants to work with.

I would imagine that more is exposed via Lua than was VB. The very little VB I have ever done with Mach3 was very basic.

In that Lua guide you will find the very page the developer was fired on :roll_eyes:

And I am not kidding about that. See if you can find it :wink:

RUMOR (as in might not be a shred of truth) has it the dude writing v4 got crapped on my management. He told them to toss off and left.

He had a cross platform core finished and was in the final stages of building the UI. So there would have been a Linux and a Mac version (if you read far enough in the docs you will find these references so that part IS NOT rumor). After he left , the owners (who apparently are not coders themselves) couldn’t find competent help for what they were paying the guy who left. They had hired people to fix Mach3 after that original guy left for exactly the same reason. This guy on Mach4 was their best guy for fixing Mach3. But they sat on him too and so he left. The next people in (and its a rovling door now) are clueless.

Well, with so many open source variations of controller software out there now, they will not catch up.
With a $4 microcontroller and a $60 open source breakout board I get great motion on other devices I’ve built. On top of that I can interface with the hardware in any way I can think of. Web interfaces for ui that are infinitely configurable too. Just controlling a laser I built and a sand table with 2 axis in my living room. The sand table has an interface I built so that visitors can draw with their fingers on a tablet and it outputs gcode to draw their drawings.

Not giving api access to everyone is insane. What the community would build for them for free or sell themselves to extend the capabilities without any output on their end could make licenses sell themselves.
Sometimes it’s hard to understand the thinking of management types. Maybe a lack of imagination or an understanding of what communities that build themselves on a software as a platform can do for the company without work on their end.

I wonder if the access to code for controller manufacturers means they literally get the entire codebase to work with. Instead of a proper API with core access.

1 Like

I cut a PCB on my Bantam for 3 RP2040 and a Whiznet 5500. The PIO pin control is much higher frequency capable than anything that FPG Warp9Ltd uses for the ESS. And its less than $2 per chip in singles. That FPG is every bit of $99 per chip in reals.

Total cost of replacing the ESS is $15 and I would be making money on that :stuck_out_tongue:

All of my other 6 machines are LinuxCNC and so will my AvidCNC PRO60120 be sooner than later.

BUT! Gotta finish the dern carousel first :frowning:

They don’t code! Problem #1. And their entire product is code.

They depend on others so they flap around in the wind like a old pair of underwear on a flag pole.

If you are a business owner and a coder then you have a passion for it and you treat your product differently (aka you actually OWN it). These people are holding onto something that have no control over at the end of the day. They can’t let it escape their clasp or they wake up tomorrow and have nothing.

Nope, just the header file. Which I could reverse engineer to be honest but why support these turds?

1 Like

Are you building these boards on your own design or something available already? I’ve not used Linux CNC myself but I’m sure I can learn.

Are you currently running your avid setup on this board?

Getting boards made with surface mount components and tested is pretty cheap now. I wouldn’t mind owning the whole chain capability for fun and maybe profit. A pick n place costs so little to make now.

Oh, I cut my own PCB in-house!

But like my other stuff, when it goes into production I find an ITAR house in the USA and contract them to do it.

But, yes I have the first iteration of the board. It comes in as Ethernet (Whiznet 5500) and the the first RP2040 breaks it up to the other two chips. Each of the 3 RP2040s then control one parallel port each. Your ESS is 3 parallel port emulator.

The PIO API that Raspberry Pi offers is really, really cool because it put zero time on the MCU, so you get parallel port pin IO for free.

That part is done! Took 2 hours in Eagle CAD / Fusion. Took about 2 hours to cut, mask and reflow the components.

Probably will take me the next 2 years writing the LinuxCNC driver :rofl:

Carousel FIRST! Too many pokers in the fire.

Besides! Do you would want vibration / ringing reduction first or is Mach4 bothering you that bad? :wink: