Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: soruud on May 15, 2017, 03:15:41 PM

Title: Need some minor LUA adjustments...
Post by: soruud on May 15, 2017, 03:15:41 PM
Hi. I got a LUA script for an Pedant, but I need help to adjust it a bit for my needs.
This Lua is written for pedant with 2 selector knobs to set MPG Axis selection and STEP rate.
I will use momentary pushbuttons for this if possible. So I will use 4 buttons for X Y Z A axis, and 3 buttons for STEP rate 0.1 - 0.01 and 0.001.
Can someone please help me?  I should mention that I dont know much about LUA... ???


--Go to the closing } of the SigLib table in the screen load script and
--delete it. Then paste all of this code in its place.
--The new closing } for the SigLib table is on line 48 of this script.
--------------------------------------
--          CNC4PC Pendant         --
--------------------------------------
-- These simply run the CNC4PCPendant function if their state changes.
[mc.ISIG_INPUT10] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT11] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT12] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT13] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT14] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT15] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT16] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT17] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT18] = function (state)
    CNC4PCPendant()
end,

[mc.ISIG_INPUT19] = function (state)
    CNC4PCPendant()
end

}

---------------------------------------------------------------
-- CNC4PC Pendant function.
---------------------------------------------------------------
function CNC4PCPendant()
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT10)    -- Is mapped to Port 2 Pin 4 *X Selection
   local XSelection, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT11)    -- Is mapped to Port 2 Pin 5 *Y Selection
   local YSelection, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT12)    -- Is mapped to Port 2 Pin 6 *Z Selection
   local ZSelection, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13)    -- Is mapped to Port 2 Pin 7 *A Selection
   local ASelection, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14)    -- Is mapped to Port 2 Pin 8 *.001 Selection
   local Step001, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15)    -- Is mapped to Port 2 Pin 9 *.010 Selection
   local Step010, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT16)    -- Is mapped to Port 2 Pin 10 *.100 Selection
   local Step100, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT17)    -- Is mapped to Port 2 Pin 15 *Estop
   local PenStop, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT18)    -- Is mapped to Port 2 Pin 12 *B Selection
   local BSelection, rc = mc.mcSignalGetState(hSig)
   local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT19)    -- Is mapped to Port 2 Pin 13 *C Selection
   local CSelection, rc = mc.mcSignalGetState(hSig)
   local PenJogOn, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)-- Is mapped to Port 2 Pin 1 *Jog on LED
   
   if XSelection == 1 then
      mc.mcMpgSetAxis(inst, 0, 0) --X Axis
      mc.mcCntlSetLastError(inst, "X Selected")
      mc.mcSignalSetState(PenJogOn, 1)
   elseif YSelection == 1 then
      mc.mcMpgSetAxis(inst, 0, 1) --Y Axis
      mc.mcCntlSetLastError(inst, "Y Selected")
      mc.mcSignalSetState(PenJogOn, 1)
   elseif ZSelection == 1 then
      mc.mcMpgSetAxis(inst, 0, 2) --Z Axis
      mc.mcCntlSetLastError(inst, "Z Selected")
      mc.mcSignalSetState(PenJogOn, 1)
   elseif ASelection == 1 then
      mc.mcMpgSetAxis(inst, 0, 3) --A Axis
      mc.mcCntlSetLastError(inst, "A Selected")
      mc.mcSignalSetState(PenJogOn, 1)
   elseif BSelection == 1 then
      mc.mcMpgSetAxis(inst, 0, 4) --B Axis
      mc.mcCntlSetLastError(inst, "B Selected")
      mc.mcSignalSetState(PenJogOn, 1)
   elseif CSelection == 1 then
      mc.mcMpgSetAxis(inst, 0, 5) --C Axis
      mc.mcCntlSetLastError(inst, "C Selected")
      mc.mcSignalSetState(PenJogOn, 1)
   else
      mc.mcMpgSetAxis(inst, 0, -1) --No Axis
      mc.mcCntlSetLastError(inst, "No Axis Selected")
      mc.mcSignalSetState(PenJogOn, 0)
   end
   
   if Step001 == 1 then
      mc.mcMpgSetInc(inst, 0, .001)
   elseif Step010 == 1 then
      mc.mcMpgSetInc(inst, 0, .010)
   elseif Step100 == 1 then
      mc.mcMpgSetInc(inst, 0, .100)
   end
   
   if PenStop == 1 then
      mc.mcCntlEStop(inst)
   end
