1 Getting Started - MapleSim Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : MapleSim Toolboxes : MapleSim Connector for LabVIEW and NI VeriStand Software : Getting Started Guide : MapleSimLabVIEWConnectorGSG/Chapter01

Contents     Previous     Next     Index

1 Getting Started

1.1 Getting Help

In Maple, enter ?LabVIEWConnector at a prompt in a worksheet.

1.2 Using the LabVIEW Component Block Generation Template

The MapleSim Connector provides LabVIEW Component Block Generation templates in the form of Maple worksheets for manipulating and exporting MapleSim subsystems. These templates contain pre-built embedded components that allow you to generate EMI Components, SIT Components, or C code from a MapleSim subsystem, export the subsystem as a LabVIEW block, and save the source code.

Using these templates, you can define inputs and outputs for the system, set the level of code optimization, choose the format of the resulting EMI Component, and generate the source code, library code, block script, or LabVIEW block. You can use any Maple commands to perform task analysis, assign model equations to a variable, group inputs and outputs to a single vector and define additional input and output ports for variables.

Note: Code generation now handles all systems modeled in MapleSim, including hybrid systems with defined signal input (RealInput) and signal output (RealOutput) ports.

Block generation for EMI or SIT consists of the following steps:

• 

Subsystem preparation

• 

Subsystem selection

• 

Port and parameter management

• 

EMI or SIT component options

• 

Generate EMI or SIT component code

• 

View generated EMI or SIT component code

Subsystem Preparation

 

Convert your model or part of your model into a subsystem.  This identifies the set of modeling components that you want to export as a block component.  Since LabVIEW only supports data signals, properties on acausal connectors such as mechanical flanges and electrical pins, must be converted to signals using the appropriate ports.

To connect a subsystem to modeling components outside of its boundary, you add subsystem ports.  A subsystem port is an extension of a component port in your subsystem.  The resulting signals can then be directed as inputs and outputs for the LabVIEW Component Block Generation templates.

Note:  For connectors you must use signal components since acausal connectors can not be converted to a signal.

By creating a subsystem you not only improve the visual layout of a system in Model Workspace and but also prepare the model for export.  The example in Chapter 2 shows you how to group all of the components into a subsystem.

Subsystem Selection

You can select which subsystems from your model you want to export to a LabVIEW block.  After a subsystem is selected, click Load Selected Subsystem.  All defined input and output ports are loaded.

Port and Parameter Management

Port and Parameter Management lets you customize, define and assign parameter values to specific ports. Subsystem components to which you assign the parameter inherit a parameter value defined at the subsystem level. After the subsystem is loaded you can group individual input and output variable elements into a vector array, and add additional input and output ports for customized parameter values.  Input ports can include variable derivatives, and output ports can include subsystem state variables.

Note:  If the parameters are not marked for export they will be numerically substituted.

 

 

Select Group all inputs into a single vector to create a single 'vector' input port for all of the input signals instead of individual ports. The order of the inputs are the same as given in the S-function mask window.

Select  Add additional inputs for required input variable derivatives to specify calculated derivative values instead of numerical approximations.

 

 

Select  Group all outputs into a single vector to define outputs as an S-Function 'mask'.

Select  Add an additional output port for subsystem state variables to add extra output ports for the state variables.

 

 

Select Group all parameters into a single vector to create a single parameter 'vector' for all of the parameters in the S-function. If not selected, the S-function mask will contain one parameter input box for each of the S-function parameters.

 

EMI or SIT Input and Output Ports

The following selections specify the input ports, output ports, and states for generating LabVIEW blocks.

  EMI or SIT Input Ports:

 

Select  Add additional inputs for required input variable derivatives to specify calculated derivative values instead of numerical approximations.

 

EMI or SIT Output Ports:

 

Select  Add an additional output port for subsystem state variables to add extra output ports for the state variables.

EMI Component Options

The EMI Component Options settings specify the advanced options for the code generation process.

