30
Getting Started with the MapleSim LabVIEW Connector Toolbox Copyright © Maplesoft, a division of Waterloo Maple Inc Maplesoft, a division of Waterloo Maple Inc

Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Getting Started with theMapleSim LabVIEW Connector

Toolbox

Copyright © Maplesoft, a division of Waterloo Maple IncMaplesoft, a division of Waterloo Maple Inc

Page 2: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Getting Started with the MapleSim LabVIEW ConnectorToolboxCopyright

Maplesoft, Maple, and MapleSim are all trademarks of Waterloo Maple Inc.

© Maplesoft, a division of Waterloo Maple Inc. 1996-2009. All rights reserved. No part of this book may be re-produced, stored in a retrieval system, or transcribed, in any form or by any means — electronic, mechanical,photocopying, recording, or otherwise. Information in this document is subject to change without notice and doesnot represent a commitment on the part of the vendor. The software described in this document is furnished undera license agreement and may be used or copied only in accordance with the agreement. It is against the law tocopy the software on any medium except as specifically allowed in the agreement.

Macintosh is a trademark of Apple Inc., registered in the U.S. and other countries.

MATLAB and Simulink are registered trademarks of The MathWorks, Inc.

All other trademarks are the property of their respective owners.

This document was produced using a special version of Maple and DocBook.

Printed in Canada

Page 3: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

ContentsIntroduction ................................................................................................... v1 Getting Started ............................................................................................. 1

1.1 Getting Help .......................................................................................... 11.2 Using the LabVIEW Block Generation Template .......................................... 1

Viewing MapleSim LabVIEW Connector Examples ...................................... 11.3 Example: RLC Circuit Model ................................................................... 21.4 Preparing a Model for Export .................................................................... 4

Converting the Model to a Subsystem .......................................................... 5Defining Subsystem Inputs and Outputs ...................................................... 6Define and Assign Subsystem Parameters ................................................... 10Exporting Your Model Using the LabVIEW EMI Block Generation Template .... 12

1.5 Running the Simulation on a LabVIEW Real-Time Target Machine ................ 13Preparing the LabVIEW Real-Time Project ................................................. 13Moving the .dll file To the Target Real-Time Machine ................................... 18

Index ........................................................................................................... 23

iii

Page 4: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

iv • Contents

Page 5: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

IntroductionThe MapleSim™ LabVIEW Connector Toolbox provides all of the tools you need to prepareand export your dynamic systems models to LabVIEW ® as EMI blocks. You can createa model in MapleSim, simplify it in Maple™ by using an extensive range of analytical tools,and then generate VIs that you can incorporate into your LabVIEW toolchain.

You can also use these tools for exporting mathematical models that you have created fromfirst principles in Maple as VIs.

Furthermore, various options allow you to use the C code generation feature in Maple tocreate code libraries of your MapleSim models for implementation in other applications.

Features of this toolbox include:

• Maple templates, which provide an intuitive user interface for optimizing yourMapleSim model, and then generate a VI in LabVIEW.

• A range of examples illustrating how to prepare and export your models.

• A direct interface between Maple and LabVIEW allows you to generate and test a VIas you develop the model.

• Commands for developing VIs of mathematical models from first principles in the Mapleenvironment and examples to illustrate how to do it.

• Access to commands in the Connectivity and DynamicSystems packages for developingautomated applications to generate VIs.

Scope of Model SupportMapleSim is a very comprehensive modeling tool where it is possible to create models thatcould go beyond the scope of this MapleSim LabVIEW Connector Toolbox release. Ingeneral, the MapleSim LabVIEW Connector Toolbox supports systems of any complexity,including systems of DAEs of any index, in any mix of domains, as long as they exhibitcontinuous behavior. Systems that contain any type of discontinuity, including discretetransforms, switches, logic gates, relational and Boolean operations are not supported bythe current release of this product.

Apart from all of the engineering and signal components that are continuous, this productalso supports lookup tables, and custom components that do not use discontinuous operationssuch as piecewise functions.

v

Page 6: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

System RequirementsThe MapleSim LabVIEW Connector Toolbox requires the following:

• LabVIEW® 2009 or later

• LabVIEW Control Design and Simulation Module 2009

• The latest versions of Maple and MapleSim

For installation instructions and a complete list of system requirements, see the Install.htmlfile on the product CD.

vi • Introduction

Page 7: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

1 Getting Started1.1 Getting HelpIn Maple, enter ?LabVIEWConnector at a prompt in a worksheet.

