Hello Guest it is January 22, 2020, 09:03:50 PM

Author Topic: Lua  (Read 8469 times)

0 Members and 1 Guest are viewing this topic.

Offline CRS

*
  •  61 61
    • View Profile
Lua
« on: January 04, 2017, 11:54:54 PM »
Hi guys, my name is Craig, a boatbuilder in the middle of converting a small Hercus mill to Mach4.

I know Lua is not a new topic, but being new to forums, I don't really know how to go about asking.

Anyway, days I have spent trying to get my head around Lua.  I've read every thread I can find about Lua, watched every video etc., and done as many online tutes as my tolerance will allow.  My rule is, don't ask questions until I've put some time in and my head hurts.

I must say, I am out of my depth and my head really hurts.  I have a lot to ask, but for now just a couple of things which are eluding me.

Can someone enlighten me about what the "mc" that appears in front of mcLua and many other script lines actually means?  And what does API stand for?  Just those two things will stop me chasing my tail quite so much.

Thanks,

Craig
Re: Lua
« Reply #1 on: January 05, 2017, 01:15:32 AM »
Hi Craig,
I'm a newcomer to LUA myself and like you really struggled initially. While by no means fluent I'm getting there. Having got over
the hump I now find LUA to be superb.

API=Application Program Interface
mc.=Mach Core

LUA like all computer languages have variables which you can manipulate in any number of ways. For LUA to be useful to us we
need to be able to make it do things to our machine. Mach provides a whole bunch of functions which allow you to do that, collectively
called the API. On the 'Program Run' page with 'File Ops' in the lower notebook with Mach enabled there is a 'Help Docs?' button and in
there 'Mach4CoreAPI.chm' provides the complete list, aside from other manuals and lists. Its quite daunting to look at to start with.

Take a simple one to start with:
inst=mc.mcGetInstance()

The mc. means 'a function within Mach Core' and the function is mcGetInstance. Sometimes the mc. is referred to as a namespace
There are others and some I have a lot of trouble with for instance wx.  It refers to wxWidgets functions which are  graphical windows,
message boxes, dialogues and that sort of thing. Another one which crops up a lot is scr.  It addresses screen elements like buttons and LEDs.
While the Mach Core API is well documented some of the others are not, scr. for instance. wx. on the other hand is superbly documented
because it is so widely used by so many different languages, the downside is its so complete I can't usually make much sense of it, it takes
some serious 'nerdiness' to read.

I've found particularly with wx. I copy/edit examples of whats already been written, setting up frames, panels and event handlers from scratch
is not easy.

For basic LUA stuff I often have
https://www.lua.org/pil/contents.html
open on the desktop so I can dip into it at need.

The good news tho is that unless you have a particular need for something that you probably don't really need to write any code to convert
a machine, Mach4 is pretty complete for milling machines. Additionally if you do want something the chances are that someone has probably
got something pretty close you can copy/edit. There are some regular contributors, Daz-The-Gaz especially who is VERY well versed in LUA and
really goes out of his way to help newcomers.

Craig
My wife left with my best friend...
     and I miss him!

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #2 on: January 05, 2017, 02:38:33 AM »
Hi Craig, isn't that a coincident.  I will have a bit of trouble remembering that name...

I have to thank you so much for taking the time.  You have just answered something that has been bugging me.  I tend to go off on tangents until I get an answer to the silliest things, and now I have it, I can move on.

I look forward to getting over that hump you mentioned.  Currently I am bogged on the way up the pre hump side.  I have found many of the tutorials for dummies and beginners, start off well, nice and slow, and then they seem to jump a gear without a real explanation and leave me in the dust, it’s then I feel like I am back learning algebra.  Never did pass that.

To your credit, and maybe it comes from the fact that you have had the same brain numbing learning experience, your explanation has taught me more than I have gleaned from my scouring of the internet for a basic starting point.

