20.6.8.4. CoSim
The CoSim block is for co-simulation between CoLink and User program. This block needs to use RecurDyn Solver with RecurDyn model.
20.6.8.4.1. CoSim Block
Dialog box
![../_images/image207.png](../_images/image207.png)
Figure 20.134 COSIM dialog box
Parameter(s) |
Description |
Sampling Period (Control Time Step) |
Enters the number of data from User program to CoLink. |
Waiting Time (msec) |
Waits the first communication with Simulink as inputted time. (Unit:MilliSecond). |
Input (Colink =>Control SW) |
Sets variables that define monitoring states from CoLink. |
Output (Control SW=>Colink) |
Sets variables that define actuator forces from control system design tools. |
For the synchronous simulation of control design tool and RecurDyn, following four steps are required as shown in Figure 20.135.
![../_images/image208.png](../_images/image208.png)
Figure 20.135 Four-step process
20.6.8.4.2. Using CoSim Block
RecurDyn/CoLink supports only User Program host mode. The user has to open the RecurDyn and Colink models.
Step I
Build or Open the RecurDyn model
Any RecurDyn model can be used in this interface.
Build or Open the CoLink model
Any CoLink Model can be used in this interface.
Make sure the CoLink model is correct.
The CoLink model and RecurDyn model must be free of simulation errors. The modeling errors must be fixed in this step. If not, it is very difficult to modify the model in co-simulation.
Step II
In RecurDyn
Identify plant inputs.
Define plant inputs and their variable names in the given list.
Identify plant outputs.
Create the plant outputs and define them using the general expression function.
Step III
In CoLink
Identify inputs and outputs.
Drag and Drop CoSim block in modeling window.
Set variables as inputs and outputs.
Connect input ports and output ports to other blocks with lines. The ports are created as much as variables.
Enter the Sampling Period and Waiting Time.
Step IV
In User Program
Library files: <Install Dir>\Toolkit\CoSim\CoSim_V8_Operator_DLL.lib, CoSim_V8_Operator_DLL.dll, CoSimGeneral.h
Interface Function
RunSimulation:
wchar_t *ModelName
double endtime
int plotstep
double interfacestep
This function must be called only one before interfacing.
ParameterName |
Unit |
Input/Output |
Type |
Description |
ModelName |
[ -] |
Input |
Wc har_t |
Is CoLink model name |
endtime |
[ -] |
Input |
double |
Is the simulation end time |
plotstep |
[ -] |
Input |
int |
Is RecurDyn request step |
interfacestep |
[ -] |
Input |
double |
Is the sampling period |
CommunicateRecurDyn:
double sim_time
int iNPin
int iNPout
double *dPIN
double *dPOUT
double *rd_time
int *error
This function must be called once at interface time step.
Parameter Name |
Unit |
Input/Output |
Type |
Description |
sim_time |
[ -] |
Input |
double |
Is the simulation time |
iNPin |
[ -] |
Input |
int |
Is the number of plant input |
iNPout |
[ -] |
Input |
int |
Is the number of plant output |
dPIN |
[ -] |
Input |
double |
Is the values of plant input |
dPOUT |
[ -] |
Output |
dou ble |
Is the values of plant output |
rd_time |
[ -] |
Output |
double |
Is the RecurDyn simulation time |
error |
[ -] |
Output |
int |
0: no error 1: The model is abnormally stopped 2: The RecurDyn don’t respond. 3: Interface time don’t match. |
GetStatusRecurDyn:
StatusRecurDyn* statusRD
int* error
This function must be called once at interface time step.
Parameter Name |
Unit |
Input/Output |
Type |
Description |
statusRD |
[ -] |
Output |
Stat usRecurDyn* |
Returns the number of plant inputs and plant outputs. |
error |
[ -] |
Output |
Int* |
error>0 : no error |
GetStringPlantInput:
int seq
char* chDirectory
int* error
Parameter Name |
Unit |
Input/Output |
Type |
Description |
seq |
[ -] |
Output |
int |
Returns the sequence of plant input. |
seq_input |
[ -] |
Output |
char* |
Returns the string of plant input defined the seq. |
error |
[ -] |
Output |
int* |
error>0 : fails to return. |
GetStringPlantOutput:
int seq
char* chDirectory
int* error
Parameter Name |
Unit |
Input/Output |
Type |
Description |
seq |
[ -] |
Output |
int |
Returns the sequence of plant output. |
seq_output |
[ -] |
Output |
char* |
Returns the string of plant output defined the seq. |
error |
[ -] |
Output |
int* |
error>0 : fails to return. |
CloseRecurDyn();
This function must be called only one after interfacing.
StopRecurDyn();
This function must be called only one after interfacing.
Step V
In User Program
Co-Simulation
Execute the user program.