Hello Guest it is March 28, 2024, 08:10:10 AM

Author Topic: Mach 4 CNC Controller Build and asking for LUA scripting help  (Read 1719 times)

0 Members and 1 Guest are viewing this topic.

Mach 4 CNC Controller Build and asking for LUA scripting help
« on: February 04, 2019, 12:12:15 PM »
Note: If this is a double post, I'm sorry. Something happened while uploading this the first time and I don't believe it actually posted.

Hi All,

I am nearing completion of a CNC mill upgrade using AB Ultra 3000 servo drives and migrating from Mach 3 to Mach 4. I have a number of thing I hope to accomplish and I am asking for resources or advice on where to find information on them. See the attached image of the control panel.

1) Basic Mach 4 configuration: I feel pretty good on setting up the Smoothstepper and configuring basic I/O. I have a working test setup in Mach 3 so matching settings shouldn't be too terrible.

2) Basic Servo enable logic: I would like to add buttons to the screen to separately enable the motion axes and servo spindle using digital outputs. I have watched as much as I could on the screen editor and feel pretty solid on this, however I haven't yet gotten to the point where I feel comfortable using LUA to set outputs using on screen buttons. I knew Mach 3 VBS very well, but this is a whole new adventure! Any links to sample code would be greatly appreciated.

3) Basic power drawbar control: I have a pushbutton on the machine which I will need to link to a pair of outputs for drawbar release and clamp. I'm assuming this will be a very similar script to #2 except it adds a timer.

4)I have 3 separate "ESTOP" type inputs (normal system ESTOP, excessive cabinet temperature, DC supply or contactor failure). I'd like them all to stop the machine, but have custom messages for each type of input.

5) Pendant interface: I have a MPG which I'd like to set up as my primary method of jogging the machine. I have no clue if this is native functionality to Mach 4 or if scripting is required for each function. Advice or examples would be wonderful here.

6) RS485 ASCII to drives: Here is where I think things will get complicated   ;) . I am controlling all of the servo axes using step/direction or quaderature outputs from the Smoothstepper. That will get just about everything working by itself, however the Ultra 3000 drives I am using have an amazing feature set that is available through serial communication. I have tested these features and find they work very very well. For anyone interested, here is a link to the manual that shows all the settings and data available over serial (https://literature.rockwellautomation.com/idc/groups/literature/documents/rm/2098-rm003_-en-p.pdf).

In order to access this data, I will need a LUA script to write ASCII data over my computer's embedded serial port. I have seen a small handful of people posting about trying to use LUARS232 package/module, however never anything definitively successful. I am hoping to work with everyone on this wonderful forum to get this working. If I can, here are some of the things I will be able to do:
  • Absolute homing using encoder position data stored in the drive. I may never need to home to a switch again!
  • Real time motor load monitoring
  • Drive diagnostics like temperature, amperage, voltage, etc.
  • Reading fault codes and displaying them in a user readable format in Mach
  • A ton more that I haven't yet thought of!

I will be so grateful for anyone who has experience with any of these things to share their knowledge. I will continue to post updates on this build as I go along, as well as answer any questions there might be. My day job is designing industrial control systems, so I have a ton of electrical panel, PLC, and software experience (just not with Mach 4... yet).

Thanks,

-Mike
« Last Edit: February 04, 2019, 12:14:29 PM by mcardoso »
Re: Mach 4 CNC Controller Build and asking for LUA scripting help
« Reply #1 on: February 04, 2019, 12:19:16 PM »
Also for anyone who is interested, this panel will be setup on a G0704 for the time being, however is was built with growth in mind, so the panel should be easy to hook up to a much larger machine if I outgrow this one.
Re: Mach 4 CNC Controller Build and asking for LUA scripting help
« Reply #2 on: February 05, 2019, 01:37:35 AM »
Hi,

2)....no trouble. You can use buttons or you can stagger the enable signals to each axis, I only learned of this feature
a few days ago.