end
Title: Re: Need some minor LUA adjustments...
Post by: CRS on May 25, 2017, 04:21:00 PM
Hi Soruud,

Not sure this will be of much help, but I have just been using the same script for my external MPG wheel with really good success.  I am also currently helping a friend with his Bridgeport conversion to Mach4 and he needs to emulate on-screen momentary buttons for where the existing toggle style buttons operate the Spindle FWD, REV and STOP.

Like you, I find Lua very difficult, getting success only by noticing some kind of repeating pattern, then copy and paste and try stuff until it works.  So I sympathise.

Your external momentary buttons will most likely be configured in a similar way to what we will have to do on screen.  I have asked the question about how to emulate a momentary button direct to Rob Gaudette at Mach Support, you may have seen or heard Rob on some of the Mach4 videos.  In the past he has been diligent at getting back to me, so when he does, I will let you know what he says.

There is a toggle option for the on screen buttons which Rob has said I can configure to suit external buttons as well, but that is not what you need.  If you look in your Mach4 Hobby Program folder and then in the Lua Examples, there is a file called Activate Output.mcs.  I think we may be able to use this.  Might be wrong, but I think perhaps the only way to emulate a true momentary action is to have the signal activate for a period of time, say 0.5 seconds, and then auto deactivate.  The Activate Output.mcs script does exactly that.  I don’t know yet how to implement it, but I will get there somehow.  Maybe Rob will steer me that way.

Our requirements a slightly different.  With the Bridgeport conversion to Mach, that machine has internal latching relays for the Spindle, and so the signal from Mach needs to only be active to latch which ever relay.  It would actually still work to use the existing toggle function leaving constant 24V power to the relay coil , but then the momentary STOP button at the machine which breaks the latching circuit would not be effective.  As soon as your figure comes off the button, the machine starts again. NOT very desirable hey!

In your case, unless you rig up some little latching relays between your pendant and PC, I guess you might have to somehow emulate that latching function in Mach4.  Not sure if that’s even possible.  I know it would just be easier for you to use something like a 5 position rotary switch for axis select.  You need an OFF position, plus the 4 axis, and one for the speed select.  Or perhaps like the PoLabs pendant, a separate dead man switch for the OFF.

Anyway Soruud, as soon as I find anything out, I’ll let you know.

Craig.
Title: Re: Need some minor LUA adjustments...
Post by: soruud on May 26, 2017, 06:39:28 AM
Hi Craig. Thanx for your reply.
As time has past and no one had a awnser I had to try myself. And I got it to work :)
Take a look at the LUA below. I only got the X,Y,Z axis active for now.
I allso added a line ( scr.SetProperty('mpgaxisdisplay', 'Label', 'X axis'); under each Axis selection to post on screen what axis are currently active.
To display the current Axis just make an Toggle button in screen edit, and name it "mpgaxisdisplay" This name can be what you desire, but MUST be the same as in the
( scr.SetProperty('mpgaxisdisplay', 'Label', 'X axis'); line. The name is allso Case Sensitive !!!. And ofcourse you will need to change the X letter with Y, Z,A.. and so on in this line to show correct axis.
Actually this line can be used to display anything you want at anny time :)
The momentary buttons on my Control Panel are connected to a POKEYS57U board, and can easly be mapped to your desired Signal Inputs in MACH Config.
In my case as you see in the script I use Input 50, 51 and 52 for my X Y and Z axis.
Thats it. Now Axis selection will work with momentary buttons, and the current axis will be displayed on screen.



--------------------------------------
--       CNC4PC Pendant             --
--------------------------------------
-- These simply run the CNC4PCPendant function if their state changes.
[mc.ISIG_INPUT50] = function (state)    CNC4PCPendant() end,
[mc.ISIG_INPUT51] = function (state)    CNC4PCPendant() end,
[mc.ISIG_INPUT52] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT13] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT14] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT15] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT16] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT17] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT18] = function (state)    CNC4PCPendant() end,
--[mc.ISIG_INPUT19] = function (state)    CNC4PCPendant() end,
}
-------------------------------------------------------------
-- CNC4PC Pendant function. --
-------------------------------------------------------------
function CNC4PCPendant()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT50)    -- Is mapped to Pokeys pin50 *X Selection
local XSelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT51)    -- Is mapped to Pokeys pin51 *Y Selection
local YSelection, rc = mc.mcSignalGetState(hSig)
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT52)    -- Is mapped to Pokeys pin52 *Z Selection
local ZSelection, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT13)    -- Is mapped to Port 2 Pin 7 *A Selection
--local ASelection, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT14)    -- Is mapped to Port 2 Pin 8 *.001 Selection
--local Step001, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT15)    -- Is mapped to Port 2 Pin 9 *.010 Selection
--local Step010, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT16)    -- Is mapped to Port 2 Pin 10 *.100 Selection
--local Step100, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT17)    -- Is mapped to Port 2 Pin 15 *Estop
--local PenStop, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT18)    -- Is mapped to Port 2 Pin 12 *B Selection
--local BSelection, rc = mc.mcSignalGetState(hSig)
--local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT19)    -- Is mapped to Port 2 Pin 13 *C Selection
--local CSelection, rc = mc.mcSignalGetState(hSig)
local PenJogOn, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT10)-- Is mapped to Port 2 Pin 1 *Jog on LED

