Hello Guest it is March 28, 2024, 06:43:54 AM

Author Topic: Lua  (Read 15283 times)

0 Members and 1 Guest are viewing this topic.

Re: Lua
« Reply #10 on: January 05, 2017, 07:41:20 AM »
Hi Craig,
just checked and Daz-The-Gaz confirms that only one motion controller can be active at once, however more
than one device can be active.

Thinking that your motion controller would be ESS with usual motors, limits, homes and Estop.

Your control panel hooks to the PoKeys.

Both would require an Ethernet connection but pretty sure you can arrange it so the IP addresses don't clash but
your PC would require two Ethernet ports.

I would in the first instance get the motion controller working and not worry about the panel until you've got the machine
running. Trying to get both going at once if your new to it is going to give you grief.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Lua
« Reply #11 on: January 05, 2017, 07:52:39 AM »
Sometimes you have to look into the future, ever wondered why you have an instance number for mach4 and suddenly appearing within in places within the GUI editor.. I could be wrong but I can see that in the future additional motion controllers could be attached to different instances, but then your talking big machines and definitely not the hobby version of mach4.

But thats just my views

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Lua
« Reply #12 on: January 05, 2017, 08:11:24 AM »
G'day DTG,
that sort of thinking does my head in! Imagine axes spread over two controllers and you want to probe....would the probe be attached to one controller
or both...

My guess was that there will come a time when you can have multiple copies of M4 running on the same platform but running different machines, or
rather multiple threads, one for each machine but only one copy of M4 running. I'm a long way from coming to terms with just one active thread!

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #13 on: January 05, 2017, 11:09:29 PM »
Hi Craig,

Another day already, thank you for your time on this, I am sure you must have other more pressing things to do.  I really appreciate your help.

Well it seems the I/O shouldn't be an issue.  I did send the question back to Mach Support, but it looks like using the ESS as the motion control and the PoKeys purely as an interface card, shouldn't be an issue.

Actually, there is a YouTube video by a chap called Paul who happens to be just down the road from where I live.  He is asking for help with his MPG issue.  https://www.youtube.com/watch?v=qFqoS4VVnrw
He uses an ESS as the controller and also has the PoKeys in his custom control box for all the I/O.  STUPID ME!  That is where I got the idea!  Getting older.

So back to Lua.  I have once again been reading more.  The Help menu on the Mach screen with all the docs, was already one of my well frequented areas as was the other link you sent.  I am still trying to figure out how to get the Cycle Stop or Feed Hold to work.  Been looking how it is written further down in the script and comparing it to the Cycle Start.  That hump is pretty high.

Have you ever tried putting any of you buttons external?

Craig

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua
« Reply #14 on: January 06, 2017, 01:22:19 AM »
Have a look up https://www.youtube.com/user/hossmachine/videos Hoss use's a C6 to run the motors and other stuff and a pokeys for IO, on his control panel.
With the pokeys you set it to a IO devices, Mach can use one motion control and one or more IO at once.

your ESS will be the motion devices on that board and the pokeys set IO, It's in the pokeys manual how to do it.

The Pokeys 57cnc is a monster of a devices it's a mile a head of the ESS the ESS may catch up one day.

Have a look on the pokeys web sight there is instructions on there for doing just what you wont http://blog.poscope.com/mach4-tutorial-custom-signal-mapping/
« Last Edit: January 06, 2017, 01:25:52 AM by dude1 »
Re: Lua
« Reply #15 on: January 06, 2017, 01:25:58 AM »
Hi Craig,
no, I don't have any external buttons. I do use a pendant which has an MPG wheel and has all the functions of your panel
and some extras. It plugs in to the USB port, real breeze. Perhaps not as convenient as your panel but it works well.

A couple of ways to do it:
1) in the PLC script have a bunch of code that reads all of the inputs in turn and performs an action if it detects
    a button. The PLC script runs every 50ms or so.
2) use a signal script. In the 'help docs' look at 'Mach4 CNC Controller Lua Scripting Guide', section 3.2.4 Signal Script
    The method of building a table (in the screen load script) and having a series of functions in the signal script for
    each of the different buttons is probably the way to go.

Option 2 is by far the more computationally efficient method.

Have you got your machine running yet? No matter how fancy your control panel is you must have a debugged motion
controller and machine for it to control. At need you can run ALL your programs without a control panel, in fact the vast
majority of Mach4 installations run this way. With a touch screen you don't even have to have a physical panel.
1) Get your machine running with Mach4/ESS/MB2
2) Shag around with a panel to your hearts content, at least you'll still be able to get your moulds done in the mean time.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #16 on: January 06, 2017, 04:25:22 AM »
Hi Dude 1 and Craig aka joaverage,

Firstly Dude.  Thanks for chiming in, yes I have watched quite a few of Hoss’ videos.  And once again silly me for not remembering his set up.

