LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to simulate large-scale non-linear systems using the Simulation Toolkit?

Hi,

I am new to LabVIEW, having used Matlab/simulink for a few years. I am trying to simulate a relatively complex non-linear vehicle model. In Matlab/Simulink I would use an m-file to describe the system equations (i.e. x1_dot=..., x2_dot=..., etc.). Is there a similar method in LabVIEW? I have got a simple simulation running using the 'eval formula node', a very ungainly method of substituting variables, and an integrator in a 'simulation node'. It takes about an hour to run a simulation that takes 3 seconds in Matlab. I just need to know if it is realistic to do large-scale simulations in LabVIEW, or if it was not designed for that and I should persuede the management to go
back to Matlab!!!

If it is possible, where can I find help on the subject? I have spent a long time looking on the web and come up with very little.

Many thanks in advance,

Paul.
0 Kudos
Message 1 of 6
(2,881 Views)
Hi Paul -
If you are referring to "Eval Formula Node.vi", then it is parsing your formula on each iteration of the simulation (this is bad - the VI in question is intended more for "one shot" formula evaluation).

There are some much better options for you in LabVIEW:

1) The formula node (in the structures palette) - this should do the parsing at edit time, and hence should run much faster. (and you can put multiple formulas in it, similar to a simple m-file)

2) If you must use the Eval Formula VIs - you should use the advanced formula parsing VIs - there is a pair that should be used together (Parse Formula String and Eval Parsed Formula). This way you can do the parsing up front (outside of the actual simulation) and speed up the result.

Hope tha
t helps! - if not you might want to follow up with a little more information about your system (how many variables you are integrating, what solver parameters you are using, etc.)

cheers,
- kevin
0 Kudos
Message 2 of 6
(2,881 Views)
If these are simple differential equations, easiest would be a for loop with a bunch of shift registers, one for each x1, x2, etc. containing the current values.

In your case, you would calculate all the derivatives from the instantaneous values inside the loop, then add them to each value before feeding them to their respective shift register again.

The attached very simple example shows how to generate an exponential decay function using the formula dx/dt= kx (and k is negative). The shift register in initialized with the starting condition x=1.
0 Kudos
Message 3 of 6
(2,881 Views)
Kevin and Altenbach,

Thank you for your suggestions. Basically, I am trying to develop a program where the user can enter variables on the front panel (there are currently 78 variables) relating to vehicle suspension parameters and geometry, then simulate the system (14 system states). I can't use a simple formula node, as the variables are changing, so I have to use 'parse formula string' etc.

Unfortunately, for some reason you are only allowed a limited set of variable names in the formula nodes, so I have to use the 'substitute variables' vi to convert the meaningful variable names in my equations into 'a0,a1,...'.

It makes sense that it was running slowly because it was parsing the formula at each time step, and I tried to change it to a 'parse formul
a string' and 'eval parsed formula string' layout (which cannot parse more than one equation as far as I can see, so I need 14 of them), but now I get some very useful error messages like 'Wrong variable name' or 'variables output error', even though I have checked these.

The whole thing is getting a bit messy, and debugging seems very difficult (even 'single stepping' through doesn't seem to help track down where the errors are occurring).

Any suggestions?!?

Thanks again.

Paul.
0 Kudos
Message 4 of 6
(2,881 Views)
Hi Paul -
Now I understand a little better - if the formula does indeed change between runs you need something that will change with it at run time, and the formula node VIs may be your best option.

I think I steered you a little bit wrong on the advanced formula parsing - if Eval Formula Node was working for you before, try using Parse Formula Node and Eval Parsed Formula Node - should be exactly the same inputs and outputs as Eval Formula Node, with a wire connecting the piece that parses and the piece that evaluates - you should get no more errors than you would have in the first place, but end up running faster.

Let me know how that works for you.

cheers,
- kevin
0 Kudos
Message 5 of 6
(2,881 Views)
Thanks Kevin - it has help a lot (now down to 6 minutes for a 10s simulation). It still seems a bit slow though. I am wondering if it is being caused by another part of the program.

As I have a large number of input variables on the front panel I have created references to them all, and group the references into a single array that I can pass to a save function, load function, and the simulation.

I have noticed that when the simulation finishes (I have it set up so I press a 'run' button to start the simulation), the processor usage is still at 100%, and if I highlight execution the program is continually making the array of references. Is it possible that this array is continually being made while the simulation is running, slowing it down? I ha
ve tried to make the array only when it is needed (i.e. immediately before saving or loading the front-panel data, or before the simulation runs) but I can't seem to get it to work. Should I try an event-driven approach?

Sorry for the long-winded question!

Many thanks,

Paul.
0 Kudos
Message 6 of 6
(2,881 Views)