if XSelection == 1 then
    mc.mcMpgSetAxis(inst, 0, 0) --X Axis
    mc.mcCntlSetLastError(inst, "X Selected")
    mc.mcSignalSetState(PenJogOn, 1)
    scr.SetProperty('mpgaxisdisplay', 'Label', 'X axis');

elseif YSelection == 1 then
    mc.mcMpgSetAxis(inst, 0, 1) --Y Axis
    mc.mcCntlSetLastError(inst, "Y Selected")
    mc.mcSignalSetState(PenJogOn, 1)
    scr.SetProperty('mpgaxisdisplay', 'Label', 'Y axis');

elseif ZSelection == 1 then
    mc.mcMpgSetAxis(inst, 0, 2) --Z Axis
    mc.mcCntlSetLastError(inst, "Z Selected")
    mc.mcSignalSetState(PenJogOn, 1)
    scr.SetProperty('mpgaxisdisplay', 'Label', 'Z axis');

--elseif ASelection == 1 then
--    mc.mcMpgSetAxis(inst, 0, 3) --A Axis
--    mc.mcCntlSetLastError(inst, "A Selected")
--    mc.mcSignalSetState(PenJogOn, 1)  

--elseif BSelection == 1 then
--    mc.mcMpgSetAxis(inst, 0, 4) --B Axis
--    mc.mcCntlSetLastError(inst, "B Selected")
--    mc.mcSignalSetState(PenJogOn, 1)

--elseif CSelection == 1 then
--    mc.mcMpgSetAxis(inst, 0, 5) --C Axis
--    mc.mcCntlSetLastError(inst, "C Selected")
--    mc.mcSignalSetState(PenJogOn, 1)

--else mc.mcMpgSetAxis(inst, 0, -1) --No Axis
--    mc.mcCntlSetLastError(inst, "No Axis Selected")
--    mc.mcSignalSetState(PenJogOn, 0)

 end

    if Step001 == 1 then
        mc.mcMpgSetInc(inst, 0, .001)
    elseif Step010 == 1 then
        mc.mcMpgSetInc(inst, 0, .010)
    elseif Step100 == 1 then
        mc.mcMpgSetInc(inst, 0, .100)
    end

--if PenStop == 1 then mc.mcCntlEStop(inst) end
end


To make it work with momentary buttons I had to disable the:

--else mc.mcMpgSetAxis(inst, 0, -1) --No Axis
--    mc.mcCntlSetLastError(inst, "No Axis Selected")
--    mc.mcSignalSetState(PenJogOn, 0)
Title: Re: Need some minor LUA adjustments...
Post by: CRS on May 26, 2017, 07:27:20 PM
Hi Soruud, that is well done.  Thanks so much for sharing this with me and all interested.
Hey, I thought you said you didn't know much about Lua.  Maybe not, but in my present state of ignorance, I couldn't have done that.

