LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript RT node define and update variable without shift register?

Is there a method for defining and updating a variable inside a MathScript RT node without using a shift register?  Something like this except that it would actually run:

error after first iterationerror after first iteration

I had a couple ideas but they didn't work:

  • Defining 'a' as global - can't use global on Real-Time system
  • Defining and saving 'a' outside this loop, then use load and save inside while loop - runs way too slow

The reason I don't want to use a shift register (like with variable 'i') is that the actual script will have a lot of arrays and variables.  I'd like to avoid "mapping" the variables to the arrays in order to pass their values to the next iteration. 

 

Any suggestions?

0 Kudos
Message 1 of 5
(2,006 Views)

Is there a specific reason for using the Mathscript node to do array math?  Switch everything over to Labview primitives and throw it all into a subVI. Make use of the auto-indexing functionality of for loops, along with shift registers for storing values between loop iterations.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 5
(1,997 Views)

j_lewis,

 

I don't quite understand your reasoning for why you don't want to use shift registers. Do you mind elaborating a little more?

 

If you want to store values locally in a RT system and then access them, this link covers the different methods.

 

Keep in mind that if you want to maintain determinism, you should use a Single Process Shared Variable with RT FIFO enabled (either single element or multi-element), or an RT FIFO. Generally, the Shared Variable will be easier to implement but the RT FIFO allows dynamic configuration and faster execution speeds. 

 

Best,

BrandonN

Applications Engineer 

 

 

0 Kudos
Message 3 of 5
(1,995 Views)

A quick description of this system is that it will read 4k values, perform a few hundred different calculations, then transmit/log about 500 values.  It will run on a PXIe RT controller at 10ms.

 

MathScript RT was chosen as the method for performing the calculations (over primitives, formula nodes, etc.) because a .m script will be easier to read and maintain outside LabView.

 

Ideally, I would like to input my 4k values as an array into a MathScript Node and output the array of 500 values.  What I've run into is that most of the calculations require variables to retain their values from one iterate to the next.  The only method I know of is to output the variable and use a shift register.  Due to the number of different variables, this would be a sizable effort.  I can clean it up by mapping all the variables to an array, but again a very sizable effort.

 

The method I'm trying to develop is to populate the "workspace" on the first iteration with all the variables, then use that workspace to retain the values for subsequent iterations.  It seems like this is what is happening in the MathScript Window but I can't figure out how to do it in the Node. 

0 Kudos
Message 4 of 5
(1,941 Views)

@j_lewis wrote:

 

MathScript RT was chosen as the method for performing the calculations (over primitives, formula nodes, etc.) because a .m script will be easier to read and maintain outside LabView. 


OTOH, a pure g version will be much more efficient and fast. How complicated are these "calculations"? Purely graphical code has many advantages, such as the ability to do certain calculations in parallel.

 


@j_lewis wrote:

The method I'm trying to develop is to populate the "workspace" on the first iteration with all the variables, then use that workspace to retain the values for subsequent iterations.


Why can't you use the looping within the mathscript node directly? Obviously, we don't quite have all the details of what you are trying to do.

0 Kudos
Message 5 of 5
(1,930 Views)