1.2 Using the LabVIEW Block Generation TemplateThe MapleSim LabVIEW Connector Toolbox provides a LabVIEW EMI Block Generationtemplate in the form of a Maple worksheet for manipulating and exporting MapleSim sub-systems. This template contains pre-built embedded components that allow you to generateLabVIEW EMI blocks from a MapleSim subsystem, export the subsystem as a LabVIEWEMI block and visual studio project, and save the source code.

Using this template, you can define inputs and outputs for the system, generate the sourcecode and library code.

Viewing MapleSim LabVIEW Connector Examples

Toolbox examples are available in the LabVIEW Connector Examples palette inMapleSim.

Each example includes a code generation template in its document folder.

To view an example:

1. In the LabVIEW Connector Examples palette at the left side of the MapleSim window,click the entry for the model that you want to view.

1

Page 8: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

2. Click the Display Document Folder icon on the main toolbar.

3. From the document list, select LabVIEW EMI Block Generation.

4. Click Open Selected. The code generation template is opened in Maple.

Some models include additional documents, such as templates that display model equationsor define custom components. You can open any of these documents by selecting its entryin the list and clicking Open Selected.

1.3 Example: RLC Circuit ModelIn this example, you will generate a LabVIEW EMI block from an RLC circuit model thatwas created in MapleSim.

To generate an EMI block:

1. From the LabVIEW Connector Examples palette, open the RLC Parallel Circuit ex-ample.

2. Click Display Document Folder icon on the main toolbar.

3. From the drop-down menu, select LabVIEW EMI Block Generation.

4. Click New.

5. Enter RLC Circuit as the worksheet name and click OK.

6. In the document list at the left side of the dialog box, select RLC Circuit and click OpenSelected. Your MapleSim model is opened in the LabVIEW EMI Block Generation forMapleSim Template in Maple.

7. In the Model Diagram section of the template, browse to the RLC Parallel Circuit 1subsystem by selecting the subsystem name from the drop-down menu in the toolbar above

2 • 1 Getting Started

Page 9: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

the model diagram. This list box displays all of the subsystems and components in yourMapleSim model.

8. In the Model Summary section of the template, click System Update. All of the templatefields are populated with information specific to the subsystem displayed in the model dia-gram.

9. In the Shared library name field, enter RLC_Circuit. This is the name that will bedisplayed for the block in LabVIEW.

You can now specify which subsystem parameters will be kept as configurable parametersin the generated LabVIEW EMI block. In this example, the resistance parameter will bekept as a configurable parameter.

10. In the Setting Parameters section, select the Main.R parameter entry in the SubstitutedParameters list.

11. Click the > button. The entry is added to the Block Parameters list. The resistanceparameter will be kept as a configurable parameter in the generated LabVIEW block andthe parameters remaining in the Substituted Parameters list will be assigned to valuesduring the code generation process.

12. To change the default value of the resistance parameter, select Main.R from the BlockParameters list and enter 5 in the Parameter Value field and click anywhere outside ofthe field.

13. In the Advanced Code Generation Settings section, set the Code Optimization optionto Full. This option specifies the degree of simplification applied to the model equationsduring the code generation process. This option eliminates redundant variables and equationsin the system.

14. Set the LabVIEW and Visual C++ directory paths.

15. Click Generate to LabVIEW to generate the Visual Studio project and Dynamic LinkLibrary (.dll) file for the EMI block.

16. Open a blank VI in LabVIEW and open the Block Diagram window (Windows>ShowBlock Diagram).

1.3 Example: RLC Circuit Model • 3

Page 10: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

17. Right-click on the drawing canvas and select Control Design Toolbox>Simula-tions>Control and Simulation Loop. Click on the canvas and draw a Simulation LoopBox.

18. Right-click in the Simulation Loop Box and select Control Design Toolbox>Simula-tions>Utilities>External Model. Click in the Simulation Loop Box to place the model.

19. Load the .dll file from the directory generated in the directory set in step 14 under thesubfolder, Release.

20. Press OK.

Note: Generating a block may require a few minutes.

1.4 Preparing a Model for ExportIn this example, you will perform the steps required to prepare a slider-crank mechanismmodel and export it as a LabVIEW EMI block:

1. Convert the slider-crank mechanism model to a subsystem.

2. Define subsystem inputs and outputs.

3. Define and assign subsystem parameters.

4. Export the model using the LabVIEW EMI Block Generation template.

5. Implement the EMI block in LabVIEW.

To open the slider-crank mechanism example:

1. In MapleSim, expand the Examples palette and then expand the Tutorial submenu.

2. Open the Slider Crank example.

4 • 1 Getting Started

Page 11: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Converting the Model to a Subsystem