I have studied what you did and can see how you did it.  I only just learned about “scr.SetProperty" by watching a video that DazTheGas has just made to show me (and anyone interested) how to set up a momentary screen button.

Check this;  https://www.youtube.com/watch?v=1Q5YxjsBfT4&feature=youtu.be

I like what you have done with the screen message for the selected axis.  The way it was, the selected axis comes up in the message line, but then disappears out of site when the next thing happens.  Well done!  I have learnt another thing.

I also have the Pokeys, but the 57E.  I have a slightly elaborate front panel and needed more inputs than the MB2 breakout board could give me.  I'll attach my front panel for your horror.

Smart what you did disabling the "No Axis Selected".  Now I get it,…. once an axis is selected, it just stays there until the state is altered by another selection.  It doesn't require an on-going ON state.  I guess this is how one learns this stuff.  One penny drop at a time.  No special momentary function needed.

Rob from Mach Support is also getting back to me with his idea for the Momentary switch.  So if you have an interest, I will post what he says in this thread.

Have a great day Soruud

Craig
Title: Re: Need some minor LUA adjustments...
Post by: soruud on May 28, 2017, 10:58:01 AM
Hi again. So nice that you found my solution useful. It takes some effort to get things as I want them in Mach4, and most because of LUA. But things are getting bether evry day.
I am waiting for my panel buttons to arrive from a fabric in China, so I am just testing some things, and playing with the Screen editor. I allso made an screen background in SolidWorks just to
see if I could use it, and that worked out great. Now I just *********ed upp a lot of other things ;D

Take a look at the attached screen file. You may find a few features there you may like. The screen are just a mess, it works, but misses a lot.
I wrecked the MDI input, so it wont work, so I got a unique chanse to learn how to fix it. haha.

Allso take a look at this video from my Youtube channel. Thats my machine and control panel with 22" Touchscreen  8)

https://www.youtube.com/watch?v=hke3yk6u3_o
Title: Re: Need some minor LUA adjustments...
Post by: CRS on May 29, 2017, 06:37:20 AM
Hi Soruud or Stig.

Hey great job on your control cabinet and panel.  I watched your videos, very entertaining.  I also use Solidworks a lot and I was impressed by how fast you were mirroring things.  I couldn’t see you using your cursor, do you have a hotkey for mirror?

I am just about done, long day of Lua and switches.  Noting does me in faster than being ignorant and staring at the screen partly from frustration and partly just plain stuffed.  I would like to find out more about your on-going project.  It looks great.  Mine is just a cover to go over the existing control panel.  Yours is a creation.
I’ll get back when I am more awake.

Craig.
Title: Re: Need some minor LUA adjustments...
Post by: soruud on May 29, 2017, 08:26:12 AM
Hi Craig. Well I got hotkeys for many things in SolidWorks. M for mirror, L for line, K for center line, C for circle, N for normal to and many more.. I draw way faster that way combining mouse and keyboard.
SolidWorks is mainly what I am doing at work when prototyping and product designing things. So when drawing skills are taken care of it is a lot easyer to have cnc as hobby :)
I allso use SolidCam for programming. Maybe some1 here in forum got a good post prosessor for me? SolidCam to Mach4.
Did you look at the screen file ? Tell me what you think? I can see the file has been downloaded a few times already, so maybe some1 else got some tips for me? Did I do anything wrong?

Sor.
Title: Re: Need some minor LUA adjustments...
Post by: CRS on May 30, 2017, 07:05:24 PM
Hi Soruud,

Sorry for the late reply, you know how life gets in the way.  Yes I opened your screen, you have been a busy guy haven’t you.  I still have to play around with it as my screen in my workshop is only a 17” (3:4), so your screen has its fair share of problems trying to fit properly.  It’s all squashed up like a can of sardines.

I am sure there is an easy and obvious way to adjust the fit, I will go and try again.  Lots of thought has gone into your screen hey.  You are a bit ahead of me.  I am still trying to get my head around not electrocuting myself and not blowing up the Pokeys, MB2 breakout board or the ESS.

I want to poke around a lot more and see how you have done things.  The whole screen set up thing is something that isn’t too hard to get your head around.  BUT LUA!  For someone with absolutely no experience in programming, that right there is enough to turn people of Mach 4.  It is the biggest hurdle and the thing I have spent and wasted the most amount of time on.  The rest is relatively intuitive and easy.  But Lua is a pain.  And without an understanding you can’t do a lot of things.