Anyway, the main thing I want to achieve is to have my existing control panel (or a copy of) with all its buttons being able to send signals to Mach and on some of the illuminated buttons, like Cycle Start/Stop Feed Hold etc., receiving back the signal to light the bulb.  There are the jog buttons and the three MPGs.  The electronics, as it turns out, is the easy part.

I have done as you say and looked for scripts already written that I can copy.  DazTheGas is great isn’t he?  What a knowledge he seems to have.  I have managed to copy and implement those few line of the Cycle Start script, which is talked about in several places on the forum, and nearly wet myself from excitement when I got that to actually work with an external button onto my Pokeys 57E.

Hey this stuff is easy! (not really) And then I tried the same thing with Cycle Stop and Feed Hold.  NO JOY!  How the fatigue sets in fast when you get a negative response for about the tenth time.  I am sure you have never felt that….  So that is where I am at.  Totally confused and back to watching more videos.

Craig once again, thanks so much, I might go back and read your reply for about the eighteenth time now.
Craig.

Re: Lua
« Reply #3 on: January 05, 2017, 03:05:48 AM »
Hi Craig,
how many buttons does your control panel have?

If its a reasonable number say 5 or less then the simplest way would be to assign 5 pins as input to Mach and
assign 5 pins as outputs from Mach to turn on the lights. I'm not familiar with your controller but would guess you
have enuf inputs/outputs

There are more complicated ways (MODBUS) to do it where you can have dozens of inputs/outputs if you need them.

Craig
My wife left with my best friend...
     and I miss him!

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #4 on: January 05, 2017, 04:09:26 AM »
Hi Craig

I didn't expect a reply so fast.  Thanks!  Hey which part of the world are you in?

Re the ins and outs.  I am using the ESS together with the MB2 break out board from CNCRoom.  The MB2, which is in my control cabinet has 22 Inputs and I think 14 outputs as well as a built in Analog speed controller.  For the front panel with all its buttons and other stuff I have the PoKeys 57E, which has 55 terminals which can be assigned as inputs or outputs.

So I have way enough to handle all the I/O.  I will attach a pdf just so you can see my intent with the front panel.  Probably getting a bit greedy, but I have been using the mill a certain way up till now, and really want to keep up what I am used to.  I have added a bit more, must admit.

The MB2 will handle of the safety stuff, E-Stop, Drive Fault as well as Limits and Spindle and the PocKeys will take care of the multitude of things on the control panel.  I have that hooked up in test mode and pretty much configured, and to my surprise, they all talk to each other.

So this is why the need to keep on learning Lua.  I did come across one thread where the guy was doing roughly the same.  He had the Cycle Start going and was onto the other buttons.  You know, for the life of me, I can’t find it again.  Really dumb of me not to book mark it.  I have found similar, but not that one.

Craig.
Re: Lua
« Reply #5 on: January 05, 2017, 04:44:43 AM »
Hi Craig,
I live in New Zealand.

That's a pretty impressive control panel, without any multiplexing I got to 27 inputs without counting the MPGs or Overrides.

I would be having a close look at the number of input/output pairs you require. I to use the ESS and it has three ports. Lets assume
that the motors, limits and homes use one port, leaving two still to be assigned. Assume also that you configure pins 2-9 on both
ports as inputs for a total of 26 inputs (2-9+10-13+15 times 2) and 8 outputs (1+14+16-17 times 2). Without multiplexing not enuf.

The overrides as you have shown them are analogue so will have to be converted to digital signals and even as serial inputs will
require 1 pin per override without multiplexing. MPGs require two pins each.

I think you either have to rationalise your control panel or do some sort of MODBUS arrangement. Depends on what you want to do,
if your hobby is tinkering with electronics and software go MODBUS or similar, if you want to make things with your machine then
shagging around with MODBUS is going delay proceedings bigtime.