By converting your entire model or part of your model into a subsystem, you identify whichparts of the model that you want to export. In this example, you will group all of the com-ponents into a subsystem.

1. Using the selection tool ( ) located above the model workspace, draw a box around allof the components in the model.

2. From the Edit menu, select Create Subsystem.

1.4 Preparing a Model for Export • 5

Page 12: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

3. In the Create Subsystem dialog box, enter SliderCrank as the subsystem name.

4. Click OK. A SliderCrank subsystem block is displayed in the model workspace.

Defining Subsystem Inputs and Outputs

LabVIEW only supports data signals. Properties on acausal ports, such as mechanical flangesand electrical pins, must be converted to signals using the appropriate components. Theresulting signals can then be directed as inputs and outputs for the subsystem in MapleSimand for the EMI block.

In this example, you will convert the displacements of the slider and the joint between thecrank and connecting rod to output signals. The input signal needs to be converted to atorque that is applied to the revolute joint that represents the crank shaft.

1. Double-click the subsystem block to view its contents. The broken line surrounding thecomponents indicates the subsystem boundary, which can be resized by clicking and draggingits sizing handles.

2. Delete the probes that are attached to the model.

3. On the left side of the MapleSim window, expand the Multibody palette and then expandthe Sensors submenu.

4. Drag the Absolute Translation component to the model workspace and place it belowthe Prismatic Joint component.

5. Right-click (Control-click for Macintosh®) the Absolute Translation component andselect Rotate Counterclockwise.

6 • 1 Getting Started

Page 13: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

6. From the Signal Blocks → Routing → Demultiplexers menu, drag a 3-port Demulti-plexer component to the model workspace and place it to the right of the Absolute Trans-lation component.

7. To connect the Absolute Translation component to the model, click the frame (the whitesquare connector). The frame is highlighted in green when you hover your pointer over it.

8. Draw a vertical line and click the connection line directly above the component. Thesensor is connected to the rest of the diagram.

9. In the same way, connect the r output port of the Absolute Translation component tothe navy blue input port of the demultiplexer. This is the displacement signal from the sensorin x, y, and z coordinates. Since the slider only moves along the x axis, you need to outputthe first coordinate as a signal.

10. Hover your pointer over the first demultiplexer port and click your mouse button once.

1.4 Preparing a Model for Export • 7

Page 14: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

11. Drag your pointer to the subsystem boundary.

12. Click the boundary once. A real output port is added to your subsystem.

13. Add another Absolute Translation component above the Connecting Rod subsystem.

14. Right-click (Control-click for Macintosh) this Absolute Translation component andselect Flip Vertically.

15. Add a 3-port Demultiplexer component to the right of the sensor and connect thecomponents as shown below.

8 • 1 Getting Started

Page 15: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Since the crank is moving in the x, y plane, you only need to output the first two signals.

You will now add a real input port to your subsystem to control the torque on the crankshaft.

16. From the 1-D Mechanical → Rotational → Torque Drivers menu, add a Torquecomponent to the model workspace and place it above the Fixed Frame component.

17. Connect the white flange of the Torque component to the white flange of the leftmostRevolute Joint.

18. Click the input port of the Torque component and drag your pointer to the subsystemboundary.

1.4 Preparing a Model for Export • 9

Page 16: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

19. Click the boundary once. A real input port is added to your subsystem.

The complete subsystem is displayed below.

Define and Assign Subsystem Parameters

You can define custom parameters that can be used in expressions in your model to editvalues more easily. To do so, you define a parameter with a numeric value in the parametereditor. You can then assign that parameter as a variable to the parameters of other compon-ents; those individual components will then inherit the numeric value of the parameterdefined in the parameter editor. By using this approach, you only need to change the valuein the parameter editor to change the parameter values for multiple components.

1. While in the detailed view of the SliderCrank subsystem, click the Parameters buttonabove the model workspace. The parameter editor is displayed.

2. In the New Parameter field, define a parameter called CrankL and press Enter.

3. Specify a default value of 1 and enter Length of the crank as the description.

10 • 1 Getting Started

Page 17: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

4. In the second row of the table, define a parameter called ConRodL and press Enter.

5. Specify a default value of 2 and enter Length of the connecting rod as the description.

6. Click Diagram to switch back to the diagram view. The parameters are defined in theParameters pane.

7. In the model workspace, select the Crank subsystem.

8. In the Parameters pane, change the length value (L) to CrankL.

The Crank subsystem now inherts the numeric value of CrankL that you defined.

9. Select the ConnectingRod subsystem and change its length value to ConRodL.

10. In the model tree, click [Top] to navigate to the top level of the model.

