Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Jul 31, 2009


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Developing Algorithms Using LabVIEW MathScript RT Module: Part 1 – The LabVIEW MathScript Node

20 ratings | 3.85 out of 5
Read in | Print | PDF

Overview

This series of documents provides exercises to inform you about the NI LabVIEW MathScript RT Module. This document offers a step-by-step examples for using the LabVIEW MathScript Node to develop algorithms.

What Is LabVIEW MathScript RT Module?

With LabVIEW, you can choose the most effective syntax for developing algorithms, exploring signal processing concepts, or analyzing results. You can combine the LabVIEW graphical programming paradigm with LabVIEW MathScript, a math-oriented textual programming language. 

See Also:
Inside LabVIEW MathScript: Making LabVIEW Ideal for Textual Algorithm Development and Prototyping
Multimedia Demonstration of LabVIEW MathScript
Test-Drive LabVIEW MathScript

The LabVIEW MathScript Node

You can work with LabVIEW MathScript through either of two interfaces: the LabVIEW MathScript Interactive Window or the MathScript Node. Refer to Part 2 of this series for more information about the LabVIEW MathScript Interactive Window.

With the LabVIEW MathScript Node, the blue rectangular region on the figure below, you can run .m file scripts from your LabVIEW graphical programs (known as virtual instruments or VIs). You can use the MathScript Node to insert textual algorithms into a VI and then use the LabVIEW graphical programming environment to instrument the scripts by adding knobs, slides, buttons, graphics, and other user controls and indicators.


The Blue Rectangular Region Represents the LabVIEW MathScript Node


See Also:
Developing Algorithms Using LabVIEW MathScript: Part 2 – The MathScript Interactive Window

Introduction to LabVIEW and Graphical Programming

LabVIEW is a graphical development platform for engineering and science applications such as design, control, and test. In LabVIEW, you build a user interface, or the front panel, with controls and indicators. Controls are knobs, push buttons, dials, text entry fields, and other input mechanisms. Indicators are graphs, numerical displays, LEDs, and other output displays. After you build the user interface, you add code using VIs and structures to control the front panel objects. The block diagram contains this code.




[+] Enlarge Image

Complete the following steps to build the front panel and block diagram of a VI.

1. Launch LabVIEW.

2. From the LabVIEW Getting Started window, select File»New VI or click the Blank VI link to create a new VI.

 


 

3. On the front panel of the VI, select View»Controls Palette to display the Controls palette.

4. Move the cursor over the icons on the Modern palette to locate the Numeric palette. When you move the cursor over icons on the Controls palette, the name of the subpalette, control, or indicator appears in a tip strip below the icon.

5. Click the Numeric icon to display the Numeric palette.

6. Move the cursor over the icons on the Numeric palette to locate the Vertical Pointer Slide.

7. Click the Vertical Pointer Slide icon and drag it to the front panel.


 

8. Double-click the Slide label of the Vertical Pointer Slide. In the text box that appears, type Amplitude.




 

9. On the Controls palette, click the Modern link to return to the Modern top-level palette. Move the cursor over the icons on the Modern palette to locate the Graph palette.

10. Click the Graph icon to display the Graph palette.

11. Move the cursor over the icons on the Graph palette to locate the Waveform Graph. Click the Waveform Graph icon and drag it to the front panel. You can display the results of an application by using indicators, charts, and other graphical displays on the front panel of a VI.




[+] Enlarge Image

 

12. Select Window»Show Block Diagram to display the block diagram of the VI. Building a block diagram is similar to building a front panel. When you place objects on the front panel, LabVIEW creates terminals for those objects on the block diagram. You can wire data in or out of the block diagram terminals to display data on the user interface or to apply user input values in your application.

13. Find the Amplitude and Waveform Graph terminals on the block diagram.





14. Select File»Save As to save the VI.

Refer to the Getting Started with LabVIEW manual for more information about the LabVIEW graphical programming environment and the basic LabVIEW features you use to build data acquisition and instrument control applications.

See Also:
Getting Started with LabVIEW

Using the MathScript Node for Algorithm Development and Prototyping


You can use the MathScript Node to develop and prototype algorithms within LabVIEW. Complete the following steps to develop and prototype an algorithm in a MathScript Node. Run that script in the VI you created in the previous section.

1. On the block diagram, select View»Functions Palette to display the Functions palette.

2. Move the cursor over the icons on the Programming palette to locate the Structures palette.

3. Click the Structures icon to display the Structures palette.

4. Move the cursor over the icons on the Structures palette to locate the MathScript Node.

5. Click the MathScript Node icon.

6. On the block diagram, click and drag the mouse in a rectangular shape to place the MathScript Node.




[+] Enlarge Image

 

