Co-simulating Using TCP/IP

Inter-Process Communication (IPC) co-simulation is an extension of the existing Shared Memory Process (SMP) co-simulation. It allows you to run co-simulation 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 Co-simulation using TCP/IP

Two IPC co-simulation modes are supported:
  • 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 in order to be loaded. For Simulink IPC co-simulation, the mex DLL needed is 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

The following model changes are required for the two different ways to use TCP/IP communication: RTW co-simulation and Simulink co-simulation.
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 RTW solver will run. If it is missing, localhost will be used as the default IP address.
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.

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.

Running an RTW IPC Co-simulation

  1. Change a RTW XML model into an IPC model by adding the ip_address attribute to Control_PlantInput and Control_PlantOutput as described above.
  2. On the machine where ip_address points to, for example, the machine with the RTW DLL, issue the following command:
    msdaemon < ip_address string>
    For example 204.235.26.47

    Please note that the required RTW DLL needs to be in the search path on that machine. The msdaemon.exe file resides in the MotionSolve installation directory: <HyperWorks_install_dir>\hwsolvers\motionsolve\bin\<platform>

    This is the only file required on this machine, and may be copied from another installation of the same platform.

  3. In the machine where the XML model resides, issue a normal MotionSolve run command as:
    msolve xml_name mrf_name

    Note that mbd_d.exe would also work instead of msolve.exe

    The co-simulation should now run to completion.

Running a Simulink IPC Co-simulation

  1. Change a Simulink model into an IPC model by:
    1. Changing the S-Function name to mscosimipc.
    2. Define MS_SERVER_IP_ADDRESS either inside a MATLAB workspace or as environmental variable, which are described above.
  2. On the machine where the MotionSolve XML model resides, issue the following command: msdaemon.
    This process loads nuserver DLL and later on loads nusolver DLL to run MotionSolve model. The name of XML model to be run is defined in the Simulink model.
  3. On the machine where Simulink model resides, launch the Simulink model and run the simulation.
    The co-simulation should now run to completion.
    Note: The ip_address attribute to Control_PlantInput and Control_PlantOutput is not used by Simulink IPC co-simulation.
    If the parameter ip_address points to a local machine, which is localhost, you only need to issue the command to start the process that drives the co-simulation ( MotionSolve for RTW IPC co-simulation; Simulink for Simulink IPC co-simulation), and not start a separate msdaemon process, which is done automatically.