Caspoc - Simulink Co-Simulation

Compared to the classical coupling the Co Simulation between Caspoc and Simulink is much easier to use and all functionality of Caspoc is included in the co-simulation. Also all scopes in Caspoc can be used as wel as the aniumation features. The interactive components in Caspoc are also enabled during the co-simulation.

The co-simulation is based upon data exchange between Caspoc and Simulink at every time step. The simulation in Simulink is controlled from Caspoc. In this way, the control can be implemented in Simulink and co-simulated with a simulation in Caspoc.

Co-Simulation process

There are some basic steps to perform to couple the simulations. The co-simulation is easy to set up and both simulators show simulation results in their own scopes. The co-simulation is controlled from Caspoc where a co-simulation is initiated and started. The process for the co-simulation is given the process number 2, as can be defined in the co-simulation properties dialog box. In general there is no input from the user required in this properties dialog box.

Communication blocks

The data exchange during the simulation is done in the block diagrams in Caspoc and Simulink.

The following blocks are used for the communication:

Caspoc: The blocks ToLF and FromLF that can be found in "components/Block/CoSimulation" The block ToLF sends data to Simulation, the block FromLF received data from Simulink. <br>Click to close the image
Simulink: The block S-Function that can be found under "Functions and Tables" represents the coupling to Caspoc. Actually the block S-Function represents the complete Caspoc Simulation. The block Mux and Demux are required to create more inputs and outputs for the S-Function. <br>Click to close the image

There are multiple inputs and outputs possible in the co-simulation. Therefore you can define which block in Caspoc is connected to an input/ouput in Simulink. This is done by numbering the blocks in Caspoc

The blocks also have to be parameterized:

Caspoc: In the ToLF and FromLF blocks you specify the process ID and the number of the input for the Mux and Demux blocks in Simulink. Set the proces ID equal to 2. This indicates that the block is performing a co-simulation under process number 2, being the Caspoc-Simulink co-simulation. At the edit field "Text2" you specify the number of the input/output in simulink.

Properties for the ToLF block: <br>Click to close the image
Properties for the FromLF block: <br>Click to close the image If you would have 3 inputs and 5 outputs in Caspoc (and also 3 inputs to the S-Function and 5 outputs from the S-Function in Simulink), you can use the number 1 .. 3 for the FromLF blocks and 1 .. 5 for the ToLF blocks. <br>Click to close the image

Simulink: In the S-Function you specify the file name c2sdll at function name. The name c2s will be displayed in the S-Function block. That is all there is to do. Well don't forget to also have the c2s.dll function in the same directory as your simulink example, or create an appropriate path in Matlab. <br>Click to close the image
Simulation Parameters in Simulink

The simulation in simulink also has to be parameterized in order to work with Caspoc. Select the properties as indicated in the properties dialog box for the simulation parameters and give the correct values for the simulation times and step size.

<br>Click to close the image Start the Simulation

To start the co-simulation, you first have to initialize the co-simulation in Caspoc. This will set up the communication.

Caspoc: Select "Options/Co-Simulation/Initialize and Start" and next select "Simulation/Start Simulation". The co-simulation is started and waits for simulink. <br>Click to close the image Simulink: In simulink, select "Simulation/Start" to start the simulation. The co-simulation is now running. <br>Click to close the image Stop the Simulation

You can stop the co-simulation in Caspoc by selecting "Options/Co-Simulation/Stop". If Caspoc is not responding after you select it from the menu bar or via Alt-TAB, you can cancel the co-simulation by clicking the [Esc] button on your keyboard. <br>Click to close the image

© 2018 CASPOC, All rights reserved. Home   |   Terms and Conditions   |   Legal   |   Export Compliance   |   Privacy Policy   |   Site Map