Optimization Options

Set the level of code optimization to specify whether equations are left in their implicit form or converted to an ordinary differential equation (ODE) system during the code generation process.  This option specifies the degree of simplification applied to the model equations during the code generation process and eliminates redundant variables and equations in the system.

Select one of the following options:

 

None (0): no optimization is performed; the default equations will be used in the generated code.

Partial (1, 2): removes redundant equations from the system.

Full  (3): performs index reduction to reduce the system to an ODE system or a differential algebraic equation (DAE) system of index 1, and removes redundant equations.

Constraint Handling Options

The Constraint Handling Options area specifies whether the constraints are satisfied in a DAE system by using constraint projection in the generated LabVIEW block. Use this option to improve the accuracy of a DAE system that has constraints. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential rate.

 

Set the Maximum number of projection iterations to specify the maximum number of times that a projection is permitted to iterate to obtain a more accurate solution.

Set the Error tolerance to specify the desirable error tolerance to achieve after the projection.

Select Apply projection during event iterations to interpolate iterations to obtain a more accurate solution.

Constraint projection is performed using the constraint projection routine in the External Model Interface as described on The MathWorks™ web site to control the drift in the result of the DAE system.

Event Handling Options

The Event Handling Options area specifies whether the events are satisfied in a DAE system by using event projection in the generated LabVIEW block.  Use this option to improve the accuracy of a DAE system with events. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential rate.

 

Set the Maximum number of event iterations to specify the maximum number of times that a projection is permitted to iterate to obtain a more accurate solution.

Set the Width of event hysteresis band to specify the desirable error tolerance to achieve after the projection.

Select Optimize for use with fixed-step integrators to optimize the event iterations as a function of hysteresis bandwidth.

Baumgarte Constraint Stabilization

The Baumgarte constraint stabilization method stabilizes the position constraint equations by combining the position, velocity, and acceleration constraints into a single expression. By integrating the linear equation in terms of the acceleration, the Baumgarte parameters, alpha and beta, act to stabilize the constraints at the position level.

Select Apply Baumgarte constraint stabilization to apply Baumgarte constraint stabilization to your model. When selected, you can enter values for the derivative gain (Alpha) and the proportional gain (Beta) that are appropriate for your model.

Select Export Baumgarte parameters to add Alpha and Beta as parameters in the generated plugin solver code for your model. This allows you to change the values of Alpha and Beta when using your plugin solver.

Discretization

Select Export as a discrete model (no continuous states) to apply discretization to your model. When selected, you can select a solver type from one of the following options:

• 

Euler: forward Euler method

• 

RK2: second-order Runge-Kutta method

• 

RK3: third-order Runge-Kutta method

• 

RK4: fourth-order Runge-Kutta method

• 

Implicit Euler: implicit Euler method

In this section, you can also set the Discrete Timestep (in seconds) for the discretization.

SIT Component Options

These settings specify the advanced options for the code generation process.

Optimization Options

Set the level of code optimization to specify whether equations are left in their implicit form or converted to an ordinary differential equation (ODE) system during the code generation process.  This option specifies the degree of simplification applied to the model equations during the code generation process and eliminates redundant variables and equations in the system.

Select one of the following options:

None (0): no optimization is performed; the default equations will be used in the generated code.

Partial (1, 2): removes redundant equations from the system.

Full  (3): performs index reduction to reduce the system to an ODE system or a differential algebraic equation (DAE) system of index 1, and removes redundant equations.

Constraint Handling Options

The Constraint Handling Options area specifies whether the constraints are satisfied in a DAE system by using constraint projection in the generated LabVIEW block. Use this option to improve the accuracy of a DAE system that has constraints. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential rate.

 

Set the Maximum number of projection iterations to specify the maximum number of times that a projection is permitted to iterate to obtain a more accurate solution.

Set the Error tolerance to specify the desirable error tolerance to achieve after the projection.

