Hello Guest it is April 24, 2024, 06:02:47 AM

Author Topic: Is there a trick to updating registers? what am I doing wrong  (Read 941 times)

0 Members and 1 Guest are viewing this topic.

Re: Is there a trick to updating registers? what am I doing wrong
« Reply #10 on: March 07, 2023, 03:14:17 PM »
Hi,
I hope I'm not belabouring the point or trying to 'teach my Grandmother to suck eggs' but we have a perfect example of one of Lua's strengths right here.

All Lua variables are a table. The syntax for addressing a table is the name of the table followed by a period followed by the name of the entry in that table.

I'm more familiar with FORTRAN and C and the elements of an array are sequentially numbered integers 0,1,2, etc. In Lua however an entry name may be a number or
a string and any mixture thereof.

As an example:

mc = the name of the table
X_AXIS = Name of an entry in the table
mcJogSetRate() = Name of an entry in the table.

Note the one entry, namely X_AXIS equates to just a number. in this case 0. The other entry, namely mcJogSetRate() is a function. Thus the entries in any given table
my be a mixture of strings, numbers or functions. Compare that to C where all elements in the array must be of the same type, say float.

This is a perfect example of the principle of 'a function as a first class value', that is to say a function can be bandied about as if its just a number.....extremely handy
and much of Lua's flexibility comes from use and re-use of that property.

The 'mc' table must be huge. Think of all the APIs like mc.mcJogSetRate() and the many hundreds like it, mc.X_AXIS and many dozens of other numeric assignments
including mc.ISIG_INPUT43 for example.

Again apologies for hijacking the thread but this property of Lua intrigues me greatly.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #11 on: March 11, 2023, 01:15:23 PM »
Code: [Select]
        --Jog Axes accordingly

rc = mc.mcJogSetRate(inst, 1, jogVelX);
rc = mc.mcJogVelocityStart(inst, 1, xAxisDirection);
rc = mc.mcJogSetRate(inst, 2, jogVelY);
rc = mc.mcJogVelocityStart(inst, 2, yAxisDirection);

What values do you have for jogVelX and jogVelY as mc.mcJogSetRate is a % of maximum motor velocity?
Also, you have the values for the X and Y axis incorrect. X axis is 0 and Y axis is 1. Alternatively you can use mc.X_AXIS and mc.Y_AXIS

Good catch!! I was using a fraction (.50 instead of 50) for the jogVelX as the analog inputs from the Pokeys are automatically scaled to a max of 1 and a midpoint (if potentiometer) of .5.  That should be an easy test to fix.

For the X and Y axes, I have used a number of variations of mc.X_AXIS, numbers and mc.mc.X_AXIS in various tests.  My intention was to get mc.X_Axis to work.  let me look at my code again
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #12 on: March 11, 2023, 01:24:57 PM »
Hi,
I hope I'm not belabouring the point or trying to 'teach my Grandmother to suck eggs' but we have a perfect example of one of Lua's strengths right here.

All Lua variables are a table. The syntax for addressing a table is the name of the table followed by a period followed by the name of the entry in that table.

I'm more familiar with FORTRAN and C and the elements of an array are sequentially numbered integers 0,1,2, etc. In Lua however an entry name may be a number or
a string and any mixture thereof.

As an example:

mc = the name of the table
X_AXIS = Name of an entry in the table
mcJogSetRate() = Name of an entry in the table.

Note the one entry, namely X_AXIS equates to just a number. in this case 0. The other entry, namely mcJogSetRate() is a function. Thus the entries in any given table
my be a mixture of strings, numbers or functions. Compare that to C where all elements in the array must be of the same type, say float.

This is a perfect example of the principle of 'a function as a first class value', that is to say a function can be bandied about as if its just a number.....extremely handy
and much of Lua's flexibility comes from use and re-use of that property.

