Hello Guest it is March 28, 2024, 11:09:44 AM

Author Topic: Lua programming of voltage meter  (Read 5733 times)

0 Members and 1 Guest are viewing this topic.

Re: Lua programming of voltage meter
« Reply #10 on: February 17, 2018, 12:24:54 PM »
Hi,
that code looks to have the 57E device read an analogue voltage and convert it to digital. Then Mach takes that digital value and converts it into
a PWM, ie an analogue voltage and output it. Why?

You want an onscreen voltmeter do you not?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Lua programming of voltage meter
« Reply #11 on: February 17, 2018, 12:58:51 PM »
Craig, yes I do want an onscreen voltmeter.  I realize now that that code is making a PWM but could I just change the code but using the reading and writing to the register to make it work? 

I do see the voltages in the register diagnostics so I know it is set up correctly.  I just have to get the LUA code correct and into a meter.
Re: Lua programming of voltage meter
« Reply #12 on: February 17, 2018, 02:25:18 PM »
Hi,
if you have a register with the numeric representation of the input voltage that's all you need.

The problem you have is that the on-screen voltmeter has a preprogrammed range of data sources and your register is not one of them. In fact
no registers are in the list.

What I was proposing was that you cheat. Use the register value that you want to display to populate one of the variables that IS on the list.
May I suggest 'C SoftLimit+'. You could repeatedlty write a new value to the C axis positive softlimit and the display that softlimit as is provided
in the Code list for the onscreen voltmeter.

A sketch, this is in the PLC script:
1) Get the register value
2) Set the C softlimit value  with mc.mcAxisSetSoftlimitMax()=register value

I don't know that it would work but its the only way I can think of that you can make the onscreen voltmeter display a register value.

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 programming of voltage meter
« Reply #13 on: February 17, 2018, 03:11:24 PM »
The Meters can be set using the "scr" class functions,

Lets assume you have you register sorted and have assigned a it to a local value as it shows in the pokeys manual from page 31 onwards.

All you need to do now is send that value to the meter, if say for instance your meter is called amtr and you want to set it to 75 then use scr.SetProperty("amtr","Value","75")

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Lua programming of voltage meter
« Reply #14 on: February 17, 2018, 03:20:43 PM »
Hi Daz,
kool that makes it easy. Just put the 'scr' assignment function in the PLC script.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Lua programming of voltage meter
« Reply #15 on: February 17, 2018, 04:08:51 PM »
Thanks guys I will see if I can make it work!
Re: Lua programming of voltage meter
« Reply #16 on: February 18, 2018, 09:29:52 AM »
Got 4 meters working great.  Key was that the CNC4PC configuration setup for the Pokeys57E already has registers going for the 4 analog inputs.
I realized that the pin setups were correct once I could see the voltages active in the reg diagnostics for the Pokeys device in Mach4.
Next, with help of the LUA Scripting Guide showing how to read register values, I read each value using the following function placed in the Screen load script.
The labels used to access the registry were listed in the registry diagnostics "CNC4PCMotionDevice" and the name of each input "Analog input 41" was there too.

function ReadAnalog(regname)
    local inst = mc.mcGetInstance()
    local hreg = mc.mcRegGetHandle(inst, string.format("CNC4PCMotionDevice/%s", regname))
    return mc.mcRegGetValueString(hreg)
end

Then in the PLC script I put a pair of lines for each of the 3 meters changing the values 41,42,43,44 or the Pokeys pins for each analog input.  Each meter was setup in the screen with labels Meter1, Meter2, Meter3 etc.

    regval=ReadAnalog("Analog input 41")
    scr.SetProperty("Meter1","Value",regval)

The PLC is now updating the meters realtime but I put it all in a do loop if (machEnabled == 1) then update the meters so it only updates when Mach is enabled.

Happy now!

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Lua programming of voltage meter
« Reply #17 on: February 18, 2018, 12:25:20 PM »
Loops in the PLC are bad, try a simpler way.

if machEnabled == 1 then
-- update meters
end

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Lua programming of voltage meter
« Reply #18 on: February 18, 2018, 01:06:00 PM »
Daz

Thanks, that is what I did.

However I added a loop to sum the values every 20 sweeps then updated a second guage with average per second.

Is there an easier way to average?
Re: Lua programming of voltage meter
« Reply #19 on: February 18, 2018, 01:08:06 PM »
Actually no loops just if then else