MotionSolve and Simulink Co-simulation Prerequisites
- In the model, create the plant inputs and outputs from the model to the
other (for example, Simulink) model.
- The inputs should be applied using PINVAL() or
VARVAL() (for example, to define forces from
Simulink). Note: The arguments that need to be specified for PINVAL() are different from the ones for VARVAL(). Please refer to the Reference Guide for details on the syntax.
- The outputs should use functions that provide values to Simulink (for example, DZ() for displacements).
- The inputs should be applied using PINVAL() or
VARVAL() (for example, to define forces from
Simulink).
- In the environment that will run MATLAB/Simulink, set the environment variables needed by to be called from the other simulation software (for example, Simulink).
- In MATLAB, set the search path for MATLAB/Simulink to find the S-Function library in the installation that is required for co-simulation.
- In the Simulink model used for co-simulation, add an S-Function block that represents the model, and enter the proper arguments for the S-Function.
Plant Inputs and Outputs
Set Up Environment Variables to run MotionSolve from MATLAB/Simulink
- Control Panel (Windows)
- In the shell/command window that calls MATLAB (for example, with the set command on Windows)
- Within MATLAB, via the setenv() command
Note that other optional environment variables may be set for your model. See MotionSolve Environment Variables for more information on these environment variables.
Set the Search Path for MATLAB/Simulink
The core feature in Simulink that creates the co-simulation is an S-Function (System Function) block in Simulink. This block requires an S-Function library (a dynamically loaded library) to define its behavior. MotionSolve provides this library, but the S-Function needs to be able to find it. To help MATLAB/Simulink find the S-Function, you need to add the location of the S-Function to the list of paths that MATLAB/Simulink uses in order to search for libraries.
The S-Function libraries for co-simulation with MotionSolve are called either:
mscosim - for IPC communication
mscosimipc - for IPC (TCP/IP sockets) communication
Changing the name of this library in the S-Function block in Simulink changes the communication behavior of the co-simulation.
These files are installed under <installation directory>\hwsolvers\motionsolve\bin\<platform>.
The location of these files needs to be added to the search path of MATLAB for the S-Function to use mscosim or mscosimipc.
This can be done in one of the following ways:
- Use the menu options:
- Use MATLAB commands:
Add the S-Function Block for Simulink that Calls MotionSolve
An S-Function (system-function) block can be found in the Simulink User-Defined Functions block library. An S-Function allows you to model any general system of equations with inputs, outputs, states, and so on, and is somewhat analogous to a Control_StateEqn in MotionSolve. See the MATLAB/Simulink documentation for more details.
After creating it, you will need to enter the arguments described in MotionView S-Function in Simulink Arguments.
For an example of this process, see the tutorial MV-7002: Co-simulation with Simulink.