NI Tutorial 3057 En

Embed Size (px)

Citation preview

  • 7/25/2019 NI Tutorial 3057 En

    1/41/4 www.ni.c

    1.2.3.

    1.

    2.

    3.

    4.

    5.

    6.

    7.

    1.

    Building a LabVIEW User Interface for a Simulink Model with LabVIEW Simulation Interface Toolkit

    Publish Date: Mar 15, 2011

    Overview

    The Simulation Interface Toolkit (SIT) provides a seamless integration between The MathWorks Inc. Simulink software and

    LabVIEW. The Simulation Interface Toolkit automatically generates LabVIEW code to interface with a Simulink module resulting

    in a flexible and easy-to-use user interface. You first must congifure the Simulink model to communicate with LabVIEW. Then

    you can create a LabVIEW host VI that automatically calls, runs and interacts with the Simulink model.

    Table of Contents

    Configuring the Simulink ModelCreating a LabVIEW User Interface

    Attachments

    1. Configuring the Simulink Model

    Before LabVIEW can communicate with your Simulink model, you must first correctly configure your model in Simulink.Save the attached files and .sinewave.mdl Sine Wave.VI

    Launch MATLAB and notice how the MATLAB command window displays the following message:

    Starting the SIT Server on port 6011SIT Server started

    The Simulation Interface Toolkit automatically installs the SIT server. If you do not see this message, the toolkit is not installedcorrectly

    Enter in the MATLAB command window to launch the window.simulink Simulink Library Browser

    Select and select the , downloaded in Step 1.FileOpen sinewave.mdl

    The simulation model should look similar to the following diagram:

    This Simulink model represents a sine wave.

    Note the block on the diagram. You must place a block on the top layer of your diagram. TheSignalProbe SignalProbeblock can be found in the library.SignalProbe NI SIT Blocks

    Also note the simulation settings by selecting . For information on setting the simulatioSimulation>>Simulation parametersoptions, refer to the LabVIEW 2010 Simulation Interface Toolkit Help.

    Save the Simulink model

    You can now create a user interface in LabVIEW for the Simulink model. Notice that the model remains fully-operationalwithin the Simulink environment

    2. Creating a LabVIEW User Interface

    To interact with the Sine Wave Model using a LabVIEW user interface, you need to create a user interface in LabVIEW.

    Launch LabVIEW and open a new VI.

  • 7/25/2019 NI Tutorial 3057 En

    2/42/4 www.ni.c

    2.

    3.

    4.

    5.

    6.

    7.

    8.

    9.

    0.

    Place two knob controls on the front panel. Label one and the other .Frequency Amplitude

    Place a waveform chart on the front panel. Label the y-axis and the x-axis .Amplitude TimeYour front panel should look similar to the following Front Panel:

    You can now create the mappings between the VI and the Simulink model. From the VI, select Tools>>SIT ConnectionManager.

    In the category, select under Host Execution. The execution host is the machineModel and Host Simulation Environmenton which the SIT server is running. If you want to select or on Local host, you must convert yourReal-Time Target Driver VISimulink model to a DLL before you can create mappings.

    Under Current Model, select and select the file.Browse sinewave.mdl

    Under Project Directory, select and select the folder in which you want your project to be contained. Ideally, thisBrowseshould be the same folder that you model is located in.

    From the list, select to display the Mappings page. The Current Mappings table shows the controls andCategory Mappingsindicators you created earlier on the front panel. You will use this page to map your front panel items to the Simulink model.

    Highlight the control in the Current Mappings table and click the button. This will bring up theFrequency Change Mappings

    Specify Parameters for Control dialog box.

    From this dialog box, select from the tree and click .Frequency sinewave>>Sine Wave OK

  • 7/25/2019 NI Tutorial 3057 En

    3/43/4 www.ni.c

    1.

    2.

    3.

    Map the remaining objects. Map the control to the from the tree. Map theAmplitude Amplitude sinewave>>Sine Wave Sinindicator to the from the treeWave Port 1 sinewave>>Sum .

    Click the button to close the SIT Connection Manager dialog box and generate the block diagram code for the VI. NoticeOKthere are now on your front panel. You can use these controls to control the model from the VI.Model Controls

    Notice the block diagram now contains code. DO NOT MODIFY ANY of the code with green labels.You can run the VI and control the simulation with the . The and knob controls can beModel Controls Frequency Amplitude

    used to change the sine wave output.This process described here does not require the MathWorks Real-Time Workshop. This VI uses Simulink to run the

    simulation. You also can use the Simulation Interface Toolkit together with the Real-Time Workshop to build the model into aDLL for stand-alone simulation. You need MATLAB, Simulink, and Real-Time Workshop to build a model DLL and configure

    the user interface. You need only LabVIEW to run the simulation. For hardware-in-the-loop (HIP) and prototyping applications,you can run the model DLL in LabVIEW Real-Time to provide real-time inputs and outputs and to ensure determinism.

    MATLAB, Simulink, and Real-Time Workshop are registered trademarks of The MathWorks, Inc. Other product and companynames listed are trademarks and trade names of their respective companies.

    3. Attachments

  • 7/25/2019 NI Tutorial 3057 En

    4/44/4 www.ni.c

    (

    /jriley/DEVO/conceptd.nsf/1949a53100ddca4e86257116006c996a/955a9d79583a0ab686256db8006672b8/$FILE/ATT7V9V7/absb) (

    /jriley/DEVO/conceptd.nsf/1949a53100ddca4e86257116006c996a/955a9d79583a0ab686256db8006672b8/$FILE/ATTXM5KP/abs)Related Links:

    LabVIEW 2010 Help: Simulation Interface Toolkit (http://digital.ni.com/manuals.nsf/websearch/499D92D6929031E3862577610078FBF7)

    Developer Zone Tutorial: Using NI-DAQmx with the LabVIEW Simulation Interface Toolkit (http://zone.ni.com/devzone/cda/tut/p/id/4611)

    KnowledgeBase KB47IG4V3N: What Software Will I Need to Use the Simulation Interface Toolkit? (http://digital.ni.com/public.nsf/allkb/8DE2AC8755DBC7A7862572A30079957E?OpenDocument)

    COMPANY

    About National Instruments (http://www.n

    Events (http://www.ni.com/events/)

    Careers (http://www.ni.com/careers/)

    SUPPORT

    Submit a service request (https://sine.ni.com/srm/app/myServiceRequests)

    Manuals (http://www.ni.com/manuals/)

    Drivers (http://www.ni.com/downloads/drivers/)

    Alliance Partners (http://partners.ni.com/partner_locator/search.aspx)

    PRODUCT

    Order status and history (http://www.ni.com/status/)

    Order by part number (

    http://sine.ni.com/apps/utf8/nios.store?action=purchase_form)

    Activate a product (http://sine.ni.com/myproducts/app/main.xhtml?lang=en)

    Order and payment information (http://www.ni.com/how-to-buy/)

    MISSION

    NI equips engineers and scientists with systems that accelerate productivity, innovation, and discovery.

    (http://twitter.com/niglobal) (http://www.facebook.com/NationalInstruments)

    http://www.linkedin.com/company/3433?trk=tyah) (http://www.ni.com/rss/) (http://www.youtube.com

    Contact Us (http://www.ni.com/contact-us/)

    National Instruments. All rights reserved.Legal (http://www.ni.com/legal/) | | Site map (

    http://www.ni.com/help/map.htm)

    (//privacy.truste.com/privacy-seal/National-Instruments-Corporation/validation?rid=bc6daa8f-7051-4eea-b7b5-fb24dcd96d95)

    http://digital.ni.com/manuals.nsf/websearch/499D92D6929031E3862577610078FBF7http://digital.ni.com/manuals.nsf/websearch/499D92D6929031E3862577610078FBF7http://zone.ni.com/devzone/cda/tut/p/id/4611http://zone.ni.com/devzone/cda/tut/p/id/4611http://digital.ni.com/public.nsf/allkb/8DE2AC8755DBC7A7862572A30079957E?OpenDocumenthttp://digital.ni.com/public.nsf/allkb/8DE2AC8755DBC7A7862572A30079957E?OpenDocumenthttp://www.ni.com/company/http://www.ni.com/events/http://www.ni.com/careers/https://sine.ni.com/srm/app/myServiceRequestshttps://sine.ni.com/srm/app/myServiceRequestshttp://www.ni.com/manuals/http://www.ni.com/downloads/drivers/http://partners.ni.com/partner_locator/search.aspxhttp://partners.ni.com/partner_locator/search.aspxhttp://www.ni.com/status/http://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://www.ni.com/how-to-buy/http://twitter.com/niglobalhttp://www.facebook.com/NationalInstrumentshttp://www.linkedin.com/company/3433?trk=tyahhttp://www.ni.com/rss/http://www.youtube.com/nationalinstrumentshttp://www.ni.com/contact-us/http://www.ni.com/legal/http://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/help/map.htmhttp://www.ni.com/legal/http://www.ni.com/legal/http://www.ni.com/contact-us/http://www.ni.com/contact-us/http://www.youtube.com/nationalinstrumentshttp://www.ni.com/rss/http://www.linkedin.com/company/3433?trk=tyahhttp://www.facebook.com/NationalInstrumentshttp://twitter.com/niglobalhttp://www.ni.com/how-to-buy/http://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/myproducts/app/main.xhtml?lang=enhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://sine.ni.com/apps/utf8/nios.store?action=purchase_formhttp://www.ni.com/status/http://partners.ni.com/partner_locator/search.aspxhttp://partners.ni.com/partner_locator/search.aspxhttp://partners.ni.com/partner_locator/search.aspxhttp://www.ni.com/downloads/drivers/http://www.ni.com/manuals/https://sine.ni.com/srm/app/myServiceRequestshttps://sine.ni.com/srm/app/myServiceRequestshttps://sine.ni.com/srm/app/myServiceRequestshttp://www.ni.com/careers/http://www.ni.com/events/http://www.ni.com/company/http://digital.ni.com/public.nsf/allkb/8DE2AC8755DBC7A7862572A30079957E?OpenDocumenthttp://digital.ni.com/public.nsf/allkb/8DE2AC8755DBC7A7862572A30079957E?OpenDocumenthttp://zone.ni.com/devzone/cda/tut/p/id/4611http://zone.ni.com/devzone/cda/tut/p/id/4611http://zone.ni.com/devzone/cda/tut/p/id/4611http://digital.ni.com/manuals.nsf/websearch/499D92D6929031E3862577610078FBF7http://digital.ni.com/manuals.nsf/websearch/499D92D6929031E3862577610078FBF7http://digital.ni.com/manuals.nsf/websearch/499D92D6929031E3862577610078FBF7