The 'mc' table must be huge. Think of all the APIs like mc.mcJogSetRate() and the many hundreds like it, mc.X_AXIS and many dozens of other numeric assignments
including mc.ISIG_INPUT43 for example.

Again apologies for hijacking the thread but this property of Lua intrigues me greatly.

Craig

Exactly, I like this property myself, especially if dealing with data from a variety of sensors or inputs.  Building data structure arrays is a time consuming process in C.

As the thread initially states, I have been unsuccessful at reliably writing anything to registers (obviously due to some flaw in my code/understanding of the mach registers)).

Are the registers (iRegs, etc...) actually also simply entries in a LUA table as well?  Or are they global variables? They seem too flexible to be actual firmware registers to me, but then again that level of detail is past my knowledge.
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #13 on: March 11, 2023, 02:48:45 PM »
Hi,

Quote
Are the registers (iRegs, etc...) actually also simply entries in a LUA table as well?  Or are they global variables?

They are certainly global variables and the only way to export data from one Lua chunk to another chunk. What I cannot tell you is whether they are a fixed location,
I suspect they are. As you know most Lua variables are dynamically allocated and throughout a session will be created and destroyed many times. As such the
'handle' for a given variable will vary, however my guess is that registers are fixed.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #14 on: March 11, 2023, 05:19:21 PM »
Hi,

Quote
Are the registers (iRegs, etc...) actually also simply entries in a LUA table as well?  Or are they global variables?

They are certainly global variables and the only way to export data from one Lua chunk to another chunk. What I cannot tell you is whether they are a fixed location,
I suspect they are. As you know most Lua variables are dynamically allocated and throughout a session will be created and destroyed many times. As such the
'handle' for a given variable will vary, however my guess is that registers are fixed.

Craig

Then i am definitely either doing something wrong, or my user registers are corrupted.  Is it possible that there are duplicated handles? The register diagnostics shows a value, but if i read it back it gives nil. 

I had identical problems with a number of my VFD registers.  It almost looks like some of them got duplicated (below the handle abstraction level).

Do you have a code snippet that writes to and reads back from a register that i can try (on a new register and an existing one)?

I’m wondering where the definitive list of registers is.  I checked the machine.ini and there is only one entry for each register. 

 
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #15 on: March 11, 2023, 07:22:50 PM »
Hi,
I have attached a couple of screen shots from my machine. The first are entries in the SigLib  table where a given input, a servo alarm for instance, will cause an Estop
but also write to a register. The second shot is of the Register Diagnostics. Note that the servo alarms are so seldom, if ever, triggered are not especially interesting,
but the AXIS1, AXIS2 reflect the status of the axis select switch on my pendant, which in turn informs Mach of the axis to jog and puts that in another register
just call AXIS and has a number, 0,1 or 2 depending on the axis to be jogged. Note that these values are live, that is to say whenever I flick the three position toggle
switch to select an axis to jog the registers update. I've been using this scheme for months and it works perfectly. If the registers were misbehaving then my pendant would be
misbehaving also,yet it is not.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #16 on: March 11, 2023, 07:24:09 PM »
Hi,
sorry the excerpt from the SigLib table is not a screen shot but rather a text file.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #17 on: March 12, 2023, 03:23:42 PM »
Hi,
sorry the excerpt from the SigLib table is not a screen shot but rather a text file.

Craig

Cool, thanks.  I’m definitely thinking that i did something wrong somewhere. As a wise electrical engineer once told me “the electrons always to to the right place, maybe just not where you wanted them to!”
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #18 on: March 13, 2023, 03:40:43 PM »
hmm,

I don't see anything different about how you are doing the register access than me.  Perhaps my registers got corrupted somehow.  Is there a way to rebuild the registers (like from the ini file or something?)
Re: Is there a trick to updating registers? what am I doing wrong
« Reply #19 on: March 13, 2023, 03:51:35 PM »
following along the "corrupt registry" thought, here is my machine.ini file