eberaud Posted February 16, 2017 Report Share Posted February 16, 2017 A few years ago I wrote my own equation computing algorithm for my company's flagship software. The user will write equations using variable names and constants (for example a=2*b+3), and those equations run continuously every 100ms. The pros The user can add Min and Max expressions inside the equation. For example a=Min(b,c)+2. The syntax supports parenthesis. For example a=3*(b+c). The limitations You can have several operators but their priority is not respected. For example the result of 1+2*3 will be 9 instead of 7. The user has to write 1+(2*3) or 2*3+1 to get the correct result. You can't put an expression inside a "Power" calculation. For example, you can do a+b^c but you can't do a^(b+c). You would need to create a new variable d=b+c and then do a+d, so now you have 2 equations running in parallel all the time instead of 1. There is no support (even though it wouldn't be hard to add) for sin, cos, tan, modulo, square root... I am now thinking of using a built-in LabVIEW feature (or one the community might have created ) in order not to reinvent the wheel completely. Surely I am not the only person who needs to compute equations. I looked at vi.lib\gmath\parser.llb\Eval Formula String.vi and it seems to answer 90% of my needs, it is simple to use, but it doesn't support Min and Max expressions and writing a hybrid system would be complicated. What do people use out there? If I need to reinvent the wheel, I found interesting resources such as https://en.wikipedia.org/wiki/Shunting-yard_algorithm and https://en.wikipedia.org/wiki/Operator-precedence_parser so I think I can pull it off, but it's going to be very time consuming! Cheers Quote Link to comment
smithd Posted February 16, 2017 Report Share Posted February 16, 2017 I've never used it, but doesn't this do that? http://zone.ni.com/reference/en-XX/help/371361J-01/gmath/eval_formula_node/ It says it supports the same syntax as the formula node which seems to include min max sine cosine etc. Might be worth trying it. Quote Link to comment
eberaud Posted February 16, 2017 Author Report Share Posted February 16, 2017 I tried, but no, Eval Formula Node.vi doesn't support min and max. Only the formula node supports it (along with modulo and remainder and others that I also need). Quote Link to comment
hooovahh Posted February 16, 2017 Report Share Posted February 16, 2017 My experience is also only with the evaluate formulas. I ended up augmenting it a bit with a few pre and post function calls for doing custom things. Quote Link to comment
Porter Posted February 16, 2017 Report Share Posted February 16, 2017 Have you taken a look at MuParser yet? http://beltoforion.de/article.php?a=muparser&p=interface Quote Link to comment
eberaud Posted February 16, 2017 Author Report Share Posted February 16, 2017 I haven't had great experiences with DLL in the past so I wanted to stay away from it Quote Link to comment
smithd Posted February 17, 2017 Report Share Posted February 17, 2017 9 hours ago, Manudelavega said: I tried, but no, Eval Formula Node.vi doesn't support min and max. Only the formula node supports it (along with modulo and remainder and others that I also need). Oh thats dumb. It looks like thats one of the few thats different from the formula node http://zone.ni.com/reference/en-XX/help/371361J-01/gmath/dif_pars_math_vis_formnode/ If you only need individual expressions and don't mind paying a little bit: http://sine.ni.com/nips/cds/view/p/lang/en/nid/21313 Quote Link to comment
Tim_S Posted February 17, 2017 Report Share Posted February 17, 2017 I have a bit of code that evaluates formulas. It has to run very fast, so the formula evaluation wasn't an option to me. The code takes the formula and converts it to a sequence of actions to perform... or, to put it another way it turns the "normal" infix formula into RPN. The evaluation is performed by iterating through the RPN formula using a "stack" (preallocated array of doubles). The initial infix to RPN is a time hit, but it's only once at the start. Quote Link to comment
eberaud Posted February 17, 2017 Author Report Share Posted February 17, 2017 I started implementing exactly what you're describing Tim. This RPN stuff is pretty neat Quote Link to comment
Steen Schmidt Posted February 23, 2017 Report Share Posted February 23, 2017 (edited) We have had such a toolset for a couple of years: http://www.gpower.as/downloads/expression-parser-toolset I have worked for almost 15 years writing math software for HP calculators, so I'm also keen on RPN ;-) It's not trivial to do a fully functional toolset like Expression Parser. Probably close to 1000 hours have gone into making it. From our website: Evaluate mathematical expressions, given as text strings, into numeric values: Build and change your math expressions at runtime. More than 260 math functions and constants supported. Very high performance. Supports any number of variables of any name. Supports VI Registers. Reports overflow if that occurs during evaluation. Supports all 14 numeric data types that LabVIEW offers, including complex evaluation. Offers special expression control like conditionals, piecewise defined functions, pulse trains, and defining your own custom periodic functions. Supported on desktop and real-time. Cheers, Steen Edited February 23, 2017 by Steen Schmidt Quote Link to comment
eberaud Posted February 28, 2017 Author Report Share Posted February 28, 2017 On 2/22/2017 at 11:15 PM, Steen Schmidt said: We have had such a toolset for a couple of years: http://www.gpower.as/downloads/expression-parser-toolset This is really nice! Koodos! Quote Link to comment
eberaud Posted March 1, 2017 Author Report Share Posted March 1, 2017 I tried to open the Expression Tester but it can't find one of the dependency... Quote Link to comment
Steen Schmidt Posted March 1, 2017 Report Share Posted March 1, 2017 12 hours ago, Manudelavega said: I tried to open the Expression Tester but it can't find one of the dependency... You need to upgrade the VI Register toolset to v2016.0.0.31. VIPM should have told you this (since that is a dependency of Expression Parser), but VIPM has been broken for a long while on many details. You can get VI Register v2016.0.0.31 either through VIPM (it's published on the LabVIEW Tools Network) or from our website here: http://www.gpower.as/images/downloads/viregister/gpower_lib_viregister-2016.0.0.31.vipc Cheers, Steen Quote Link to comment
eberaud Posted March 1, 2017 Author Report Share Posted March 1, 2017 Thanks, that fixed my issue, but now it is stuck on "starting expression tester, please wait" (or something similar) and I need to kill the LabVIEW process after a few minutes Quote Link to comment
Steen Schmidt Posted March 1, 2017 Report Share Posted March 1, 2017 1 hour ago, Manudelavega said: Thanks, that fixed my issue, but now it is stuck on "starting expression tester, please wait" (or something similar) and I need to kill the LabVIEW process after a few minutes Oh yes, that's a side effect of VIPM not making sure all dependencies are in order during the installation process. You want to either 1) uninstall and then re-install Expression Parser after its dependencies are in place (making sure mass compile is enabled in VIPM), or 2) manually mass compile the 'C:\Program Files (x86)\National Instruments\LabVIEW 2015\vi.lib\GPower\ExprParser' folder, whichever you prefer. All something VIPM should have done for you. The reason is that since you have updated a dependency (VI Register) after you installed Expression Parser it makes LabVIEW need to compile the Expression Tester when you launch that. For most LabVIEW code compiling on load is merely an annoyance that takes an extra few seconds, but for Expression Parser the matter is different. It's very complex code, which takes around 5 minutes to load an uncompiled Expression Tester for instance. The entire Expression Parser VI package takes around half an hour to build (so it's good only I have to do that). We made some improvements to the code architecture from the last version to this newest one, which improved VIP installation speed from 15 to 4 minutes. Still much too long for comfort. I have a much faster installing version here, but that one takes a 10% runtime performance hit which I'd like to get back before we release it. Quote Link to comment
eberaud Posted March 1, 2017 Author Report Share Posted March 1, 2017 Did the mass compile and everything works fine now Quote Link to comment
Porter Posted August 26, 2017 Report Share Posted August 26, 2017 Anyone interested in trying this out? Quote Link to comment
ensegre Posted August 27, 2017 Report Share Posted August 27, 2017 On 2/16/2017 at 7:37 PM, Manudelavega said: I tried, but no, Eval Formula Node.vi doesn't support min and max. Just mentioning, if not OT. Something else not supported are booleans (ok you could use 0 and 1 and + *). In a project of mine I ended up using this, which is fine but simplistic. I don't remember about performance; considering my application it may well be that simple expressions evaluated in less than a ms. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.