# Engineering Method and Tool for the Complete Virtual Commissioning of Robotic Cells
## 3 Proposed Virtual Commissioning Approach
### Description of the Signal Exchange Mechanism  
As mentioned before, according to the devices utilized in the cell and the required signals, the user adds the necessary I/O signals, providing a name which corresponds to the desired variable in TC to be connected. As an example, a variable could be named as \"MAIN.Robot1.busy\". This means that, in the PLC code, a variable named \"busy\" is searched in the instance \"Robot1\" of a function block that likely includes the characteristics of a specific robot type; the instance \"Robot1\" has been declared in the program organization unit (POU) named \"MAIN\". Essentially, such expedient represents a direct means to map RobotStudio signal names to TC variables. In the following, pseudocode of the PLC_Beckhoff SC (Algorithm 1) outlines the initialization of the communication by mapping the RS signals to TC variables. _IOS_ refers to the collection of signals managed from the PLC_Beckhoff SC, which is cycled to instantiate a SignalMapInfo object _mi_ for each element to be mapped with the PLC. Such objects are then stored in two sets, named _SI_ (i.e., input signals of the PLC_Beckhoff SC, going from RS to TC) and _SO_ (i.e., output signals of the PLC_Beckhoff SC, going from TC to RS). To synchronize the value of an RS signal with TC and vice versa, the mapping data include:  
* A reference to the RS signal object;
* A pointer to the handle properly created to reach the desired variable in TC from the user specified name;
* The last exchanged value of the signal. Figure 3: Default appearance of the PLC_Beckhoff SC in RS. **(a)** Graphic user interface of the SC in the Station Logic section of RS: in the figure, no signal to be exchanged with the PLC has yet been defined; **(b)** SC in edit mode: the user can use this form to configure ADS connection options and create signals that are required for specific applications. ```
InitializeCommunication() in: TC client host name \(t\)_tHostName_, TC client port name \(t\)_tPortName_, set of IO Signals \(IOS\) from RS out: TC connected client \(ads\) set of input signals \(SI\) (from RS to TC) set of output signals \(SO\) (from TC to RS) local: current RS signal \(s\) being considered, signal mapping info \(mi\)
1:\(\triangleright\) Instantiation of the ADS connection
2:\(ads\leftarrow connect\) (\(t\)_tHostName_, \(t\)_tPortName_)
3:\(\triangleright\) Instantiation of the signal maps
4:\(\mid\)MI\(\mid\gets 0\)
5:\(\mid\)MO\(\mid\gets 0\)
6:\(\triangleright\) Instantiation of a signal info map \(mi\) to TC for each RS signal
7:for all\(s\in LOS\)do
8:case name(s) of
9:\(``Start\"\):\(\triangleright\) Nothing to do
10:\(``Stop\"\):\(\triangleright\) Nothing to do
11:\(``CreateSignal\"\):\(\triangleright\) Nothing to do
12:\(``DeleteSignal\"\):\(\triangleright\) Nothing to do
13:others:
14:\(\triangleright\) Instantiate and populate mapping info \(mi\)
15:\(mi\leftarrow\)CreateMappingInfo(s)
16:\(rsSignal(mi)\gets s\)
17:\(t\)_Handle(\(mi\))\(\leftarrow\)CreateTCVariableHandle(\(ads\), name(s))
18:\(lastValue(mi)\leftarrow value(s)\)
19:\(\triangleright\)Add \(mi\) to the proper set
20:if\(isInput(mi)\)then
21:\(\text{AddElement(}MI,mi)\)
22:else
23:\(\text{AddElement(}MO,mi)\)
24:endif
25:end case
```  
**Algorithm 1** Communication initialization  
When the button Start is clicked, the ADS connection is established and the handle variables are automatically created due to the initialization procedure described above. After that, RS simulation can also be run. As long as the simulation is active, an event handler called OnSimulationStep is called for every RS elementary simulation step. The code executed at each step iteration includes two methods:  
* RobotStudioReadTwincatWrite, which updates the values of variables in TC from signal changes in RS;
* TwincatReadRobotStudioWrite, which changes the status of signals in RS as a variable value is changed in TC. The pseudocode of the first of the two functions is reported below (Algorithm 2). The other function has a specular structure.