0

I need some help in creating a VI that generates virtual or calculated channels based on several channels I measure.

e.g. I measure voltage on several AI, lets say, ch A,B,C,D,E were B,C and E represent current on a shunt and would like to calculate a the power of the system

Q[A] = B+C
R[W] = A*Q
S[W] = D*E
T[W] = R+S

I would like to load the equations externally from a configuration file that may vary from one project to another equations would come in a format of a string Q=A+B , R= A*Q ..... *(during a run equation and channel count don't change - only when loading config).

The main issues that I am facing is that the inputs to each equation may have dependencies on virtual channels that do not have data yet

Was trying to use: formula nodes/ Math scripts: https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/formula_nodes/ https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000x30HCAQ&l=en-IL

All data that should be chunked into a data stream (continues sampling) that can be presented on a Chart/Graph and saved to CSV/TDMS

  • do I need some additional packages?

I have tried the following based on the the example given - getting strange result

enter image description here

enter image description here

kosist
  • 2,868
  • 2
  • 17
  • 30
Assaf Baker
  • 151
  • 1
  • 1
  • 8

1 Answers1

1

Answer

The elements you are looking for are not the Formula/Math Nodes but rather the:

Formula Parsing VIs

Parsing Nodes in the menu

Using these VIs you are able to pass a calculation in the form of a string and an array of variable names and then evaluate the formula. This allows for run-time variable scripting, where most other nodes require compile time formula evaluation (With the exception of the python node).

Example

Example of using a very simple program to evaluate two different calculations using the same values and variables. Front panel of evaluation Block diagram of evaluation

Steve
  • 963
  • 5
  • 16
  • thanks but would it support a continues analog input ? was not able to add so – Assaf Baker Jun 30 '21 at 21:19
  • If you want to run this continuously, the only step would need to be to add a WHILE loop around the 'Eval Parsed Formula' with changing values going into the Input values array. Will edit solution. – Steve Jun 30 '21 at 22:07
  • see my updated question please i have tried some formula calculation based on the example but the results don't update correctly getting the same result on the 2 outputs – Assaf Baker Oct 06 '21 at 13:00
  • @AssafBaker Having a deeper look into this reveals some oddities. Tracked down the issue you are seeing to brackets being introduced from the Substitution. If you open up 'Parse Formula Node' you'll see that the VariablesOutput is not connected to anything. Basically, **Don't even bother with output variables, just put a variable on the left of the equals and the output will be the same** However this requires more explanation than a comment can handle. For more info open a new question. – Steve Oct 06 '21 at 18:32
  • Steve, please see the following. (Thanks) https://stackoverflow.com/questions/69476154/dynamic-equation-calculation-for-multiple-channels – Assaf Baker Oct 07 '21 at 06:04