Hello Guest it is March 29, 2024, 10:31:37 AM

Author Topic: Need some minor LUA adjustments...  (Read 6123 times)

0 Members and 1 Guest are viewing this topic.

Re: Need some minor LUA adjustments...
« Reply #10 on: May 31, 2017, 04:01:09 AM »
Hi again.. This is to be short.. Need to study for my exam...   I made an post 1 or 2 days ago about buttons and switches... take a look here:
http://www.machsupport.com/forum/index.php/topic,35013.msg240578.html#msg240578

About your button question how to activate an output... I just made an short video for you on my Youtube channel.. Just an short tutorial..

https://www.youtube.com/watch?v=3XY0o0gXz2A

I hope this will help :)

SOR.. 8)

Offline CRS

*
  •  61 61
    • View Profile
Re: Need some minor LUA adjustments...
« Reply #11 on: May 31, 2017, 06:51:49 AM »
Hi Soruud, thank you for going to so much effort, and so quickly.  You are a good man.

But now I feel like a total dork.

After I posted, I went back down to my workshop and realised I should have been more specific about my question.  When I said screen button, I meant the standard single action button.  Yes the toggle button allows you to choose the outputs from a long list, but I need to use the standard button, which for whatever reason doesn’t do that.  I have tried scripts, but that is my challenge.

I intended to do another quick post to you, but you beat me to it.

Because of the latching relays on the Bridgeport mill, the three spindle control buttons, CW, CCW and STOP need to operate like a momentary switch, that is on when it’s down and off when it is up, this works really well for latching in the relays just like the momentary ON and STOP buttons on the machine.

The standard button can operate this way, but don’t offer a selection of many outputs, only some predefined ones in the event section.  Down action and Up action.
So this is a bit embarrassing, I promise next time I think more and not just ask as a passing thought as I rush away.  Still I am sure that video will help some poor person on their trek for Mach mastery.

Thanks Soruud

Craig.
Re: Need some minor LUA adjustments...
« Reply #12 on: May 31, 2017, 07:52:24 AM »
Ahh... Well lets try to do this with an normal momentary button then :)


Make an normal button.
Go to Clicked Script and enter this:

hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0);
local state = false;
local VarIamTestingFor = SomeThingIamWatchingOrSettingOrValue;
if VarIamTestingFor == WhatSetsTheOutputToOn then
state = true;
else
state = false;
end
mc.mcSignalSetState(hsig, state);

Now the button will set Output 0 to Active until you somehow deactivates it.
So if you want to deactivate it with an other button you wil do the same just enter the same script and invert the "true" to "false" and the "false" to "true"
As this:

hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0);
local state = true;
local VarIamTestingFor = SomeThingIamWatchingOrSettingOrValue;
if VarIamTestingFor == WhatSetsTheOutputToOn then
state = false;
else
state = true;
end
mc.mcSignalSetState(hsig, state);


This script is an example taken from a PDF made By Scott “Poppa Bear”
The PDF is easy to find on web. Google for Poppa Bear LUA.

1 step closer now ?

Sor

Offline CRS

*
  •  61 61
    • View Profile
Re: Need some minor LUA adjustments...
« Reply #13 on: May 31, 2017, 08:32:04 AM »
Hey you are meant to be studying!

Thanks Soruud, late now, so after school drop off, first thing tomorrow morning, I will try this.

Thanks so much, I had better hurry up so I can help you somehow.

Well done.

Craig.

Offline CRS

*
  •  61 61
    • View Profile
Re: Need some minor LUA adjustments...
« Reply #14 on: May 31, 2017, 08:11:45 PM »
Hi Soruud,

Hey what is it you are getting examined for?

Now the Spin Stop switch.  Well my excitement waned after I couldn't get it working.  Still I will keep trying, doing something wrong...

Re external Jog increment and continuous.  Quite a while back I downloaded a script by Bob Mills.  There is a bit in there that may be of use to you (and me) which deals with inputs for incremental and continuous.  Have a look and see what you think.

Craig


Offline CRS

