Making a Standalone Vortex-Simulink Executable With the Simulink Compiler

Introduction

The Simulink Compiler allows you to make a standalone executable containing your Simulink simulation with the Vortex block. The executable file can be redistributed to systems who do not have a MATLAB installation.

Requirements

  • A Simulink Compiler license.
  • Your Simulink model must only contain blocks from toolboxes supported by the compiler. See this MathWorks documentation page for more details.
  • Your model must successfully execute in Rapid Accelerator mode.
  • The target system (the system that will run the compiled package) will require the MATLAB Runtime to be installed for the same version of MATLAB that was used to create the compiled package.

Compiling a Model to an Executable

There is currently issues with running a Simulink model containing a Vortex block in Rapid Accelerator mode. This will be address in future releases.


  1. Make sure that MATLAB is configured with the path to the Vortex block and other resource files. Please refer to this guide for additional details.
  2. Open MATLAB.
  3. Navigate to your project folder (it could be any blank folder if you are starting for scratch). In order to compile the Vortex block, a current limitation is that the path of the project folder should not have spaces in it. 
  4. Open Simulink
  5. Create a new model and add the Vortex block. Parametrize and connect the block's signals as needed.
  6. Save the model and go back to the MATLAB window. In this example, we will save it as "testcomp".
  7. Right-click in the Current Folder view on the left and select New -> Script.
  8. Name the script however you like, In this example, we will use deploy.m.
  9. Double-click on the script and add the following code in the Editor.

    function deploy() % This function should have the same name as the script.
        in = Simulink.SimulationInput('testcomp'); % Function parameter should be the name of your Simulink model.
        in = simulink.compiler.configureForDeployment(in);
        out = sim(in);
    end

  10. Save the script. - At this point, your project folder should contain the Simulink model you have created in step 5, and the script from steps 9-11. This is all that is required for the Vortex block to be compiled into your Simulink model. 
  11. In the MATLAB Command Window, input the following command:

    mcc -m deploy.m

  12. At this point, the compiler is invoked and if there is any issue with your model you will see warnings and errors in the MATLAB Command Window.
  13. If the compilation succeeds, a .exe file with the same name as your script will be created in your project folder.

Running the Co-Simulation

To generate a compiled Simulink executable containing a Vortex block, Vortex uses a code generation template that connect the Vortex and Simulink instances at the start of the execution of Simulink executable.
Because of this, it is important to remember that you must first launch your Vortex application (e.g. Vortex Studio Editor) before your launch the Simulink executable. Using the automatic launch described in the next section is good way to always make sure of this. Note that if the option to 'Wait for Vortex before start' has been selected in the Vortex S-function block parameters, that the Simulink simulation will idle, and cannot be stopped, until the Vortex simulation is started. 

Keep in mind also that in a model that was compiled to a standalone executable, everything is hard-coded, including the address, port and model name. In order to be able to re-use a compiled model on a different computer, it is necessary that the address and port parameters be given to the compiled model when it is launched. To override the values that were hardcoded in the Vortex block when you compiled the model, the compiled Simulink executable supports the following environment variables.

VORTEX_SIMULINK_ADDRESSThe address defined in the Vortex Simulink Block module.
VORTEX_SIMULINK_PORTThe port defined in the Vortex Simulink Block module.
VORTEX_SIMULINK_IDENTIFIERThe Model Base Name defined in the .json file used to configure the Vortex S-function block

The compiled model will read those environment variables when it is launched, thus allowing it to run on a different context.

Using Vortex to Automatically Launch the Simulink Executable

Your Vortex application can take care of launching and stopping your compiled Simulink executable automatically. The external executable will be launched when your Vortex application starts simulating and stopped when the simulation ends.

Setting this up is quite simple.

  • No need to open Matlab/Simulink
  • Open Vortex Studio Editor.
  • Load the content file containing the Simulink Block extension (a scene, mechanism or assembly).
  • In you content, locate the Simulink Block extension.
  • Select it in the Explorer and look at the Properties.
    The Model Program parameter allows you to specify the path to the executable to be launched. By default, the path will be saved relative to the location of the content file.
  • Once set and the simulation is started, this program will be automatically launched by Vortex.
  • When the simulation is stopped, the program will be terminated.

In Vortex Studio 2022.4 there is an outstanding issue when using the Model Program parameter. When stopping the Vortex simulation, the main Simulink program process will be terminated but not any processes that are created by the main one.
These additional processes must be closed manually through the task manager.