You will include these parameter values in the model that you export. You are now readyto convert your model to an EMI block.

1.4 Preparing a Model for Export • 11

Page 18: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Exporting Your Model Using the LabVIEW EMI Block GenerationTemplate

After preparing the model, you can use the LabVIEW EMI Block Generation template toset export options and convert the model to an EMI block.

1. Click the Display Document Folder icon on the main toolbar.

2. From the drop-down menu, select LabVIEW EMI Block Generation.

3. Click New.

4. Enter Slider Crank EMI as the worksheet name and click OK.

5. In the document list at the left side of the dialog box, select Slider Crank EMI and clickOpen Selected. The slider-crank subsystem is opened in the LabVIEW EMI Generationfor MapleSim Template in Maple.

6. From the Subsystem drop-down menu, select SliderCrank and click System Update.All of the template fields are populated with information specific to the subsystem.

7. In the Setting Parameters section, click the >> button. The ConRodL and CrankLparameters, which you defined in the previous section, are added to the LabVIEW Para-meters list. These parameters will be kept as configurable parameters in the generated EMIblock.

8. Click Generate to LabVIEW to generate the block.

9. Set the LabVIEW and Visual C++ directory paths.

10. Click Generate to LabVIEW to generate the Visual Studio project and Dynamic LinkLibrary (.dll) file for the EMI block.

11. Open a blank VI in LabVIEW and open the Block Diagram window (Windows>ShowBlock Diagram).

12. Right-click on the drawing canvas and select Control Design Toolbox>Simula-tions>Control and Simulation Loop. Click on the canvas and draw a Simulation LoopBox.

12 • 1 Getting Started

Page 19: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

13. Right-click in the Simulation Loop Box and select Control Design Toolbox>Simula-tions>Utilities>External Model. Click in the Simulation Loop Box to place the model.

14. Load the .dll file generated in step 10, under the subfolder Release.

15. Press OK.

16. Connect the output of the block to a scope and the input to a sine wave.

17. Run the simulation.

1.5 Running the Simulation on a LabVIEW Real-TimeTarget MachinePreparing the LabVIEW Real-Time Project

To run the simulation on a LabVIEW real-time target machine:

From the LabVIEW Getting Started window, click Real-Time Project.

Keep the default project type as Continuous communication architecture and change theproject name to RTSliderCrank.

1.5 Running the Simulation on a LabVIEW Real-Time Target Machine • 13

Page 20: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Click Next.

At the Customize Architecture Options window, click Next.

14 • 1 Getting Started

Page 21: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

From the drop down menu, browse to find the real-time target platform. Click Next.

A summary of your options are displayed. Click Finish to create the model. The model isnow displayed.

1.5 Running the Simulation on a LabVIEW Real-Time Target Machine • 15

Page 22: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

From the Project Explorer, right-click on the target platform and select Add->File.

Load the .dll file generated in step 10 of the previous section under the subfolder, Release.Click OK.

Navigate back to the block diagram of the VI. Double-click on the Simulation Parameterswindow to the left of the simulation loop. The Configuration Simulation Parameterswindow will appear.

16 • 1 Getting Started

Page 23: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Select the Time Parameter tab and select Synchronize loop to time source. Click OK.

1.5 Running the Simulation on a LabVIEW Real-Time Target Machine • 17

Page 24: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Save the file.

Moving the .dll file To the Target Real-Time Machine

From the start menu, select Measurement and Automation Explorer.

In the Measurement and Automation Explorer window, expand Remote Systems.

Right-click on your target machine

Select File Transfer

18 • 1 Getting Started

Page 25: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Navigate to the directory that contains the .dll file you created in step 10 of Exporting YourModel Using the LabVIEW EMI Block Generation Template.

Select the .dll file.

1.5 Running the Simulation on a LabVIEW Real-Time Target Machine • 19

Page 26: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

Click To Remote to move the .dll file from your local machine to the target machine underthe ni-rt/system directory

Click Close

Run the simulation by clicking the run button on the front panel of the VI.

20 • 1 Getting Started

Page 27: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

1.5 Running the Simulation on a LabVIEW Real-Time Target Machine • 21

Page 28: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

22 • 1 Getting Started

Page 29: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

IndexCConnector Examples Palette, 1

IInputs and outputs, 6

Rreal-time project

preparing, 13real-time simulation , 13

SSubsystem

Creating, 5Subsystem parameters, 10

TTemplates

LabVIEW EMI Block Generation, 1, 12

23

Page 30: Getting Started with the MapleSim LabVIEW Connector ToolboxThis document was produced using a special version of Maple and DocBook. ... see the Install.html file on the product CD

24 • Index