*
  •  61 61
    • View Profile
Re: Need some minor LUA adjustments...
« Reply #15 on: June 01, 2017, 12:51:31 AM »
Hi soruud, me again.

I wasn’t able to get the other Papa Bear script working, so embarked on another way of doing it.  And I am very proud of myself.  Today was the absolute first time I have written some Lua code from scratch, albeit very simple, and got it to work.  No cut and pasting or copying.  Well not exactly anyway.

I have no idea if it’s a correct way or just plain ugly, but for now I will rejoice in my first time ever.

I got a standard button to activate output 0 when pushed in and deactivate when let off.  I am sure someone will read this and laugh, but when you are having a love to hate relationship with Lua, any small success must be celebrated!

Now we have three buttons that all emulate a momentary switch. The Spindle FWD and REV buttons were a lot easier to configure as you can select them from the Up and Down Action lists.  But this darn Spindle OFF button has been the challenge.  But now it works.

The small bit of code for the Up and Down Scripts is below.

I also had to make sure that Cycle Stop activated Output 0 as well, so spindle will stop when you hit that button.

Thanks for your help Soruud.  Let me know if you have any Joy from the Bob Mills script for jog settings.

Craig.



This is how I did it.

Code: [Select]
--Up Script

local inst = mc.mcGetInstance()

local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0)
spinoff = mc.mcSignalGetState(hsig)
if (spinoff == 0) then
    mc.mcSignalSetState(hsig, 1)
else
    mc.mcSignalSetState(hsig, 0)
end

--Down Script

local inst = mc.mcGetInstance()

local hsig = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0)
spinoff = mc.mcSignalGetState(hsig)
if (spinoff ==1) then
    mc.mcSignalSetState(hsig, 0)
end

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Need some minor LUA adjustments...
« Reply #16 on: June 01, 2017, 08:48:11 AM »
Nice! I knew you would get it.  :)

You could use the return calls to do some error checking to make it a little more robust but what you have should work just fine.

I love seeing folks grow.
;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: Need some minor LUA adjustments...
« Reply #17 on: June 01, 2017, 04:09:28 PM »
Hi Chaoticone, thanks for the encouragement, it was of course your fault that I discovered the simplicity of using the standard switch as momentary.  Lesson there was, don’t assume without trying.

Other lesson, be more precise when asking questions.  I led DazTheGas off on a tangent looking for the switch to have a time delay, because that is what I asked for.  He is a good man hey.  Still I ended up using his idea in the Macros for M3, M4 and M5.  So all good.  And learned about the wx.timer along the way.

Now there you go mentioning something that I now need to know about.   Kind of like saying to a child, “did you know about the free ice cream?”  As if they are going to let that go.

Error checking??  Has that something to do with the rc.____  I see it a lot?  I worked out the “rc” must be Return Code, but return from what?

Thanks  Chaoticone, off to hit my head against another brick wall.

Craig.
Re: Need some minor LUA adjustments...
« Reply #18 on: June 01, 2017, 05:15:08 PM »
Hi. I was allso wondring about the RC word... What does it mean?
And how exactly do I make a external button to set an output without going back to previous state when using momentary buttons? I tought I knew, but still dont.
When a momentary button are pressed it changes state, but it does it again on release... This is probably a dumb question...
I tought I got control of my buttons until yesterday whan I found out that things dont work...

Things work just fine as screen buttons, but not as pokeys unput buttons...

Daz... Please. You know all about this, dont you ???

An tutorial video for dummies during setup of Pokeys buttons would be just awesome :))

Offline CRS

*
  •  61 61
    • View Profile
Re: Need some minor LUA adjustments...
« Reply #19 on: June 01, 2017, 05:51:59 PM »
Hi Shoruud, I'm off for school drop off, but just wanted to say, that Daz, if I remeber correctly, doesn't have a Pokeys.  But I'm sure it is the same for all external buttons no matter how they are getting into the mix.

I will be using some latching buttons, but for simple cycle start and jogging, the momentary thing works perfectly.

Have to go, talk soon

Craig.