LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to interface a simulink model in an easy way using LabVIEW 2009 and SIT ?

Solved!
Go to solution

Hi,

 

I finally found a way to use a simulink model with LabVIEW and the SIT toolkit, but I'm not satisfied with it.

If you have any suggestion, ressource link that I would have missed, please feel free to answer

 

Note that I don't know much about simulink, so that if my question sounds stupid, let me know it is 😉

 

Software configuration

 

OS : Windows (not an RT target)

LabVIEW 2009

SIT 2009

 

1st question: interfacing the model DLL (mapping considerations) with a driver VI

 

We created a model DLL using the "Real-time workshop" tab in simulink.

In LabVIEW, we launch the "SIT connection manager" tool and try to use the DLL with a driver VI by mapping the model I/Os to the VIs controls/indicators.

 

The fact is that I do not manage to connect model I/Os to my VI controls/indicators since they don't appear in the mapping dialog box.

The only simulink objects I managed to map are "constants" and "test points" so that I need to modify the simulink model itself (example shown below)

 

simulink mapping.JPG

 

Are model I/Os not considered as being part of the model parameters ? (this could make sense since the mapping actually states it operates on "model parameters")

Is it possible to link model I/Os to VI controls/indicators ?

 

Note :

- the "Configure HW I/O Mappings" dialog box lets me map model I/Os with HW I/Os...

- Examples provided also use these "constants" and "test points"

 

2nd question: direct use of the SIT VIs

 

I tried to use the model DLL directly with the SIT VIs (code example shown below)

This kind of code is working nicely on another project (LV 8.0/RT target) but not on the current project (LV 2009/Windows)

 

The second step of the model never finishes:

- loop index 0 works as expected (model doing his job),

- loop index 1 starts as expected, but the execution is stucked in the "SIT scheduler.vi"

 

I then have no other choice than killing LabVIEW ("Resetting VIs" windows showing up if I try to stop/close them).

 

model DLL and SIT VIs.png

 

Is there any reason that I don't see that explains this behaviour ?

 

Thanks for reading.

Any help appreciated.

 

Regards,

Message Edited by Mathieu Steiner on 02-07-2010 03:00 PM
0 Kudos
Message 1 of 14
(10,617 Views)

First question may be related to this: source

Models Using Signal Storage Reuse, Block Reduction Optimization, or Virtual Blocks

Mappings might appear invalid if the model uses either Signal Storage Reuse or Block Reduction Optimization. These items are options you can set in the Simulink application software to reduce the memory footprint of the model. Disabling these options for the entire model makes all signals available for probing but increases the memory footprint of the model. You can mark individual signals as test points to maintain a reduced memory footprint while keeping certain signals available for probing. To make this change, load the model in the Simulink application software and perform the following actions:

[...]

For the MATLAB® application software release 14 and later, right-click a signal and select Signal properties from the shortcut menu. Click the Logging and accessibility tab, place a checkmark in the Test point checkbox, and click the OK button to save changes.

0 Kudos
Message 2 of 14
(10,575 Views)

For question 1:

Review the help topic for Creating Mappings:

http://zone.ni.com/reference/en-XX/help/371504E-01/lvsitconcepts/sit_c_creating_mappings/

 

In particular the section Models Using Signal Storage Reuse, Block Reduction Optimization, or Virtual Blocks in Fixing Invalid Mappings

 

You can connect any signal in the model to an indicator in the LV VI as long as that signal has not been optomized away.  One way to avoid it being optomized is to add test points, the other is to turn of all optomizations.  Especially Signal Storage Reuse tends to lead to signals not being available.

 

You can connect any parameter to a control in LV.  The value of a constant is a parameter.  Inports and outports do not have parameters.

 

You can connect the the inports and outports of your model to hardware in the driver VI, through the "Configure HW I/O Mappings" dialog box as you already found.   You can not connect inports and outports to controls and indicators.  For signals, mappings are done by the source.  An outport is not a source.  Instead if you want to view the outport signal you can map your control to the source of the signal (in your second model that is the summer block).  Inports can not take a value from both the UI and from the hardware, there fore it can only be mapped to hardware.  If you know that your inport will always be mapped to the UI you can replace it with a constant.  If it will sometimes be mapped to the UI and sometimes mapped to hardware you can use the method of a constant with a summer block, as you have done in your second model.

 

For question 2:

Review the driver VI that is generated by the SIT Connection Manager in SIT 2009 (LV 2009).  It is slightly different from the one in SIT 3.0 (LV 8.0).  You can still do the same thing, you just need to adjust your code.

 

Carl L

National Instruments 

Message Edited by Carl L. on 02-08-2010 10:50 AM
0 Kudos
Message 3 of 14
(10,572 Views)

