Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Configuring Simulation Functions from LabVIEW MathScripts (Control Design and Simulation Module)

LabVIEW 2012 Control Design and Simulation Module Help

Edition Date: June 2012

Part Number: 371894G-01

»View Product Info

You can integrate text-based scripts and simulations on the same block diagram. The following examples describe possible workflows:

  • Execute a text-based script in a MathScript Node at the start of a VI. In the script, assign results to model parameters of Simulation functions and subsystems in the VI.
  • Run a simulation, and then, in a MathScript Node, read values from model parameters for use as variables in a text-based script.
  • Execute mathematical commands in the LabVIEW MathScript Window, and then assign results to model parameters of Simulation functions and subsystems in a VI.
Note  You must have the MathScript RT Module installed to use a MathScript Node. To determine whether the MathScript RT Module is installed, open the Tools menu and check whether the MathScript Window item is present.

Configuring Model Parameters from a MathScript Node

Call the getmodelparam and setmodelparam LabVIEW MathScript functions in a MathScript Node to get and set the values of model parameters in a simulation hierarchy. The following block diagram shows a simple example of using setmodelparam to configure the frequency and amplitude parameters of a Sine Signal function in a subsystem.

Lines 1 and 2 perform calculations using the value of the input control and assign the results to variables freq and amp. Lines 4 and 5 initialize parameters of the Sine Signal function with the values of those variables.

Note  To access a simulation diagram in another VI, specify the VI name or path as the first input to the getmodelparam and setmodelparam functions. Refer to the help topics for those functions for more information about the required syntax.

Refer to the SimEx Initializing and Analyzing Subsystem with Mathscript VI in the labview\examples\Control and Simulation\Simulation\Mathscript Integration directory for examples of configuring model parameters from a MathScript Node.

Advantages of Configuring Parameters from a MathScript Node

In the previous section, the setmodelparam function is useful because you can set the frequency parameter of the Sine Signal function without wiring the freq variable out of the MathScript Node and into the Control & Simulation Loop. The following block diagram shows that scenario.

When functions are in subsystems, you must also build the connector pane of the subsystem and wire values through the connector pane to the function. Thus, in applications with nested subsystems, the getmodelparam and setmodelparam MathScript functions allow you to avoid even more wiring.

Simplifying Access to Model Parameters in a MathScript Node

The example in the previous section uses the full path of the parameter when it calls the setmodelparam function. If you access a simulation diagram in another VI, you also must specify the VI name or path as an input to the getmodelparam and setmodelparam functions. To reduce the length of this MathScript syntax, you can define and use an alias to identify the parameter you want to configure.

The following block diagram shows an example of using aliases (sig_frequency and sig_amplitude) with the setmodelparam function.

Refer to the SimEx Initializing and Analyzing Subsystem with Mathscript VI in the labview\examples\Control and Simulation\Simulation\Mathscript Integration directory for examples of defining and using aliases for model parameters.

Configuring Model Parameters from the LabVIEW MathScript Window

Call the getmodelparam and setmodelparam functions in the LabVIEW MathScript Window to get and set the values of model parameters in a VI. You must specify the VI name or path as the first input to these functions. Refer to the help topics for those functions for more information about this syntax.

Refer to the SimEx Interacting with Mathscript Window VI in the labview\examples\Control and Simulation\Simulation\Mathscript Integration directory for examples of configuring model parameters from the LabVIEW MathScript Window.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit