LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Matlab/Simulink Models on LabVIEW

Hi,

 

I am hoping to get some suggestions on how I can achieve the following.

 

I have a host PC that runs LabVIEW, and another PC (target PC) that runs Matlab/Simulink models.   I am using LabVIEW on the host PC mainly for data acquisition, monitoring, data logging etc.  I am trying to implement closed loop control algorithms, which are Matlab/Simulink Models on the target PC,  and access them on the host PC.  I have a PXI, which I can use if required.

   

 

Can someone please tell me how I can complete this setup and what tools I require?

 

Thanks in advance.

0 Kudos
Message 1 of 10
(5,634 Views)

To compile and run a Simulink model you'll need:

  • N.I. Simulation Interface Toolkit
  • LabVIEW Realtime, in your case on a PXI controller (8.x)
  • MathWorks MatLab w/RealTime Workshop
  • Microsoft C/C++ compiler, e.g., VS2003
0 Kudos
Message 2 of 10
(5,622 Views)

Thanks.   Can you please be a bit more specific?  For example, where should I connect PXI?  Since I have two PCs (host and target), can I do all my work including the control of target PC on the host PC?  I am hoping to use the Target PC only for Matlab/Simulink algorithm development. 

 

Thanks in advance. 

0 Kudos
Message 3 of 10
(5,607 Views)

Hi Sunnyabc,

 

You can replace the PC running the Simulink Models with the PXI Controller and connect between Host and PXI Controller via a crossover cable. Then just use the Simulation Interface Toolkit to run the models and control them from your host in LabVIEW. Some resources that may be helpful:

 

Simulation Interface Toolkit How To

If you want to still use your Windows PC:

Executing a Model DLL on a Windows Computer

The advantage of using the Real-Time PXI Controller is that your model will be run deterministically. This cannot be done in the Windows environment.

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 4 of 10
(5,579 Views)
Thanks.  I need to install Matlab/Simulink on the Target PC because the Host PC cannot handle this additional load.   It looks like Simulation Interface only supports certain RT targets such as PXI.  Please advice how I can use a Windows PC that runs Matlab/Simulink as the Target PC for LabVIEW.  Thanks.
0 Kudos
Message 5 of 10
(5,574 Views)

I am wondering if the new RT Virtualization technology would allow both of these to run on the same computer. Also, PXI is not required for real-time. You may be able to us a desktop RT deployment license to run ETS on your "model" pc. I agree that RT is the right way to go for running the model determinisitically, but if for some reason your model does not need to run deterministically (or it runs so slow that it doesn't really matter), you may be able to get away with a windows pc. SIT is used along with those other tools to convert your simulink model into a dll which will run on the RT target (matlab/simulink need not be installed). SIT also creates the interface vi's necessary to interact with the model.

 

Real-Time Workshop by itself costs ~$7500, so if you can't get funding for those tools, you may be limited in how you can implement this. I believe you can also run a simulink model in simulink and interface with it through SIT, but I am not so clear on how that works, or if you can do it across a network on another computer. 

 

There are also Mathworks tools to let you run your model on a RT target (xPC, I believe). We evaluated them, but decided that the extra complexity on start up was overwhelmed by the implementation flexibilty with the NI tools.

 

Chris

0 Kudos
Message 6 of 10
(5,563 Views)

Back in 2003 / 2004 I did this and had an article written up in the Swiss NI days.. and the soloution still works for realtime process control with 4-5 step horizon.

 

PC with Labview runs the physical plant... 

 

PC with Matlab runs the realtime optimisation (4-5 step horizon) with integration to CPLEX solvers... (not my code)...

 

Solution 1:...

In Labview we open a DCOM interface to the Matlab PC and run some setup scripts (setup.m)

 

Each Labview loop.... We stuff into Matlab (via DCOM interface) the data which is needed for the optimisation algorithms.

Labview  then reads controls (data buffers) which contain the correct optimisation parameters for the plant...

 

In the meantime Matlab opens a DCOM interface back to the Labview application; and sets up a timer object. 

When the timer object elapses; a script is called to read the matlab variables (stuffed from Labview), do the processing, and then put the values back into the Labview controls (data buffers via DCOM).

 

This solution is still very stable... (after >4 years), but also provides control engineers the opportunity to easily change their optimisation aglortihms without touching offending Labview code (and vice versa). A temporary write up is here...

http://people.ee.ethz.ch/~lawrence/public-project-trac/wiki/LabviewToMatlab

 

0 Kudos
Message 7 of 10
(5,544 Views)

Thanks Marc.  I am looking for a solution like this.  It is not very clear to me how it works.   Thanks very much.

 

I already have Real Time Workshop, and will purchase any hardware/software necessary to complete this task.

 

Do you think that Mathworks' xPC Target Box will make things easier for me?

 

Thanks

  

0 Kudos
Message 8 of 10
(5,530 Views)

Out of the box; Labview and Matlab both have ActiveX support. Thanks to the great Microsoft naming conventions, ActiveX can mean both a graphical object (like a Labview Control) or a server / client concept (like a database). COM (Component Object Model) and DCOM (Distributed COM) also use the same conventions.

 

In Labview you can use the Automation Open objects (ActiveX controls) to create a server to the Matlab object... you supply an IP address if the machine is 'remote'. This means that both machines need to know about Matlab / Labview and this is why I extracted the type library information (on the link provided).

 

Then when you send commands via the COM / ActiveX blocks it can be relatively easy to do some fancy things... all you need to do in Matlab is wrap the Simulink optimisation commands into a script function. This can be done fairly easy - I forget the commands to run simulink from script but it is something trivial. 

 

To test the reverse to Labview... try doing the following in Matlab (assuming both are installed on same machine for development purposes)

.

a = actserver('Labview.application');

b = a.GetVIReference('filename.vi')

 

C = b.GetControlValue('Controlname')

C = C+1;

b.SetControlValue('Controlname',C)

 

 

 

0 Kudos
Message 9 of 10
(5,528 Views)

"Do you think that Mathworks' xPC Target Box will make things easier for me?"

 

It's hard to answer that question. It depends on a lot of things. I think the xPC stuff is probablyl easier if you have compatible hardware already, and you don't need to create any nice looking/professional interfaces, and you don't mind manually firing up the model everytime you want to use it.

 

If you already have RTW, than all you need is SIT and an RT deployment license (again, assuming your hardware is compatible;check: http://zone.ni.com/devzone/cda/tut/p/id/8239), aannd LabVIEW RT Module if you don't already have it.

 

Just to reiterate, using this technique will get your model running on a real-time system deterministically (and at pretty high loop rates depending on the model and the hardware). You will not need to have a Matlab/Simulink license tied up with a computer, and the RT hardware can be set to automatically start when powered up.

 

If you don't need the determinism (or potentially the speed), you can proceed with the technique like what Marc was describing (or I still think there is a way to do it through SIT). The benefit of his approach is that you probably wouldn't have to buy anything. Also, it sounds like the COM approach didn't have any hardware tied directly in to the model; I may have misunderstood, but it sounded like all the IO was happening through LabVIEW, and messages are essentially sent to update the model inputs and get the model outputs.

 

Maybe it would help if you described a little more about the system you are trying to implement.

 

Chris

0 Kudos
Message 10 of 10
(5,521 Views)