Mach 4 lua capabilities

it is mach4corAPI.chm Why that is not in the help dropdown, who knows. thank you. I could not even find the reference. I was looking for any sort of help file referencing c/c++ or anything. This entire system is much too cryptic. I will scratch my eyes out once I get this working. I will deal until then.

i think i found it. this is exactly the doc i needed. mcaxissetposition. i know theres more to work out. now it might actually get finished. i have given up a few times and keep coming back. i will get it eventually.

Mach4CoreAPI.pdf (4.1 MB)

I converted it to PDF. In case someone wants it, I attached here.

1 Like

This might be a better Lua UI system. that wxWidget stuff is for the :bird:s

https://luapower.com/ui

For sure, dealing with that interface is a pain. I can deal with it for now. I may get into making a great looking interface for things as long as I can get other stuff working well.

That being said, mcAxisSetPosition is the thing needed to inject the calculated offset for what I am working on. I tested it in simulation mode. Whatever offset you are working within will get the input. You just have to assign the axis to put the number into. It has to be by number. In the sim it is axis 2. Probably axis 2 on my machine as well.

Now I need to work out some logic for shorter vs longer tools and then probing setup as well as finishing m6 to put in the value. I have recalling and storing registers and basic calculations not. Just for getting numbers moved around to test with.

I am actually getting close, i think. We will see soon enough.

How could you call this script during m6? When attempting to integrate what I’ve built into m6, I had to create all the functions to pull in and write registers. I can’t access the global things within the macro.
I’m not using yours, just wondering how that is done normally by people. I can add all the functions needed but, I’m sure there’s a better method.

Ok, I watched the missing mach 4 programming video again and now things make some more sense.
I assume I’ll have to write an mcodes that has a bunch of functions needed to match what is available to the screens. Then use registers to make sure that the values are able to be pulled in either without mismatching.

I was attempting to use the function from avid for the stored mtc location in my m6. Since it’s a button script that is recalling values from another script that stores that location, I’ll have to copy the function from their code and put it within my macro to read the values outside of screen.

I assume that this also means I can take advantage of their probing code in a similar way. My first testing days ago with attempting to probe fast and then slow failed. It just skipped over the second section of probing and used the first value it received. It seems I have to do something other than straight probe. I do recall seeing something else that seemed to loop until a signal activated.

I would not use Avid’s scripts. They won’t tell you when they change things and that can be an expensive mistake.

The registers are where you store values. That is not just how you persist variables but also how Modbus passes numeric values.

You can make modules and call them which will keep your code much cleaner and make reuse easier.

All of my code starts life as an m code because it’s easy but migrates to modules. The m-codes will all call the modules because it keeps them and the UI scripts lean and uncomplicated.

Oh gosh, no! Remember that the Lua engine is disconnected from the Mach4 core. You will never get a signal and be able to act on it in enough time to not damage your machine.

You will depend on the ESS to stop the machine and then you read the state to see if it errored out or it tripped.

I will check back in tomorrow because I got to your post here at 2am.

I apologize if I misread what you wrote.

Ok. I will not use avids code and keep mine separate. Getting deeper into this and it just seems to get more complicated. I’ll have to read up on lua in hopes that it helps me understand what is happening half the time.

I keep seeing different scripts people have made referencing things I just can’t find definitions for. Obviously there is structure and use definitions in the scripting help file but, no idea what they can access half the time.
The pound variable grabs some number that defines something. No idea how you can know what it grabs though.

When talking about the loop I was referring to what seemed to wait for the signal from the ess to write somewhere and then check that. Is it not looping and waiting for that signal? Is it instead telling the machine to move and then it moves until ess stops the move and then checks for that as an error?

So I found a list online of the enums available, at least it is some of them. Most of them seem to spell out what they are. There is an amazing amount of disparate information spread across the internet. Once I compile all of the information together in one place and make a functioning tool change script, I am going to put this in my github so that someone might not just give up when they cannot find anything.

Well, this video just explained so much to me about evening in looking for. Now I finally understand where the probing routines get the values and how to deal with them. I was confused by the code always waiting for an error from ess. It finally makes sense.
DasTheGas seems to have about 5 or so hours of stuff to watch before you stumble on answers.

It isn’t easier to find answers using all the old forums though.

So, I’ve been at it today creating two separate scripts. One for setup using the when and another for m6.
I do not want to test this in my machine before more debugging. So, my second computer is in simulation. What I can’t figure out is how to access the ess registers in simulation mode. Is there a way to do this without testing on my real setup?

Yep, you beg Newfangled until they drop crumbs. They have a small cadre they leak knowledge to like dazthagaz and a few others. If you think about it or take it personally it will mess with your ability to enjoy the tool you have. Just make lots of friends and learn from others the best you can.

Now that IS in the Mach4 Core API doc. Its under signals somewhere. I find it and then I forget where and have to repeat the journey every 3 or 4 months.

Nope, you do a wait on a signal like this;

rc = mc.mcSignalWait(inst, mc.ISIG_INPUT50, mc.WAIT_MODE_LOW, seconds)
if(rc ~= 0) then
	print("Error while waiting for tool sensor carriage response")
	return false
end

The code above waits so many seconds for that signal to go low or rc is an error code.