Select Apply projection during event iterations to interpolate iterations to obtain a more accurate solution.  Constraint projection is performed using the constraint projection routine in the External Model Interface as described on The MathWorks™ web site to control the drift in the result of the DAE system.

Event Handling Options

The Event Handling Options area specifies whether the events are satisfied in a DAE system by using event projection in the generated LabVIEW block.  Use this option to improve the accuracy of a DAE system with events. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential rate.

 

Set the Maximum number of event iterations to specify the maximum number of times that a projection is permitted to iterate to obtain a more accurate solution.

Set the Width of event hysteresis band to specify the desirable error tolerance to achieve after the projection.

Event projection is performed using the event projection routine in the External Model Interface as described on The MathWorks™ web site to control the drift in the result of the DAE system.

Baumgarte Constraint Stabilization

The Baumgarte constraint stabilization method stabilizes the position constraint equations by combining the position, velocity, and acceleration constraints into a single expression. By integrating the linear equation in terms of the acceleration, the Baumgarte parameters, alpha and beta, act to stabilize the constraints at the position level.

Select Apply Baumgarte constraint stabilization to apply Baumgarte constraint stabilization to your model. When selected, you can enter values for the derivative gain (Alpha) and the proportional gain (Beta) that are appropriate for your model.

Select Export Baumgarte parameters to add Alpha and Beta as parameters in the generated plugin solver code for your model. This allows you to change the values of Alpha and Beta when using your plugin solver.

Baserate

The Baserate area specifies the rate at which the model runs.  Use this option to improve the accuracy of a DAE system with events. If the constraint is not satisfied, the system result may deviate from the actual solution and could lead to an increase in error at an exponential rate.

Inputs

Specify the input type; internal, external or both.

Generate SIT Component Code

 

Provide a block name, SIT and Visual C++ directories and specify the location for the generated SIT file.

To generate SIT Component code without a VeriStand connection, click Generate SIT Component.

To generate and compile SIT Component code into VeriStand, click Generate and Compile SIT Component to VeriStand.

Generate EMI Component Code

 

Provide a block name, LabVIEW and Visual C++ directories and specify the location for the generated EMI file.

To generate EMI Component code without a LabVIEW connection, click Generate EMI Component.

To generate EMI Component code, click Generate and Compile EMI Component to LabVIEW.

Note: If your model contains an external library, then you must add the directory that contains the external library to your search path. See Adding External Libraries to Your Search Path for instructions on how to do this.

View EMI or SIT Component Code

After you generate the EMI Component code and create the block, a LabView command window opens and the block with any of the following specified parameters is generated in LabVIEW:

• 

Header File

• 

C Code

1.3 Using the LabVIEW Block Generation Templates

The MapleSim Connector for LabVIEW and NI VeriStand Software provides an NI LabVIEW EMI Block Generation template and an NI VeriStand and LabVIEW SIT Component Model Generation template in the form of Maple worksheets for manipulating and exporting MapleSim subsystems. These templates contain pre-built embedded components that allow you to generate LabVIEW blocks from a MapleSim subsystem, export the subsystem as a LabVIEW block and Microsoft® Visual Studio® project, and save the source code.

Using either of these templates, you can define inputs and outputs for the system, generate the source code and library code.

Example models are available in the NI Connector Examples palette in MapleSim. To access them, from the Help menu, select Examples > NI connector Examples.

 

Viewing Examples

To view an example:

1. 

From the Help menu, select the Examples > NI Connector Examples menu, and then click the entry for the model that you want to view.

Some models include additional documents, such as templates that display model equations or define custom components.

2. 

In the Attached Files tab, expand Documents.  You can open any of these documents by right-clicking its entry in the list and clicking View.

After you add a template to a model, it becomes available from this list.

1.4 Example: RLC Circuit Model

In this example, you will generate a LabVIEW EMI or SIT block, or a block for NI VeriStand using an RLC circuit model that was created in MapleSim.

To generate a LabVIEW block

1. 