https://www.machsupport.com/forum/index.php?topic=39375.msg264520#msg264520

3)....no trouble

4)....no trouble but I would have one Estop, the usual and conventional emergency stop button. You can have other triggers
such as overtemp, overvoltage etc each with their own messages but should still be 'additional' to the absolutely basic and
reliable Estop.

5)....The ESS handles MPGs no trouble. You will have to add a lot of buttons and/or rotary switches to come close to most
pendants. I use a VistaCNC pendant and I couldn't possibly make one that does as good a job for the money. You might like
to check out Daz-the-Gaz's Xbox plugin, I suspect it will give you results that would take you hundreds of hours work just
to match let alone exceed.

https://www.machsupport.com/forum/index.php?topic=33121.0

6)....That is ambitious. I have a Allen Bradley servo and drive and I too am absolutely gob-smacked at the flexibility
of the control software. Most of the functions you describe can be programmed into the drive and would be
reflected at a number of the programmable output pins. To have Mach communicate to the drive to reprogram the drive
is very ambitious. I myself just use the Rockwell setup software to program the drive and monitor the outputs I deem
necessary (output current, as I use my servo as a spindle drive).

I have encountered a quote from a novel I am reading at the moment......'Perfect is the mortal enemy of good enough'.
Over the years I have done just exactly that, tried to do something perfectly but declining to make the attempt because it was
beyond my means/skill/whatever and denied myself the chance of having a 'good enough solution'.

May I suggest working on 2), 3), 4) and 5) as eminently achievable and THEN chip away at 6). If you don't get 6) working
properly it still won't stop you from having a kick-anus machine with those servos!

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 CNC Controller Build and asking for LUA scripting help
« Reply #3 on: February 05, 2019, 08:43:37 AM »
Craig,

Thanks for the very detailed response! Your plan you laid out in the last paragraph is exactly where I am hoping to go with this. I need the power drawbar and enable signals, MPG would be incredibly useful, drives communications... mostly fun. I added all the wiring ahead of time so all that would be required in the future would be software configuration.

The separate axis enable and spindle enable signals would allow me to release the servo locked spindle to check the cutter or get a pin wrench on it. The link you sent looks like exactly like what I will need to do (unbinding the button script and throwing my own in). I can't imagine it would be hard to set an output from a button script.

For 3), are there native timers to LUA or do you need to build your own by incrementing a counter?

For 4), I will only have the single software ESTOP, so I should use my terminology correctly, but I have lots of inputs which should trigger a machine stop (requiring a reset) with a custom message.

On 5), I purchased a low cost MPG that has two rotary switches (axis select and resolution), an ESTOP which is wired into my ESTOP string, and the actual MPG. It was only $50 or so but it is pretty rugged. I already have all those input wired into the smoothstepper.

Even without any of the communications in 6), the servo drives will do exactly what they are meant to do. I never planned on relying on the communications. That being said if the simple statement "I can write the string 'abc' over the serial port from Mach 4" is true, then I have 100% confidence that I can make this communication work, and it would just be putting the data in the right place on the screen.


Thanks again for the quick response!
Re: Mach 4 CNC Controller Build and asking for LUA scripting help
« Reply #4 on: February 05, 2019, 06:34:51 PM »
Hi,

Quote
For 3), are there native timers to LUA or do you need to build your own by incrementing a counter?

wxTimer() is the function you are looking for. Try Daz-the-Gaz's video:

https://www.machsupport.com/forum/index.php?topic=32573.0

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach 4 CNC Controller Build and asking for LUA scripting help
« Reply #5 on: February 08, 2019, 09:53:46 AM »
Just a short update on this project. Control panel is wired and installed. Panel mount PC is installed. Servos are hooked up and running on an old Mach 3 test program. Next step will be to setup the PC for Mach 4 and start checking out the I/O.  Will be asking for help very soon!
« Last Edit: February 08, 2019, 09:55:52 AM by mcardoso »