Making a Co-Simulation Between Vortex and Simulink

Making a Co-Simulation Between Vortex and Simulink



Introduction

The Simulink Plugin comes pre-installed with Vortex. If you have Simulink installed on your system, it allows you to transfer information between Vortex and Simulink while simulations are running, allowing co-simulation between the two pieces of software. This guide demonstrates how to set up the communication link between Vortex and Simulink, and how to run a simulation with the information exchange.

Pre-requisites

  • To follow this guide you need a valid licensed installation of Matlab and Simulink version R2021b.

Configuration

Configuring Vortex

To configure Vortex, the Simulink module must be added to the Vortex application that Simulink will communicate with. In this example we will use the Vortex Studio Editor but it can be done for any Vortex application.

  • Launch the Vortex Studio Editor.

  • Open the setup document (.vxc) of the application which will communicate with Simulink.

    • For the Editor, there is a quick shortcut. Click Options. Navigate to the Setup pane, and, under Application Setup, click the green button indicated below.

  • Once the setup file is open, go to the Toolbox, and search for Simulink. The Simulink Module icon should appear in the toolbox.

  • Double-click on the module to add it to the setup document.

  • Upon being added to the configuration, the properties of the module will appear in the Properties pane. There are three options here:

  • Now, save the setup document by clicking the save button.

  • Vortex is now configured to send and receive information from Simulink. 

Configuring Matlab/Simulink

To configure Matlab/Simulink, the file where the Vortex S-function blocks are stored must be added to the Matlab path in order to make them available for use in the Simulink block library.

  • First open Matlab.

  • Inside Matlab, navigate to the root folder of your Vortex install. Then, further navigate to the bin/matlab folder.

    • The contents of this folder should include 'VortexBlockset.mexw64' as seen below. 

  • Once in this folder, type the following command. This adds the current directory to the Matlab path. 

    addpath(pwd)
  • Using the command path in the Matlab command line will allow you to check that the folder has indeed been added to the Matlab search path.

  • If you wish to permanently add this folder to the Matlab search path (and not just for this session), you can run the command:

    savepath
  • The configuration of  Matlab is now complete. It will now be able to find and use the Vortex S-function block.

Creating the Simulation

The Vortex Simulink Extension

In this section, we will add the Simulink block to a mechanism, and use it to transmit the world transform of a part to Simulink. To provide a demonstration, we will use a Mechanism that contains an Assembly which consists of a single part with a cubic collision geometry. 

  • Open Vortex Studio Editor.

  • Create a new Assembly.

  • In the Toolbox, double-click on Part to add a new part to the assembly.

  • In the Explorer, right-click on the part and select Create Primitive Geometry. Select a Box.

  • Save the assembly.

  • Create a new Mechanism.

  • In the Toolbox, double-click on Assemblies From Files

  • Select the assembly that was just created and click OK.

The content in the Editor should now look like this:

  • Search for the Simulink block in the toolbox, and double click to add it to the Mechanism.
    Upon being added, the Simulink extension contains no variables, but it does have two parameters, 'Model Base Name' and 'Model Program'. You can change 'Model Base Name' to whatever signifier you think is appropriate for your task.

  • In the Explorer, right-click on the Simulink Block extension and select Edit. This will allow you to add variables to the Simulink extension that will be transmitted or received to/from Simulink.
     

  • This brings up the edit field wizard. For this demonstration, we will add a single input, call it inputTransform, and set the type to Transform, we will also add a single output, call it simulinkSignal, and set the type to Double.



  • Clicking OK will add the variables to the Simulink extension.

  • In the Toolbox, search for Connection Container and double click to add it to the mechanism.

  • In the Explorer, click the drop down arrow next to the Assembly extension.

  • Select the Part.

  • In the Properties panel to the right, navigate to the Outputs pane and click and drag the World Transform output variable into the Connections editor view.

  • In the Explorer, select the Simulink extension and drag and drop the 'inputTransform' variable into the connections editor.

  • Connect the World Transform output to the inputTransform input by drag and dropping between the two circles.

  • Now that we have configured the Simulink extension and determined exactly what variables we will need, we need to create the file which will communicate this information to Simulink.
    To do this, right-click on the Simulink Block extension in the Explorer, and select the Export configuration option. 

  • Save the file with a name and a location of your choosing. It will be needed later to connect Simulink to Vortex.