On the probing, yes. You give it a command to move so far and then the next line you check if it hit anything or if it gave you an error. That is because the gcode execution is blocking. When your code resumes (the very next line) either the ESS has blown up or the probe has a result.

NOW! Be aware that Warp9ltd and Newfangled have differing opinions on how things should report during probing. I think we have already talked about this but I will mention this here again just in case. The ESS is set up to FAIL (throws the e-stop for you) when a probe command completes WITH NO STRIKE. Another way of saying this is if it completes the move and did not contact something ESS considers this to be an error.

On the other hand, Newfangled DOES NOT throw an error and in fact uses this as a method to “safely move around the space” without breaking the probe.

My take on this is both are wrong. Using G38.x is far superior because you have move to “touch” and move to “untouch.” You can also set the work offset using gcode (for example G10 L20 P1 Z1.52).

The LinuxCNC folks and all of the derivatives like Grbl, Marlin etc all have those features. So your cheapo 40 watt laser diode machine has it but not your sad little Mach4 box :rofl:

Yep, and nobody will read it. Not that it isn’t cool but that everyone has the “better idea.”

There are a billion such github projects. All of them abandoned… mine included :grin:

April is my date for getting things released.

Thank you for so much feedback. It really is helping.
It is funny how many inexpensive controllers I have that have insane amounts of documentation and capabilities. With Marlin I can basically create anything I want. Including custom hardware to do tasks triggered by whatever random thing I feel like using and add long as there are ways to send and receive different signals. I could use mqtt if I wanted.

One more thing, do you know of a way to simulate the setup on another computer and get signals simulated from the ess? If not, I just have to test on my real setup and hope I get it right before throwing around the tool head

It’s not possible. Just have to run the machine with motors off and manually trigger to test

And now I’m actually testing on the machine and finally understand what you meant by it being unresponsive during these moves. I still want to get this working this way, since I’m very close.

Building a module would be the next attempt after refining everything I have now. I started going into that with basic things to test. It’s as confusing as I expected.

I don’t know of anything that would allow you to simulate a real machine with Mach4.

Newfangled wouldn’t license me their API for plugins despite their claims it’s for writing motion controllers. To which my carousel apparently isn’t worthy (which is why it now supports ModBus, fudge them and the donkey they rode into town on).

I do a fair amount of work with my carousel controller and Mach4 on my laptop. I just wait for the ESS to time out and then the ModBus comes up and I can see signals and polling just fine.

I also use RDP to my actual CNC PC and use a camera to view what is happening and then I can sit back in the comfort of my office and code.

Like you said, I have 6 CNC machines and many controller for more of them. All of them have better documentation and the developers for all of them will respond and help you with just about anything.

I truly believe that the owners of Newfangled not only do not code but they are ignorant of their own product.

I attempted messing with modbus on mach3. I figured that could extend to anything with signals. That does make sense you would use it. I’m not there yet.

I assume you just use wifi to remote in. I have my win10 machine at 1607ltsc and everything possible turned off. That was mainly because windows update is insanely chatty. I used to run a kvm between my desk and the shop.

It did freak me out the first time I ran the code with motors on. However, it all worked, mostly. No crashing.

I’ll just have to deal with no feedback until the step is done and make sure it cannot crash unless something real dumb happens.

I use Windows 11 Pro and inhibit updates. So I can be on both wired and wifi. With Winderz Pro you can set it to delay updated by 1 month and then you update it on your own time. Generally I either update before shutting down for the day on I do a Sunday systems check and get it then.

Give it time. Beginners luck :rofl:

I fly 3D RC helicopters and the difference between a wreck and a re-kit is milliseconds on the throttle hold. Its a switch that cuts the power to the main rotor. The quicker you cut that power the less damage the helicopter suffers during mishaps.

That training for the past 30 years has paid off more than once with my AvidCNC.

Here is a trick, while writing make it pause and wait for you to click the cycle start between each step. And do a print("describe what I am doing...") in the Lua code so you can can figure out where you mistakes are and it wont just run through when things go bad.

The print command will be visible in the History dialog so you can see what its doing from the screen as well as from the debugger.

While running the m6 itself, I get all the GUI feedback. Just the GUI button blocks.
I’ve inserted messages at every step along the way. Still not fun feeling when testing though. I do not like how it just locks up the system during it. When testing strictly on my main computer yesterday, I called something in the script. I was working on it remotely and it locked up the whole machine and disconnected me. Got home and it was still locked up. Had to hard restart to get back. I figured it was something that would work itself out before I got home. Nope.

It’s my design machine and mach doesn’t take much of it to run. 256gb ram. 3070 and amd 5950. Beast. I can’t believe you would run mach on windows 11 first off. I don’t even run windows 11 on any machine I want to use yet. Windows 10 is hard enough to calm down in the background. With everything Microsoft is doing with distributed updates across your local network, constant need and ad garbage and whatever random things want to run. I can’t believe your mach setup doesn’t randomly crash because of whatever is happening somewhere in the system. With mach3 you could crash because a USB device was plugged in. Moved your mouse too fast? Lose a bit.

That being said, I have both of my scripts working with motion and touching and recording positions.
Next is getting the math for tool change worked out. Because I’m changing z work offset accordingly, the value could be negative or positive. I’ll have to check for this and then do the correct math based off of that check. Hopefully I’ll have this done by the morning.