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
-
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.
- 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 in a manner that is convenient to
you.
The S-Function that represents the MotionSolve model will update accordingly.
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 inputs to and outputs from the S-Function.
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
- Set the environment variables to point to the solver binaries.NUSOL_DLL_DIR <installation directory>\hwsolvers\motionsolve\bin\<platform>
where <installation directory> is the full path to the product installation. <platform> is win64 for 64-bit Windows, and so on.
For example, on Windows 64-bit:set NUSOL_DLL_DIR=C:\<installation_directory>\hwsolvers\motionsolve\bin\win64
- Set the environment variables for licensing:
RADFLEX_PATH <installation directory>\hwsolvers\common\bin\<platform>
PATH <installation directory>\hwsolvers\common\bin\<platform>;%PATH%
(Notice that the product directory is pre-pended to the original PATH).
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.