I don’t really have any problems with the whole ESS/PoKeys getting along thing.  I have both working together with Mach and can run a G Code file and have the ESS, via the MB2 BOB sending out motor commands which was all initiated by using my Cycle Start button which is hooked up to the PoKeys 57E.  Also I have configured pins on the PoKeys to receive signals back from Mach which I set up with the default choices in the Mach configuration dialog box.  And that all works just fine.

If I was starting again, maybe I would have gone with the PoKeys CNC, but when I started, all I knew about was the Smooth Stepper.  I will be making another after this, so I will probably go with it for that one.

Thanks again to Craig for the info.  I couldn’t agree more about getting the mill up and running first.  I can get a bit wordy with my explanations, so on my wife’s direction I have learnt not to include every bit of boring info straight up.  Let people warm to me first…. And then bore them to death.

So I left out the whole explanation of where I am at with the building of the control and the fact that it is chugging along very nicely in the back ground.  The whole put-together of the electrics, the electronics and associated parts is fun and is now quite easy for me.  Didn't state out that way though.

I decided to dedicate myself to learning about Lua, as I knew it was coming up and I wanted to be ready.  Yes I will run the machine and get it all working first and then spend the time getting the buttons working.  The touch screen is a real option.  But the darn things seem to be quite expensive, so I shyed away.

Back to Dude1, I did actually use the PoKeys script example which you steered me towards.  It also appears in several other places in the Mach forum and by following that example, it was quite easy to get my Cycle Start button working with the PoKeys.  But I get lost with the next step where he talks of the Signal Library, handlers and tables.  My wife is Croatian and I have been trying to learn that language for about thirteen years, Lua seems about as complex at that.

Craig, I have read your last email a few times and now off to study more on how to do what you have suggested with option 2.  Once again those strange terms like Signal scripts etc..  I read about it all, but still not making sense.  Wise words though my friend about majoring on the major things.  Couldn't agree more.

Guys thanks, I will stop bugging you now.  I will go suffer in silence.  Have a great weekend and hopefully the next time I post on the forum, I will be free-wheeling down the other side of that proverbial Hump.
Craig.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Lua
« Reply #17 on: January 06, 2017, 09:07:58 AM »
This is an example that is in the default screens. Most of it is commented out and it doesn't have as many comments but what it does is sets up input one to do two things. Cycle start and feed hold. It acts like a dead man if used with a momentary switch.

You push the switch in, input one changes states from 0 (off) to 1 (on), the function runs which checks the state of the switch and if == 1 it runs the CycleStart function (found further down in the screen load script).

When you release the button the state of input one changes again and it now == 0 (off). So, since the state changed from 1 to 0 the function runs again which checks the state and if anything other than 1 run the  mc.mcCntlFeedHold API call.

Code: [Select]
[mc.ISIG_INPUT1] = function (state) --Add input one to the signal table so this function runs each time input one changes states.
    if (state == 1) then --If the state of input one equals 1 (on) run the CycleStart function.
        CycleStart()
    else --The state of input one does not equal 1
        mc.mcCntlFeedHold (0) --Feed hold instance 0 of Mach4
    end

end,
« Last Edit: January 06, 2017, 09:11:02 AM by Chaoticone »
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #18 on: January 06, 2017, 11:28:06 PM »
Hi Chaoticone, thanks for your input.  I have seen a lot of your posts over the time that I have been looking though the forums.  It is a pretty amazing thing, that a community of like minds that can share this knowledge world-wide, without having to actually meet.  That still amazes me.

I think my wife is becoming a CNC widow..

I had seen that example that you showed on your post, and I think pretty much the same as on the Pokeys site and a few other threads.  Thanks for explaining it as you did.  Every bit helps me to become more comfortable with it all.  I did get the Cycle Start working as it should by using this example.  But when I try the same thing for Feed Hold and Cycle stop, I just get errors.  More to learn.

Got to get my head around how the bits in the Screen Load script, the PLC, Signal Library and the Signal Script all relate to each other.  And what all the weird names mean.  I have done many tutorials and the penny will drop I am sure.  It is just a mind shift I guess.  Thank you though for taking the time to explain a bit more.  I look forward to being able to help some other confused enthusiast down the track.

Craig.

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua
« Reply #19 on: January 07, 2017, 01:11:57 AM »
You need something like this I am not sure if this is the correct way to do it now
Code: [Select]
SignalTable = {001,
    [mc.ISIG_INPUT0] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStart(inst)
        end
    end
}
SignalTable = {002,
    [mc.ISIG_INPUT1] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlCycleStop(inst)
        end
    end
}
SignalTable = {003,
    [mc.ISIG_INPUT2] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlReset(inst)
        end
    end
}
SignalTable = {004,
    [mc.ISIG_INPUT3] = function (on_off)
        if (on_off == 1) then
            mc.mcCntlFeedHold(inst)
        end
    end
}   
 ------------------------------------------------------------------------   

if (SignalTable[001] ~= nil) then
SignalTable[sig](state)
end

if (SignalTable[002] ~= nil) then
SignalTable[sig](state)
end

if (SignalTable[003] ~= nil) then
SignalTable[sig](state)
end

if (SignalTable[004] ~= nil) then
    SignalTable[sig](state)
end