LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Machine simulation

Solved!
Go to solution

hi, I'm creating program for machine control. Application debugging process is not easy especially because it could be done with machine only. I'd like to create machine simulation VI. It takes all application outputs, calculate machine reaction and set application inputs accordingly. (The simulation algorithm will not be perfect of course but for initial testing very helpfull.) So I can make most of debugging easy without machine.

 

Aaand now my problem: how to read application outputs and write application inputs (IO variables both) ? Another problem is that with IO variables I'm not able to run application on development computer.

 

ALIASES solution: all "inputs" and "outputs" in application are single process variables. Special simulation VI read "outputs", makes simulation and writes "inputs". As soon as debugging process is finished I remove simulation VI and set all variables type to IO variable alias. But this is quite labour intensivewith hundreds of IOs especially if you need switch to simulation debugging and back several times. Is it possible to change variable type of many variables at once?

 

I'd like to know any ideas, experience etc how to do it better... another way...

 

Please keep in mind that my app "scan" time is circa 1-5 ms so the solution have to be performace lightweight.


*** LV2018 ***
0 Kudos
Message 1 of 10
(3,850 Views)

I'm not entirely certain what you're asking.  I have a few ideas but it's hard to know which if any apply to your needs.

 

Can you post a sample of what you're talking about?  Just a few (3-5?) cases should be enough, we don't need to see hundreds of them.

0 Kudos
Message 2 of 10
(3,823 Views)

Heard of NI Multisim before?

You can design entire analog and digital systems on here and use it to simulate your machine.

0 Kudos
Message 3 of 10
(3,810 Views)

Kyle97330:  see example below. It's a simple example to demonstrate problem and explain what I'm asking for.

 

Example.vi - simple app to start engine with feedback (engine is running, engine failure). But the IO variables are not valid i.e. app can be run ONLY with appropriate hardware (IO cards, electric part, engine itself). I'd like to test my app without I/O etc. This could be done by replacing IO variables by simulating subsystem see Example2.vi. That way I can run app without hardware and test it.

 

And now 2 questions:

- is it possible easily switch between IO variables and simulating system somehow ? without need to rewrite big part of app?

- any other way to do such a simulation ???

 

 

kingehp: frankly I don't know Multisim. It seems to me a complicated way to do what I want. And I'm not sure it's suitable...


*** LV2018 ***
0 Kudos
Message 4 of 10
(3,774 Views)

I have done similar things before.

 

Rather than having them ship a 200 HP diesel engine to me and install it in my 14x14 office, I built an engine simulator, from code.

 

It's a software black box, with THROTTLE and DYNO SPEED inputs, and SPEED and TORQUE outputs.

 

I set a conditional symbol called DUMMY ENGINE, and when that is true, every sample I generate to drive the THROTTLE and DYNO SPEED goes to the AO output *-AND-* to my dummy engine code.  The dummy engine does a rough simulation to produce new SPEED and TORQUE values, and I replace the samples I measured, with the simulated ones.

 

It still goes through the AO and AI stages, but the actual values resemble a real engine, so that the PID logic and other logic can function reasonably.

 

In your case, I would have a single VI that updates all outputs, and another VI that collects all inputs.

You should shield ALL your other code from knowing the details about how the outputs happen.  That's good practice, even without a simulation.

There should be ONE place that handles the details of getting the signals OUT.

There should be ONE place that handles the details of getting the signals IN.

 

 

Use a conditional symbol to switch from calling the REAL output VI to calling the DUMMY output VI, and from calling the REAL input VI to calling the DUMMY input VI.

 

In either the dummy IN or OUT vi, put code that simulates whatever you're driving, and produces simulated responses.

 

The more code you can put outside of those dummies, the better your chances are when you turn OFF the simulation.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 10
(3,725 Views)
Solution
Accepted by topic author petrnowak

is it possible easily switch between IO variables and simulating system somehow ?

The short answer is YES, if you have organized it correctly.

 

The CONDITIONAL DISABLE structure will do that for you.

 

Basically, it's like a CASE structure, except the case SELECTOR is a symbol that is determined at COMPILE time.

 

In your project, pop up on the TARGET and select PROPERTIES.

 

Choose the CONDITIONAL DISABLE SYMBOLS category.

 

Enter SIMULATED ENGINE or something in the NEW SYMBOL box, and TRUE in the NEW VALUE box, and then click ADD.

 

Now you have a new symbol to use.

 

Place a CONDITIONAL DISABLE box on your code, around the part that should be disabled if you're simulating.

 

That will be your default code - the NON-simulated portion.

 

Pop up on the structure and choose ADD SUBDIAGRAM AFTER.

 

The CONDITION for this case should be SIMULATED ENGINE == TRUE.

 

Now put your simulation code in that case.

 

You can have as many of these as you want - they will all switch when you change the SYMBOL value.

 

Remember, this is at COMPILE time, not RUN time,  Your code will contain ONE case or the other, but not both.

 

You DON'T want to put one around every I/O variable, that just clutters up the diagram.  Put all your INs in one place, and conditionalize that, and put all your outs in another place and conditionalize that.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 6 of 10
(3,714 Views)

Great. That works.

I'd like to run IO version on target and simulate version on my development PC (so without target HW). And avoid diagram disable sctructure. That could be done:

Create two libraries with variables; one library has variables for simulation (single process variables), the second one has variables - IO aliases; corresponding variables have identical names; both libraries has the same name (therefore one of them should be saved in different directory e.g. subdirectory of main project directory);

IO aliases library is placed under target in project tree;

Single process variables library is placed under My computer in project tree;

Application refers to variables via variable nodes;

Now I simply drag my main app VI from RT target to My computer and back; library is referenced relatively to project tree so LV uses IO aliases library when under target, or it uses single process vars library when under My computer in project tree;

That way I can avoid diagram disable structure completely. Tested and works.

 

Do you see any problem with this method ?

 

 


*** LV2018 ***
0 Kudos
Message 7 of 10
(3,682 Views)

Why is avoiding the CONDITIONAL DISABLE structure a goal?

 

It's a legitimate way of selecting one version from a collection of two (or more) versions.

 

The problem I see with your approach is that it's not clear (to me, anyway).

 

If you look at this code a year from now, will it be clear how to put it back into simulation mode?  It should be.

 

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 8 of 10
(3,672 Views)

Dear Mr. Nowak,

I think you are talking about diagram disable structure while Steve talked about conditional disable structure. The second one is very useful if you need to switch cases globally (for example before the compilation) on the project level. There are some predefined symbols but you can also add user-defined symbols.
Here is small example: http://screencast.com/t/TqaxDppB

 

Ondřej K.

NIEE AE

CLA, CTA, CLED
Message 9 of 10
(3,637 Views)

okubik: I fully understand difference diagram vs conditional disable structure.

 

CoastalMaine: yes, you're right the use of conditional structure is much clear than library variables from the understanding point of view. However any changes in variables type means digging deep into code and looking for all instances. One way or another I'm in stage of creating my "LV frawework". So I don't know what method I use finally...

 


*** LV2018 ***
0 Kudos
Message 10 of 10
(3,545 Views)