From the Help menu, select Examples > NI Connector Examples, and then select the RLC Parallel Circuit example.

2. 

Select the Add Apps or Templates tab ( ).

3. 

In the Templates palette, double-click on either NI LabVIEW EMI Component Block Generation to generate a LabVIEW EMI block or NI VeriStand and LabVIEW SIT Component Model Generation to generate a block for the LabVIEW Simulation Interface Toolkit or NI VeriStand.

4. 

Enter RLC Circuit as the worksheet name.

5. 

Click Create Attachment ( ). Your MapleSim model opens in Maple, in the template that you select.

6. 

Browse to the RLC Parallel Circuit 1 subsystem by selecting the subsystem name from the drop-down menu in the toolbar above the model diagram. This menu displays all of the subsystems and components in your MapleSim model.

7. 

In the EMI Block Generation section of the template, click Load Selected Subsystem.  All of the template fields are populated with information specific to the subsystem displayed in the model diagram.  You can now specify which subsystem parameters will be kept as configurable parameters in the generated block.

8. 

In the EMI Component Options section, set the Code Optimization option to Full (3). This option specifies the degree of simplification applied to the model equations during the code generation process. This option eliminates redundant variables and equations in the system.

9. 

If you plan to generate a LabVIEW EMI block, follow the steps in the Generating a LabVIEW EMI Block section below.  If you plan to generate a block for NI VeriStand or the LabVIEW Simulation Interface Toolkit, follow the steps in the Generating a LabVIEW Block for NI VeriStand or SIT section below.

Generating a LabVIEW EMI Block

To generate a LabVIEW EMI block

1. 

In the Generate EMI Component Code section of the template, specify the LabVIEW and Visual C++ directories.

2. 

Click Generate and Compile EMI Component to LabVIEW to generate the Visual Studio project and dynamic-link library (.dll) file for the EMI block.

3. 

In LabVIEW, open a new VI and open the block diagram window by selecting Windows>Show Block Diagram.

4. 

Right-click the canvas and select Control Design & Simulation > Simulations > Control and Simulation Loop. Click the canvas and draw a simulation loop box.

5. 

Right-click the simulation loop box and select Control Design & Simulation>Simulations>Utilities>External Model. Click a point in the box to position the model.

6. 

In the Select an External Model Library window, browse to the Release subfolder located in the default directory that you specified in the LabVIEW EMI Block Generation template and open the .dll file that you generated.

7. 

Click OK. You can now use the RLC circuit block in a LabVIEW EMI diagram. To view a complete example that describes how to prepare and export a slider-crank model as a LabVIEW EMI block, see Example: Exporting a Model as a LabVIEW EMI Block.

Note: Generating a block may require a few minutes.

Generating a LabVIEW Block for NI VeriStand or the LabVIEW SIT

To generate a LabVIEW block for NI VeriStand or the LabVIEW SIT

1. 

In the Generate SIT Component Code section of the template, specify the SIT and Visual C++ directories.

2. 

Click Generate and Compile SIT Component to VeriStand to generate the Visual Studio project and dynamic-link library (.dll) file for the SIT block.

3. 

In LabVIEW, open a new VI and open the block diagram window by selecting Windows>Show Block Diagram.

4. 

Right-click the canvas and select Control Design & Simulation > Simulations > Control and Simulation Loop. Click the canvas and draw a simulation loop box.

5. 

Right-click the simulation loop box and select Control Design & Simulation > Simulations > Utilities > External Model. Click a point in the box to position the model.

6. 

In the Select an External Model Library window, browse to the Release subfolder located in the default directory that you specified in the LabVIEW EMI Block Generation template and open the .dll file that you generated.

7. 

Click OK.

 

Note: Generating a block may require a few minutes.

 

For more information about preparing your block for either the NI VeriStand or LabVIEW SIT environment, see Working with Your Block in NI VeriStand or LabVIEW SIT.

 

Contents     Previous     Next     Index


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam