Simulink Coder Co-simulation with MotionSolve

Simulink Coder may be used to generate a library that represents the Simulink model and runs with MotionSolve. The following provides the main steps involved.

For complete details, see MV-7005: Linking Matlab/Simulink Generated Code (Simulink Coder) with MotionSolve.

Planting Inputs and Outputs

Create one or more Control: PlantInput and Control: PlantOuput that stores a list of the input and output variables that are passed between MotionSolve and Simulink. For more details, see those statements in the MotionSolve Reference Guide and some of the other FAQ’s listed here.

The input variables from Control_PlantInput can be accessed via a PINVAL() or VARVAL() function, and the output variables from Control_PlantOutput are usually runtime functions (for example, DZ(), for displacement) going to Simulink.

Create the number Control_PlantInput's and Control_PlantOutput's as Inports and Outports, respectively, (for example, one Control_PlantInput for each Outport) in the Simulink model to setup the proper interface communication.

The order of the Control_PlantInput's and Control_PlantOutput's found in the MotionSolve model (.xml) (by line number, from top to bottom) should match the order of the IDs for the Outports and Inports, respectively, in the Simulink model to ensure the variables are exchanged in the proper order.

For a Simulink Coder library co-simulation, set usrsub_param_string to have one integer that will uniquely identify the Simulink Coder library used. This number (ID) should be the same for all Control_PlantInput's and Control_PlantOutput's that are used for this Simulink Coder library.

Creating Simulink Inports and Outports

The next main step is to create or confirm that your Simulink model has Inports and Outports that match the corresponding Control_PlantOutput's and Control_PlantIntput's, respectively.

Setting Up the Simulink Coder

Simulink Coder configured and used to generate a set of source code in C++ that can be used to build a library in the next step.

Building the Simulink Library in Compiler

Finally, the source code is loaded into a compiler and modified. The compiler is configured and you can build the library. An installation of MATLAB and MotionSolve is needed to complete this process. After the library is generated, it no longer requires a license to use it.