Hello Guest it is April 19, 2024, 05:42:21 AM

Author Topic: Lua  (Read 15375 times)

0 Members and 1 Guest are viewing this topic.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Lua
« Reply #30 on: January 18, 2017, 11:16:18 PM »
Something like this?

local percent = analog/1*250 ‐‐Calculate percentage from 0% to 250%

if (percent < 50) then
    (percent = 50)
end

That wont take care of offset so you can take advantage of the the full sweep of the pot though.
« Last Edit: January 18, 2017, 11:19:38 PM 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 DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Lua
« Reply #31 on: January 19, 2017, 03:14:20 PM »
This should get you in the right direction, lua file attached.

https://youtu.be/3TeqRoT1pD4

One other thing though, I took a look at the link you sent me and looked at the code, I would be totally against putting "dofile(“C:\\Mach4Hobby\\PoKeys_analog_FRO.lua”)" in the PLC. dofile is just as it says (it runs the file) so this will be done at the speed of the PLC, so continuously reading the harddisk or cache and redeclareing the functions. I would seriously consider moving the functions to the screen load script and calling them from the PLC.

DazTheGas
New For 2022 - Instagram: dazthegas

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #32 on: January 19, 2017, 03:38:07 PM »
Daz, how did you do that?  In the time it took me to go to the workshop and get a few things ready for today’s work, you manage to write all that stuff in Lua, set up the bread board and make a video!

I was still back on the question about the resolution of the pot....  You are a man of action.

Can you tell me how you know about Lua.  Did you learn on the go, or do you have a back ground in programming.

I have NO idea about it.  Can you tell me a good REALLY beginners way to learn it?  All the tutes start off assuming i know something and then hit over drive.

Thanks so so much for your time and explanation.  Hopefully I can return the favour one day.

Craig Smith

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #33 on: January 19, 2017, 03:41:19 PM »
Hi Dude, hey check out Daz's response on this thread.  What a guy.  Already made a video and uploaded the Lua script to take care of it.  How did he do that?!

I have to go out and all I want to do it try it.  Let me know how it goes for you.

Craig.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Lua
« Reply #34 on: January 19, 2017, 03:45:07 PM »
Arduino already setup for another project I am working on,

A real good way is to look at other code snippets and scripts, learn a few commands from the api and when they make sense the rest of the api will too.

DazTheGas

New For 2022 - Instagram: dazthegas

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Lua
« Reply #35 on: January 19, 2017, 04:42:26 PM »
That's why I said PM Daz he is very good,

What he has done is in the wrong langue for me to use My machine that will be run on M4 has all the codes done from Daz's help, years ago.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Lua
« Reply #36 on: January 19, 2017, 05:01:30 PM »
Duuuuuude, nice to see you back here :-)

Daz
New For 2022 - Instagram: dazthegas

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #37 on: January 21, 2017, 07:24:52 PM »
Hi DazTheGas,

I have to say I was pretty excited to get the Spin OVR happening, thanks again for you very impressive help.

All grown up and I still get that sinking feeling when things don’t quite go as planned.  Two days now of…. Hmmm what if I try this or that or this..etc..

I think I must be filling in one of the options incorrectly as the Spin OVR slider in Mach 4 is stuck hard to the bottom.  There are no errors when I run the Screen Load or PLC scrips.  Actually there is a nagging little error in the PLC, but that has been there since day one.

Firstly, the name of my controller, I know this should be obvious to me, but do you mean the PoKeys, the ESS or the screen set?  I have tried all three with no success.

I noticed that on your video, the name of the Screen Set is “machduino” which matched what you have in the table, however there are capitols in that line of code. “MachDuino”.  So perhaps your Arduino is called machduino. Confussion.  I am using screen set wx4.

The other thing is the name of the register. I assume that’s the name of the input when you look in the Register Diagnostics in Mach, which in my case is “Analog pin 42”.  So I think I got that right.

Like I said, no errors show up, but that slider sucker won’t move.  Any thoughts DTG? Sorry to harass on a Sunday.

Craig. (CRS)

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Lua
« Reply #38 on: January 22, 2017, 07:29:02 AM »
How very odd, ive just read the pokey`s manual and the analog is a value between 0v and 3.3v so I will have to redo the table to reflect this as the value its picking up is 0 so thinking you want only 50%

Take no notice of the screenset name thats just purely a name.

Quote
which in my case is “Analog pin 42”
that is the name of the register, if you look above this then you will have the controller name too, (take a look at page 32 of the pokeys manual at 2 pics at top)

Code: [Select]
local hreg = mc.mcRegGetHandle(inst, string.format("NAME OF CONTROLLER", "Analog pin 42"))
I will redo the table and repost.

PS what nag do you have in the PLC??

DazTheGas

New For 2022 - Instagram: dazthegas

Offline CRS

*
  •  61 61
    • View Profile
Re: Lua
« Reply #39 on: January 22, 2017, 02:46:05 PM »
DTG, when do you sleep?  Thanks again, I don't know what else to say, I'm starting to feel quite guilty.

I tried to look in the PoKeys manual, of which I seem to have a few versions, but couldn't see anything on any of the page 32s. (nice grammar)  Not to worry as I got what you are saying.  My controller is "PoKeys_25172" and Register name is "Analog input 42". (Not actually Analog pin 42)

I changed that in my SpindleOVR.lua file, but slider still stuck hard.  I thought it may come up a bit based on what you wrote about it thinking I only waned 50%, thought it may slide up a bit.  But no.

I should have mentioned about the 0 to 3.3 volts, for once I knew something and neglected to share.
I will wait for the modified table and see if that does it.  Can’t thank you enough for doing this.

The nag in the PLC.  This is the message I get when I run it:

Compilation successful!
Output: "C:\Users\Craig\AppData\Local\Temp\leEAAF.mcc"
Lua: Error while running chunk

It didn’t look life threatening, so I just continued on undeterred.  I will attach the PLC file. 2 infact as not sure which is the one.

Thanks again Daz.  Need any help with boatbuilding?  Epoxy Resin?  Fibre reinforcement? Just ask.

Craig.