Hi Mathieu,

 

For your first question, you should add a Signal Probe block to your Simulink model.

Then, for mapping to parameters or signals, please read the SIT section in LabVIEW help.

You will find in SIT How-to section and Configuring a Simulation, all the steps for mapping parameters and signals, without the need of using probes.

 

For your second question, I don't have any idea yet.

Please send your VI and the dll of your model for me to test it. Which version of Matlab are you using?

Then, do not hesitate to open a SR calling us directly.

 

Regards,

Olivier L. | Certified LabVIEW Developer


0 Kudos
Message 4 of 14
(10,570 Views)

Carl, Olivier,

 

Thank you for confirming the first point.

Too bad we cannot map models I/Os the SW but only to HW. Any reason for that ? (the reason why I'm asking is that my customer doesn't like to modify the model...)

As a newbie, I was expecting this to be possible Smiley Surprised

 

Concerning the code that is scripted by the 'SIT connection manager', I will need to dig into it... (and read the F* help manual ) Smiley Tongue

 

Regards,

Message Edited by Mathieu Steiner on 02-08-2010 06:05 PM
0 Kudos
Message 5 of 14
(10,565 Views)

The problem with mapping from both SW and HW is that it can't get the value from both at the same time.

 

A simple way to avoid modifying the customer model is to simply create a wrapper around the customers model.  Use a linked subsystem so it updates if the original model changes.  Add constants for all the inports.  When you use the model with SIT, you build the model using the wrapper, when using it for any other purpose then use the original model.

 

Carl L

National Instruments

0 Kudos
Message 6 of 14
(10,538 Views)
Solution
Accepted by Former NI Employee MS

Hi,

 

I spent some time analyzing the driver VI as you suggested.

Here are my conclusions.

 

Question 1: the SIT connection manager does not allow to map model input with SW controls/indicators. It only allows the user to map HW AIs/AOs.

 

The only solution I found (to have a SW object - e.g a shared variable -  mapped to a model input/output) is to customize the driver VI that is scripted by the SIT connection manager ("<model_name>_Base Rate Loop.vi" in the flat sequence structure named "read code")

 

Question 2: after having spent some time in the driver VI, it appears that the right VI to call is not "SIT scheduler.vi" but "SIT Take Model Time Step" (that uses the other as a SubVI)

 

Working SIT.png

 

Are my conclusions correct ? If I'm using the API the wrong way, please let me know.

 

Regards,

Message Edited by Mathieu Steiner on 02-15-2010 10:01 AM
0 Kudos
Message 7 of 14
(10,486 Views)

Hi Mathieu,

 

How this topic is about mapping signals between Simulink model and LabVIEW, I hope this can be the correct space to ask Smiley Indifferent


Basically, I need to send control data from Simulink to LabVIEW model, and give back resulting data to Simulink to complete the closed loop control in this way.

 

Is that possible to do??

 

Software configuration

 

OS : Windows (not an RT target)

LabVIEW 8.6

SIT 5.0

 

To be more clear I hope the pictures of the next example help.

 

P control in Simulink:

 

ctr_Simulink.JPG

 

And a simple model in LabVIEW:

 

model_LV.JPG

 

I am not sure if SIT could help me in this issue, and that's why I've decide to ask you. Maybe is not necesary to use the SIT, but at the moment I don't have another idea.

 

So far I've only conected LabVIEW controls with model parameters of Simulink bolcks and LabVIEW indicators with model signals of Simulink, and that not solve my issue.

Thank you for reading.. Smiley Wink

Any help appreciated.

 

Regards

 

Fabian León
Certified LabVIEW Associate Developer
0 Kudos
Message 8 of 14
(10,392 Views)

Sorry, the simple model in LabVIEW is this:

 

model_LV.JPG

Fabian León
Certified LabVIEW Associate Developer
0 Kudos
Message 9 of 14
(10,373 Views)

 

Question 1: the SIT connection manager does not allow to map model input with SW controls/indicators. It only allows the user to map HW AIs/AOs.

 

The only solution I found (to have a SW object - e.g a shared variable -  mapped to a model input/output) is to customize the driver VI that is scripted by the SIT connection manager ("<model_name>_Base Rate Loop.vi" in the flat sequence structure named "read code")

 

 ------------------------------------------------------------------------------------------------------------

 

Would I Know, how I can customize the driver VI that is scripted by the SIT connection manager? In particular there is an example where i can see How modify ("<model_name>_Base Rate Loop.vi" in the flat sequence structure named "read code").

 

Thanks a lot

 

barciuz 

 

 

0 Kudos
Message 10 of 14
(10,037 Views)