Contents Previous Next Index
2 Further Examples
This chapter describes how to prepare a model for export by grouping the necessary components in a subsystem, shows how to use the B&R MapleSim Connector to export a spreadsheet of operational data for use by the B&R SERVOsoft drive train tool, and demonstrates the 1-D motion generation app.
2.1 Preparing the 2-D Rigid Slider Crank Model for Export Using Subsystems
Preparing a Model
This example starts with a slider crank model and prepares it for export by grouping the necessary components in a subsystem. At the end of the process, the example will look like the example model used in the FMU Generation Example: Slider Crank Model section of the Chapter 1. This step is necessary before exporting your model to an FMU.
1. Convert the slider-crank mechanism model to a subsystem.
2. Define subsystem inputs and outputs.
3. Define and assign subsystem parameters.
To open the slider-crank mechanism example:
In MapleSim, under the Help menu, browse to the Examples > User's Guide Examples > Chapter 6 menu.
Open the Planar Slider-Crank Mechanism example. The example appears in the Model Workspace.
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 generate C code for. In this example, you will group all of the components into a subsystem.
To create a subsystem:
Using the selection tool ( ) located in the Model Workspace Toolbar, draw a box around all of the components in the model.
From the Edit menu, select Create Subsystem.
In the Create Subsystem dialog box, enter SliderCrank as the subsystem name.
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 the B&R MapleSim Connector 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 generated C code.
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. A spherical geometry component is also added for visualization purposes.
To create a subsystem output port:
Double-click the subsystem block to view its contents. In this view, the broken line indicates the subsystem boundary. You can edit the connection lines and components within the boundary, and add subsystem ports to connect the subsystem to other components.
Delete the probes that are attached to the model.
Under the Libraries tab on the left side of the MapleSim window, expand the 1-D Mechanical palette and then expand the Rotational > Sensors subpalette.
Drag the Angle Sensor component to the Model Workspace and place it above the Revolute2 component.
To connect the Angle Sensor component to the model, click the triangular y connector. The frame is highlighted in green when you hover your pointer over it.
Drag your pointer to the subsystem boundary.
Click the boundary once. A real output port is added to your subsystem.
Connect the other end of the Angle Sensor to the white flange of revolute joint Revolute1.
Since the B&R connector supports causal and acausal ports, an acausal input is added outside of the subsystem to control the torque on the crank shaft.
Click on the white flange of the leftmost Revolute Joint R1 and drag the pointer to the left boundary. This will act as the acausal input connection to the subsystem.
From the Multibody > Visualization palette, select the Spherical Geometry component and add it above the Rigid Body component. Use Edit > Flip Horizontal to flip the component and then connect it to both Revolute3 and the Rigid Body component.
Add a probe: Click Attach Probe( ) above the Model Workspace toolbar and then click the connection line from Revolute1 to Angle Sensor. Click the probe once to position it.
In the Properties tab, name the probe crank, and select Angle, Angular velocity, and Torque to measure these quantities.
The complete subsystem appears below.
Click Main ( ) in the Model Workspace toolbar to browse to the top level of the model.
From the 1-D Mechanical > Rotational > Torque Drivers menu, add a Torque component to the Model Workspace and place it next to the subsystem. Connect its output port to the input port of the SliderCrank subsystem.
From the Signal Blocks > Controllers palette, drag a PID component into the model workspace and connect its output port to the input signal port of the Torque component. The result is shown below.
Click on the PID and in the Properties tab set k to 400, Ti to 0.5 s, and Td to 0.1 s.
From the Signal Blocks > Math > Operators palette, drag a Feedback component into the model workspace and connect its output port to the input port of the PID component.
Click the Feedback component, and from the Edit menu, select Flip Vertical.
Connect the Feedback component to the PID component and the SlidingCrank subsystem to the Feedback component.
From the Signal blocks>Common menu, add a Constant signal component to the Model Workspace and connect it to the input of the Feedback component.
The model is prepared and ready to use with the apps in the B&R MapleSim Connector.
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.
Change the Type to Length from the drop-down menu.
Specify a default value of 1m 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 2m 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 in the B&R Connector App.
2.3 Exporting Your Model Using the B&R Automation Studio FMU Generation App
After preparing the model, you can use the B&R Automation Studio FMU Generation app to set export options and convert the model to an FMU file. In this example, the Slider Crank Subsystem is exported as an FMU block for which the controller can be designed in the Automation Studio.
From the main toolbar, click Show Apps Manager ( ).
Double-click on the B&R Automation Studio FMU Generation entry under B&R connector in the Apps palette. The B&R FMU Component Code Generation app opens.
In the Subsystem Selection section, select the SliderCrank subsystem from the drop-down list, and then click Load Selected Subsystem. All of the app fields are populated with information specific to the subsystem.
Since this example uses an acausal 1D - mechanical rotational flange, on selecting the input option, you have option to either choose a torque or an angle input that can be fed into the subsystem.
In the Export section, specify the location for the Target Directory and provide a name for the generated FMU Archive.
Click Generate FMU Archive to generate the .FMU zip file.
2.4 Generating Operational Data Model
In this example, you will use the B&R SERVOsoft Data Generation app to create a spreadsheet of the velocity/torque characteristics needed to drive the slider crank model.
Open the Slider Crank example created in the above section,
Load the B&R SERVOsoft Data Generation app.
Define app settings.
Simulate and display the graph.
Export data to a spreadsheet.
To open the Slider Crank example and load the app:
Open the Slider Crank example created in the previous session.
Double-click the B&R SERVOsoft Data Generation entry from the B&R connector in the Apps palette. The B&R SERVOsoft Data Generation app opens.
In the app, click Load System. All of the app fields are populated with information specific to your model. You can now specify the app settings.
To define the app settings:
In the Actuator and Export section, select ** Probes ** from the Device drop-down menu, click the Rotational radio button, and set the Probe, Velocity, and Thrust to be crank.phi, crank.w, and crank.tau, respectively. Note the default units, which are appropriate for this example.
In the Export Options section, ensure the time is from 0 to 2.
To simulate and display the graph:
Click Preview Export(Simulate). The simulation runs and the graph is displayed.
Click the Thrust vs Velocity radio button to view this graph.
To export the data to a spreadsheet:
Specify the locations for the Target Directory.
Provide a name for the generated XLS file in Filename.
Click Export. The XLS files are created and saved in the target directory.
Note: Generating a block may require a few minutes.
2.5 Using the 1-D Motion Generation App
The example shows how to create a motion profile using the 1-D Motion Generation app in MapleSim.
Double-click the 1-D Motion Generation entry in the Apps palette.
Change the class to Rotational Angle from the Configure section. Note the default units, which are appropriate for this example.
select Add Right from the Waveform Creation.
Change the Height from Segment Properties to 1 and choose Sinusoid from the drop down menu and click Apply.
Click on Add Right again and change the Height to -1 from the Segment Properties.
Change the Model Name to Motion under Model Generation.
And click Generate.
The new motion profile created will be seen in the Local Components tab ( ) in MapleSim.
Download Help Document