Co-simulation Using TCP/IP
Inter-Process Communication (IPC) co-simulation allows co-simulation to run on the same machine, as well as between different machines/platforms.
IPC co-simulation uses TCP sockets to communicate between the two processes that run solvers. Because TCP protocol is platform independent, this communication type allows communication between different platforms.
Supported Methods for MATLAB/Simulink-Related Co-simulation Using TCP/IP
- Simulink Coder/Real-Time Workshop (RTW) IPC co-simulation.
- Simulink IPC co-simulation.
Two additional DLLs are needed for both IPC co-simulations: nuclient.dll and nuserver.dll. These libraries are used to establish the server-client communication.
For the RTW DLL, there is no change for the existing RTW DLL for it to be loaded. For Simulink IPC co-simulation, the mex DLL needed can be either mscosim or mscosimipc, which is the name entered for the S-Function block.
Note that for a co-simulation with an RTW DLL, MotionSolve drives the simulation (MotionSolve is called first). For a Simulink IPC co-simulation, Simulink is launched and called first. The process that brokers the communication (the TCP/IP daemon) is running on the machine to be called by the driving process.
Required Model Changes
- RTW
- For RTW co-simulation, add the attribute ip_address inside the Control_PlantInput and Control_PlantOutput elements. This attribute contains a string that indicates the IP address (204.235.26.47 or localhost, for example) where the MotionSolve solver will run.
- Simulink
- For Simulink IPC co-simulation, there is no change to MotionSolve XML model. For the Simulink model,
change the name of the S-Function from mscosim into
mscosimipc, or keep the same.
Additionally, you need to specify the IP address of the machine where MotionSolve will be running. To do this, define either a MATLAB variable or the environment variable MS_SERVER_IP_ADDRESS in the MATLAB workspace (for example, MS_SERVER_IP_ADDRESS = 204.235.26.47 or setenv (MS_SERVER_IP_ADDRESS, 204.235.26.47) ).
If you use this method, you will need to specify that each time you start MATLAB, since the variable will not persist after closing MATLAB. If you want to define the IP address only once and will not change it later on, you can define a system-level environmental variable, MS_SERVER_IP_ADDRESS, that points to an IP address where MotionSolve is running. If this environment variable is not found at the time of the IPC co-simulation run, locachost will be used as the default for the IP address.