Contents Previous Next Index
2 Example: Exporting a Model as a LabVIEW EMI Block
2.1 Preparing a Model for Export
In this example, you will perform the steps required to prepare a slider-crank mechanism model 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:
In MapleSim, click the Help menu item.
Select Examples > User's Guide Examples > Chapter 6, and then select Planar Slider-Crank Mechanism.
Converting the Model to a Subsystem
By converting your entire model or part of your model into a subsystem, you identify which parts of the model that you want to export. In this example, you will group all of the components into a subsystem.
To convert the model to a subsystem:
1. Draw a box around all of the components in the model by dragging your mouse over them.
2. From the Edit menu, select Create Subsystem.
3. In the Create Subsystem dialog box, enter SliderCrank as the subsystem name.
4. Click OK. A SliderCrank subsystem block appears in the Model Workspace.
Defining Subsystem Inputs and Outputs
MapleSim uses a topological representation to connect interrelated components without having to consider how signals flow between them, whereas traditional signal-flow modeling tools require explicitly defined system inputs and outputs. Since LabVIEW only supports data signals, properties on acausal ports, such as mechanical flanges and electrical pins, must be converted to signals using the appropriate components. The resulting signals are directed as inputs and outputs for the subsystem in MapleSim and for the EMI block.
Note: Currently, code generation is limited to subsystems with defined signal input (RealInput) and signal output (RealOutput) ports.
In this example, you will convert the displacements of the slider and the joint between the crank and connecting rod to output signals. The input signal needs to be converted to a torque that is applied to the revolute joint that represents the crank shaft.
To define subsystem inputs and outputs:
Double-click the subsystem block to view its contents. The broken line surrounding the components indicates the subsystem boundary, which can be resized by clicking and dragging its sizing handles.
Delete the probes that are attached to the model.
In the Library Components tab (
) on the left side of the MapleSim window, expand the Multibody palette and then expand the Sensors submenu.
Drag the Absolute Translation component to the Model Workspace and place it below the Prismatic Joint component.
Right-click (Control-click for Mac®) the Absolute Translation component and select Rotate Counterclockwise.
From the Signal Blocks > Routing > Demultiplexers menu, drag a Real Demultiplexer component to the Model Workspace and place it to the right of the Absolute Translation component.
To connect the Absolute Translation component to the model, click the frame_b connector. The frame is highlighted in green when you hover your pointer over it.
Draw a vertical line and click the connection line directly above the component. The sensor is connected to the rest of the diagram.
In the same way, connect the r output port (TMOutputP) of the Absolute Translation component to the input port of the demultiplexer. This is the displacement signal from the sensor in x, y, and z coordinates. Since the slider only moves along the x axis, the first coordinate must be an output signal.
Hover your pointer over the first demultiplexer port and click your mouse button once.
Drag your pointer to the subsystem boundary and then click the boundary once. A real output port is added to your subsystem.
Add another Absolute Translation component above the Connecting Rod subsystem.
Right-click (Control-click for Mac) the Absolute Translation component and select Flip Vertical. Right-click the Absolute Translation component again and select Rotate Clockwise.
Add a Real Demultiplexer component to the right of the sensor and connect the components as shown below. Since the crank is moving in the x, y plane, you only need to output the first two signals. You are now ready to add a real input port to your subsystem to control the torque on the crank shaft.
From the 1-D Mechanical > Rotational > Torque Drivers menu, add a Torque component to the Model Workspace and place it above the Fixed Frame component.
Connect the white flange of the Torque component to the white flange of the leftmost Revolute Joint.
Click the input port of the Torque component, then drag your pointer to the subsystem boundary and click the boundary once. A real input port is added to your subsystem.
The complete subsystem appears below.
Click Main (
) in the Model Workspace toolbar to browse to the top level of the model.
From the Signal Blocks > Sources > Real menu, drag a Constant source into the Model Workspace and connect its output port to the input port of the SliderCrank subsystem as shown below.
Click Attach Probe (
) above the Model Workspace toolbar and then click the top output port of the SliderCrank subsystem.
In the Model Workspace, click the probe once to position it.
In the same way, add probes to the other SliderCrank output ports as shown below.
2.2 Defining and Assigning Subsystem Parameters
You can define custom parameters that can be used in expressions in your model to edit values more easily. To do so, you define a parameter with a numeric value in the parameter editor. You can then assign that parameter as a variable to the parameters of other components; those individual components will then inherit the numeric value of the parameter defined in the parameter editor. By using this approach, you only need to change the value in the parameter editor to change the parameter values for multiple components.
To edit parameters
Double-click the SliderCrank component on the Model Workspace to see the detailed view of the SliderCrank subsystem, and then click Parameters (
) in the Model Workspace toolbar. The parameter editor appears.
In the first Name field, type CrankL and press Enter.
Specify a default value of 1 and enter Crank length as the description.
In the second row of the table, define a parameter called ConRodL and press Enter.
Specify a default value of 2 and enter Connecting Rod Length as the description.
Click Diagram View (
) to switch to the diagram view, and then click Main (
Select the SliderCrank subsystem. The parameters are defined in the Properties tab (
Double-click the SliderCrank subsystem, and then select the Crank subsystem.
In the Properties tab (
), change the length value (L) to CrankL. The Crank subsystem now inherits the numeric value of CrankL that you defined.
Select the ConnectingRod subsystem and change its length value to ConRodL.
Click Main (
) in the Model Workspace toolbar to navigate to the top level of the model. You will include these parameter values in the model that you export. You are now ready to convert your model to an EMI block.
2.3 Exporting Your Model Using the LabVIEW EMI Block Generation Template
After preparing the model, you can use the LabVIEW EMI Block Generation template to set export options and convert the model to a LabVIEW EMI block.
To generate an EMI file:
Select the Add Apps or Templates tab (
Double-click on the NI LabVIEW EMI Component Block Generation entry in the Templates palette.
Enter Slider Crank EMI as the worksheet name, and click Create Attachment (
). The slider-crank subsystem is opened in the LabVIEW EMI Block Generation Template in Maple.
Use the navigation controls above the model diagram to select the SliderCrank subsystem and then click Load Selected System. All of the template fields are populated with information specific to the subsystem.
Click Generate to LabVIEW to generate the block.
Set the LabVIEW and Visual C++ directory paths.
At the bottom of the template, click Generate and Compile EMI Component to LabVIEW to generate the Visual Studio project and dynamic-link library (.dll) file for the EMI block.
In LabVIEW, open a new VI and open the block diagram window by selecting Windows > Show Block Diagram.
Right-click the drawing canvas and select Control Design & Simulation > Simulations > Control and Simulation Loop. Click the canvas and draw a simulation loop box.
Right-click the simulation loop box and select Control Design & Simulation > Simulations > Utilities > External Model. Click the simulation loop box to position the model.
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.
Connect the output of the block to a scope and the input to a sine wave.
Download Help Document
What kind of issue would you like to report? (Optional)