Anyway, stop my whinging. I watched a couple more of your videos.  You putting together your cabinet and also the SW videos.  It is so interesting to see someone else’s take on how to do things.  I use Solidworks a lot, but not really for my work.  Just to design stuff.  I have been building radio control racing yachts as my income for about 24 years now and after designing the hull in a program called Maxsurf, I bring the hull surface into Solidworks to construct all the deck and other detail.

Then it’s off to the Pattern Making guy (my mate) to get the patterns CNCed on one of his much bigger machines.  So it is with much interest that I watch how you work with SW.  Hey can I ask you a question?  By the way, that wasn’t the question.

Do you have external buttons for jogging? I don’t think I saw you do that on the video.  If you do, or don’t, do you have external control for the Incremental of continuous jogging?

Really like watching the videos Soruud.  What software do you use to capture your work on Solidworks?

Craig.
Title: Re: Need some minor LUA adjustments...
Post by: soruud on May 31, 2017, 01:58:12 AM
Hi Craig. The screen file are looking the same on my screen I think. Main tab window down to the right are allmost folded up. Its because I only use this screen for testing,
and I needed the space. If youn are watching at 2.35min into the video you will see that I use an digital joystick for jogging. That is all I got, but an digital joystick
works exactly the same way as an momentary pushbutton, only 4 of them :) And it only works in continious mode. >:( This is a problem because I want it to work in INC mode as well. I really dont know how to do that... But some1 here in the formy may know? I am afraid we need to have dedicated buttons for INC jog, but it SHOUD be able to change the mapping of a button ?
I actually posted a tread about this problen in this forum, but there is no replays.  ???
Title: Re: Need some minor LUA adjustments...
Post by: CRS on May 31, 2017, 02:55:36 AM
Okay so the screen is still a work in progress.  I kind of got it to fit just by resizing, but thought there was a way of making the existing full screen re adjust, like one does with the TV screen.

Anyway, regarding the incremental and continuous jog from an external button.  Funny about that, it is exactly one of the things I still have to get sorted.  I'm helping a friend, who has even less idea about any of this, convert his old Bridgeport mill to Mach4 and then there is my own little Hercus mill conversion.  The external jog with inc and cont is for my machine.

I thought to have this one as a latching switch on my control panel.  I have many of the same kind of little push button switches as I saw on your video, I assume yours all come from China as well.
I also thought to make the default “off or un-latched” position incremental for safety and latched in for continuous.  Only need to use one input and now I just need to figure out how.  Should never use the work "JUST" with all this.

So maybe we can let each other know when we find out new stuff.  I think you have a better grasp.  I am still back at WHY?  All the Lua material seems to assume you know what the heck they are talking about.  I need to go back to, “why is it so?”

Here’s a basic question Soruud.  Do you know how to make a screen button activate an output?  I just want to know that right now.  The hours I have wasted.  They all seem to activate a pre-defined output like mc.OSIG_SPINDLEON.  I just want to active an output that I chose, for example OUTPUT_0.

Any ideas?

Craig.
Title: Re: Need some minor LUA adjustments...
Post by: soruud 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)
Title: Re: Need some minor LUA adjustments...
Post by: CRS 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.
Title: Re: Need some minor LUA adjustments...
Post by: soruud 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
Title: Re: Need some minor LUA adjustments...
Post by: CRS 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.
Title: Re: Need some minor LUA adjustments...
Post by: CRS 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


Title: Re: Need some minor LUA adjustments...
Post by: CRS 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
Title: Re: Need some minor LUA adjustments...
Post by: Chaoticone 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.
Title: Re: Need some minor LUA adjustments...
Post by: CRS 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.
Title: Re: Need some minor LUA adjustments...
Post by: soruud 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 :))

Title: Re: Need some minor LUA adjustments...
Post by: CRS 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.
Title: Re: Need some minor LUA adjustments...
Post by: CRS on June 01, 2017, 09:39:04 PM
Hi again Soruud, so which buttons are you thinking of?  I mean for which functions?