7. Click inside the MathScript Node and type the following commands.

x = linspace(0, 2*pi, 30);
b = A*sin(x)

Notice that the x = linspace(0, 2*pi, 30); command creates a new variable x and populates that variable with 30 samples evenly distributed between 0 and 2*pi.

(Optional) You also can right-click the MathScript Node and select Import from the shortcut menu to import an .m file script that you created.




8. Right-click the MathScript Node frame and select Add Input from the shortcut menu.

9. Type A in the input terminal to add an input for the A variable in the script.



10. Right-click the MathScript Node frame and select Add Output from the shortcut menu.

11. Type b in the output terminal to add an output for the b variable in the script.

12. Right-click the b output terminal and select Choose Data Type»1D-Array»DBL 1D from the shortcut menu to specify the data type of the b output variable.




 

13. Move the cursor over the arrow on the Amplitude terminal. The cursor becomes a wire spool, or the Wiring tool. Use the Wiring tool to wire objects together on the block diagram.

14. When the Wiring tool appears, click the arrow on the Amplitude terminal and then click the arrow on the A input of the MathScript Node to wire the two objects together. Data flows along this wire from the Amplitude terminal to the MathScript Node.

15. Similarly, wire the b output to the Waveform Graph terminal. You now can obtain appropriate data from the script and visually analyze the results with the rich user interface capabilities of LabVIEW. The block diagram should look like this:





16. Select Window»Show Front Panel to display the front panel of the VI.

17. Drag the slider of the Amplitude control to approximately 3.

18. Click the Run button, or the white arrow, at the top of the front panel. Notice that the waveform graph updates with a sine wave.




19. Drag the slider of the Amplitude control to a different value and run the VI again. Notice that the sine wave updates accordingly.

20. (Optional) Click the Run Continuously button, or the circular arrows, at the top of the front panel. Notice that the waveform graph updates each time you change the value of the Amplitude control.

21. Select File»Save to save the VI.

You can access the LabVIEW tools and functions through interactive palettes, dialog boxes, and menus. LabVIEW also provides hundreds of VIs that you can use within the programs that you create. Drag and drop these VIs onto a block diagram to define the behavior of the applications you write. This point-and-click approach significantly reduces the time you need to get from initial setup to a final solution.

 

Deploying LabVIEW MathScript RT Module Applications to Real-Time Targets

LabVIEW Real-Time allows you to compile and download code to develop deterministic applications designed to run on real-time hardware targets.  You can develop applications using the LabVIEW MathScript RT Module to deploy your .m file scripts to these targets.  Follow these steps to run the previously developed algorithm on a Real-Time target.

1.       From the VI you saved, select File»New Project to create a new project.



2.      In the Open Items dialog box, select Add to add your VI to the new project.




3.      When the Project Explorer window opens, select File»Save As… to save your project.

4.      Right-click Project:  Project Name.lvproj and select New»Targets and Devices…




5.      Select Existing target or device to locate your networked Real-Time Target.




6.      Left-click and drag the VI under the Real-Time Target in the Project Explorer




7.      Press the Run button to deploy and execute the VI on the Real-Time target.

For more information about deploying your algorithms to a Real-Time target, see Deploying Text-Based Math to Real-Time Hardware with the LabVIEW MathScript RT Module.

Related Links

Developing Algorithms Using LabVIEW MathScript: Part 2 – The MathScript Interactive Window

 

20 ratings | 3.85 out of 5
Read in | Print | PDF

Reader Comments | Submit a comment »

last value in the linspace command should be 30 not 3.
- Sep 15, 2009

To clarify
The amplitude and wave graph terminal can be shown as in figure by right clicking the icons and untick 'View as icon'. Took me some time to figure out though.
- Jacky. lwu034@aucklanduni.ac.nz - Jun 20, 2009

very useful information
- govind sharma - Aug 12, 2008

Great: Mathscript and other script nodes are a wonder weapon !
Mathscript Nodes and also the other script nodes are great. In shortest time i can implement my complex algorithm into Labview. That reduces development times dramatically! That really rocks !
- Geissler. aj.geissler@googlemail.com - Apr 16, 2008

For a keyboard person and procedural text type programmer who wanted a good mix between object at the front panel and scripts this is a pretty good page!
- Berns Buenaobra, IMI Design and Engineering. bernardino.j.buenaobra@imiphil.com - Mar 4, 2008

Very useful and essential guide! Thanks a lot!!
- Apr 17, 2007

this rocks man.
praise you! this has been most helpful!
- May 31, 2006

fig is not very clear
I know the figs are from snapshot of labview window, but there are not very clear, can't you make the same quality ?
- Jan 14, 2006

This rocks!!!
- Oct 21, 2005

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).