Craig
My wife left with my best friend...
     and I miss him!

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #6 on: January 05, 2017, 05:25:05 AM »
Ah ha, New Zealand, I have been there so many times.  Great country ah.  I’m not really sure how to spell ah...

Yes the question of inputs and outputs.  Having enough resources to handle it all.  But first to answer the other question about what I do with the machine.  The mill is actually a help for me to manufacture.  I cut moulds with it.  It functions well as is, although a huge pain.  I generate the tool path with Mastercam, then have to download it via the RS-232 port into the old ANCA control.

For one surfacing job, on one mould, on one side of the mould, I would normally do three to four separate downloads to get the job done.  About 12 to 14 thousand lines of code.  The old 1986 ANCA has a huge whopping 0.153mb (153kB) of memory free for me to use.  I know, I know, quite impressive hey...  So you can imagine why I am keen to get out of there.

Back to I/O.  The PoKeys connects to the PC via its own cat6 cable and as uneducated as I am with the whole Mach thing, it looked like, from Mach's point of view, when I go into the config Mach section, that there are plenty of inputs and outputs available.

I had the same question about the parallel port thing as well.  But from what I read on the Pokeys site and talking to my friend who is actually an electronics guys unlike me, and also has the ESS and PoKeys, it seems like Mach has the ability to accept all the inputs from the PoKeys as well as the ESS.  I think the MB2’s available I/O pretty much fills up what is available from the Parallel Ports, but when I look in Mach, there is something like sixty something available inputs.

Am I talking nonsense or is it possible?

The PoKeys also has I think 7 Analog inputs for use with Potentiometers or other analog devices.  Also heaps of encoder inputs to take care of the MPGs.

I am still trying to get a handle on all this, so now you have got me thinking about it, I best go off and re check.

Probably time for you to get to bed, being you are a couple of hours ahead of us here.

Craig.


Re: Lua
« Reply #7 on: January 05, 2017, 05:38:10 AM »
Hi Craig,
to my knowledge Mach4 can have one motion controller active at a time. I'm a very recent convert to M4 so what I say
is far from gospel. If I'm correct then a simple in/out pin pair arrangement won't work with ESS.

I am unfamiliar with the PoKeys board but sounds like your best bet particularly if it has analogue inputs.

Mach4 has plenty of in/out but you have to squeeze it thru your motion controller, I think that's going to be your
bottleneck.

Craig
My wife left with my best friend...
     and I miss him!
Re: Lua
« Reply #8 on: January 05, 2017, 06:06:32 AM »
Hi,
just had a look at the PoKeys 57 manual, pretty impressive.

From what I can gather you can have a total of 55 inputs or outputs, less one for each analogue input and less two
for every encoder. Haven't quite worked out how the digitised data gets communicated yet but guess its via Modbus registers.

If you can have more than one motion controller active you'll be fine.

Craig
My wife left with my best friend...
     and I miss him!

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #9 on: January 05, 2017, 07:00:36 AM »
Hey Craig, you are a worse night owl than I am.

That is a good point you make about not having two motion controllers active at the same time.  Maybe becasue I am only using the PoKeys as an interface then that isn’t an issue.

About a week ago I opened a ticket with the Mach support and explained that to increase the I/O I wanted to use the PoKeys for all my front panel stuff and the ESS/MB2 for the other stuff and asked if they could see any issues.   Actually I did the same with the PoKeys support as well.  Both came back with positive responses.

Matevž from PoLabs said that he couldn't see any issues just to make sure that the PoKeys got a valid network configuration.  I had no idea what that meant and had to ask for clarification.

Rob Gaudette from Mach support said just to do all the mapping via the ESS and I would be good to go.  I still don't really understand what he meant, but I did my best to do that and have them both configured and running at the same time in Mach and they both seem to make stuff happen without getting in each other’s way.

But I am going to ask Mach support again I think, just to be sure.  Thanks so much for drawing my attention to this Craig.  You are a Champ

Bed time

Craig.