I re read the whole thread by Bob69 (Bob Mill) which was back in October 2016.  It was about multiple inputs in a Lua script.  I am sure you must have come across it, but just in case here it is

http://www.machsupport.com/forum/index.php/topic,33402.0.html (ftp://http://www.machsupport.com/forum/index.php/topic,33402.0.html)

He spends a lot of time on the whole Jogging thing.  So I send a personal message to him asking if he has it sorted yet.  He was almost there back then.  So hopefully...

I re read and the rc definitely stands for Return Code, so I assume that is what Chaoticone was talking about with error checking.  Now to figure that out as well.

Anyway, I'll let you know if Bob comes back with some info.

Craig.
Title: Re: Need some minor LUA adjustments...
Post by: soruud on June 02, 2017, 12:30:54 AM
That is true. It dont mather what type of I/O board we use.. The way to do it is the same.

Have a nice day at school. I my self are going for a weekend with Hardcore OffRoad ;)

Pic attached :)
Title: Re: Need some minor LUA adjustments...
Post by: CRS on June 02, 2017, 01:59:09 AM
I wasn't going to school for the day, just drop off my little girl. Believe it or not, I do in fact work....occasionally.

That is a fun buggy you are going to punish on the weekend.  Have fun, I'm sure you will.

I heard back from Bob69, sadly he has never got the whole jogging thing worked out.  That's a shame.  He seemed to have a better grasp of how to make the scripts work than I ever have, so I'm not feeling confident...

Still, if I/you stick with it long enough the answer will happen.  Wouldn't it be nice if there were just a user interface and we ticked the boxed for what we wanted and it all just happened?  Maybe with Mach 97 that will happen.

Have fun OffRoad.

Craig.
Title: Re: Need some minor LUA adjustments...
Post by: Chaoticone on June 02, 2017, 09:15:15 AM
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.


Yup, rc = return code. It is used for Machs built in error checking and returned from the core (which is the wizard behind the curtain, manages all things Mach) the best I understand. I think all of the api calls have the various possibilities for each call listed in the API help file. The more you learn/understand about Machs lua the better the help file is. It really is good.

Here is a link you might find helpful.
http://www.machsupport.com/forum/index.php/topic,32263.msg224557.html#msg224557

And an attachment.
Title: Re: Need some minor LUA adjustments...
Post by: Chaoticone on June 02, 2017, 09:33:36 AM
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 :))



Lots of ways you can do buttons, inputs, etc..

Regular button ..... is a momentary. It goes down when clicked and back up when released. Toggle: one press or state change sets the state of something, another press sets another state, another press........ etc.

First find out what state your in then do what ever you want on the next press/state change. For an on screen button do it in the buttons clicked script, for an input button use the sig lib (signal script) in the screen load script. If you want an on screen button and an input button to do the same thing create a function and call it from the on screen button and sig lib. If want a custom m code to do the same thing roll that function into a module and call if from onscreen buttons, input buttons and/or m codes.

Toggle Button....... is a two state button. It has an up and down state that are maintained until the next click. The up state script and properties are what you want the button to do, look like and say when in the up state. Same for down.

You can do any of teh above with dwell by using a timer as Daz has already done such a good job showing.


Title: Re: Need some minor LUA adjustments...
Post by: CRS on June 08, 2017, 05:58:08 AM
Hi Soruud, how was the big boys weekend away?  I assume you must be back.

Have you seen one of the latest posts by Bob69.  I have been involved with him as he works out the same thing you are interested in with the external Jogging

I think he has it.  Go here and have a look http://www.machsupport.com/forum/index.php/topic,35072.0.html (http://www.machsupport.com/forum/index.php/topic,35072.0.html)

I have it edited to suit my needs, but haven't tried it yet.

Craig
Title: Re: Need some minor LUA adjustments...
Post by: soruud on June 08, 2017, 06:42:40 AM
Hi Craig. I am back yes :) Weekend was just awesome. I will check out your link. So far many has tryed to fix this, but no fix yet as far as I know.
I think I can live without it if I must, but nice to have if I can.

SOR
Title: Re: Need some minor LUA adjustments...
Post by: CRS on June 08, 2017, 07:08:29 AM
Bob actually has it working.  I have spent about a week back and foward with him, and he has a good handle on the whole thing.  So yes take a look.

Craig.