# Petri Net-Based Semi-Compiled Code Generation for Programmable Logic Controllers
## 3 Use Case
### Manufacturing System Automation
#### 3.3.1 PN Implementation by Means of the Proposed Approach  
For both implementations carried out on PLCs from different vendors, the procedure described in Section 2.2 was applied and the following starting points were assumed:  
* Project created in the development environment, and the PLC hardware used properly configured. * In device program memory:
* Created program block structure. * Coded the content of fixed blocks, corresponding to PN marking evolution management. In Siemens environment, as a result of the first algorithm development and subsequent testing. For Omron, as a result of code transfer. It should be noted that, for a first implementation in a new development environment, compilation errors may occur as a result of the platform-specific editing procedure. Often, PLC program editing task needs variable name recognition, thus it should be written literally at its very first appearance in a programming module. In that case, simple copy-paste does not work properly. * Blocks related to PN interpretation, empty. * In device data memory:
* Variables corresponding to inputs and outputs, and specific to algorithm, declared. * Variables associated with PN structure were not declared, as they were transferred from the design and simulation package through proprietary software. and \(M_{2}\) machines, respectively, with places representing their loading, processing, and unloading. The model is completed with \(M\) place, the shared-use robot, and two places, \(H\) and \(O\), representing free and occupied positions, respectively, of the intermediate buffer, conveniently initially marked. It was decided initially being three occupied positions (number or tokens at \(O\) place) and four free positions (initial marking of place \(H\)). \begin{table}
\begin{tabular}{l l l} \hline \hline
**Place** & **Action** & **Description** \\ \hline \(H\) & - & Buffer free positions. \\ \(M\) & - & Robot, shared use. \\ \(O\) & - & Buffer occupied positions. \\ \(p_{10}\) & - & Wait until station 1 (\(M_{1}\)) can be loaded. \\ \(p_{11}\) & \(CM1\) & \(M_{1}\) loading signal. \\ \(p_{12}\) & \(PM1\) & \(M_{1}\) processing signal. \\ \(p_{13}\) & - & Wait until \(M_{1}\) can be unloaded. \\ \(p_{14}\) & \(DM1\) & \(M_{1}\) unloading signal. \\ \(p_{20}\) & - & Wait until station 2 (\(M_{2}\)) can be loaded. \\ \(p_{21}\) & \(CM2\) & \(M_{2}\) loading signal. \\ \(p_{22}\) & \(PM2\) & \(M_{2}\) processing signal. \\ \(p_{23}\) & - & Wait until \(M_{2}\) can be unloaded. \\ \(p_{24}\) & \(DM2\) & \(M_{2}\) unloading signal. \\ \hline
**Transition** & **Condition** & **Description** \\ \hline \(t_{10}\) & _PE_ & Part at input point. \\ \(t_{11}\) & _PCM_1 & Part loaded in \(M_{1}\). \\ \(t_{12}\) & - & Direct. \\ \(t_{13}\) & - & There are resources for unloading \(M_{1}\). \\ \(t_{14}\) & _EB_ & Part in buffer input. \\ \(t_{20}\) & _SB_ & Part in buffer output. \\ \(t_{21}\) & _PCM_2 & Part loaded in \(M_{2}\). \\ \(t_{22}\) & - & Direct. \\ \(t_{23}\) & - & There are resources for unloading \(M_{2}\). \\ \(t_{24}\) & _PS_ & Part at output point. \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Interpretation to be added to the PN structure shown in Figure 9.  
Figure 9: PN structure modeling manufacturing cell behavior. PN interpretation to be added to the net structure is contained in Table 2. Actions (command signals through PLC digital outputs) were associated to places and conditions (sensor status queries) to transitions. Note that processing tasks were simulated by means of timers, so conditions \(FPM1\) and \(FPM2\) correspond to their endings. Places \(p_{13}\) and \(p_{23}\) do not have associated actions, as they correspond to waiting places for the necessary resources to face the respective machines unloading. After PN structural analysis (Section 2.2.2) and matrix generation (Figure 10), structural data transfer was carried out (Section 2.2.3), previously converted to the syntax of the target development environment using a proprietary application.