## 4 RCPetri MATLAB(r) App
### Control Synthesis  
Once the Plant and the Specification are defined as \(IPN\), a regulation controller can be computed in the \"Controller Tab\", which implements the methodology introduced in [20] and resumed in Section 3, synthesizing an \(IPN\) controller that enforces the occurrence of sequences \(\sigma_{k}\) in the Plant to make the output error to be null. For this, the app modifies the Specification output labels (character # is added to each symbol) in order to distinguish them from the Plant output labels, and later, the labels mapping \(\mathbf{\Omega}\) is computed. The computation of the marking mapping \(\mathbf{\Pi}\) is performed by the MATLAB(r) solver \(intlinprog()\). Next, sequences \(\sigma_{k}\) are computed with Algorithm 1. Finally, Algorithm 3 is executed to build the \(IPN\) Controller. Moreover, the app generates the \(IPN\) representing the control program (\(\hat{Q}||\hat{Q}\)) and the closed-loop system (\(Q||\hat{Q}||\hat{Q}\)). ```
1 Input: Plant \(Q\). Specification \(\hat{Q}\). Matrix \(\mathbf{\Pi}\) and sequences \(\sigma_{k}\). 2 Output:\(IPN\) model \(\hat{Q}\) representing the Controller. 3 forach\(\tilde{t}_{k}\in\tilde{T}\)do
4 %Build a controller subnet \(\hat{Q}^{\tilde{t}_{k}}\) as follows:
5 Denote the corresponding sequence \(\sigma_{k}=\hat{t}_{k}^{1}\hat{t}_{k}^{2}...\hat{t}_{k}^{r}\), and let \(\tilde{M}_{k-1}[\tilde{t}_{k}>\) Define a new transition \(\tilde{t}_{k}^{0}\) with identity label \(\tilde{\lambda}_{Id}(\tilde{t}_{k})\). Set \(s=0\). 6 for\(q=1\) to \(r\)do
7 if\(\hat{t}_{k}^{q}\) is controllablethen
8 Update \(s=s+1\). 9 Define a new place \(\hat{p}_{k}^{s}\) and connect \(\tilde{t}_{k}^{s-1}\) to \(\hat{p}_{k}^{s}\). Add the symbols \(\lambda_{I}(\hat{t}_{k}^{q})\) to \(\hat{p}_{k}^{s}\). 10 Define a new transition \(\hat{t}_{k}^{s}\) and connect \(\hat{p}_{k}^{s}\) to \(\hat{t}_{k}^{s}\). Add the symbols \(\varphi(M^{\prime})\) to \(\hat{t}_{k}^{s}\), where \(\mathbf{\Pi}\tilde{M}_{k-1}[\hat{t}_{k}^{1}...\hat{t}_{k}^{q}>M^{\prime}\)
11 Define a new identity label \(\delta_{k}\) and add it to \(\hat{t}_{k}^{s}\). 12 forach\(\hat{p}_{j}\in\tilde{P}\)do
13 Build a controller subnet \(\hat{Q}^{\hat{p}_{j}}\) consisting of a place \(\hat{p}_{j}\), an input transition \(\hat{t}_{k}\) (identity-labeled as \(\delta_{k}\)) for each \(\tilde{t}_{k}\in\tilde{\bullet}\)\(\hat{p}_{j}\), and an output transition \(\hat{t}_{k}\) (identity-labeled as \(\lambda_{Id}(\tilde{t}_{k})\)) for each \(\tilde{t}_{k}\in\tilde{p}_{j}^{\bullet}\). 14 Then, the Controller \(IPN\) model is \(\hat{Q}=\hat{Q}^{\hat{t}_{1}}||...||\hat{Q}^{\hat{t}_{1}}||\hat{Q}^{\hat{p}_{1 }}||...||\hat{Q}^{\hat{p}_{|\tilde{p}_{|\tilde{p}_{|\tilde{p}_{|\tilde{p}_{| \tilde{p}_{|\tilde{p}_{|\tilde{p}_{|\tilde{p}_{|\tilde{p}}_{|\tilde{p}_{| \tilde{p}}_{|\tilde{p}}}}}}}}}}}}}\)
```  
**Algorithm 3**Building the \(IPN\) Controller. **Example 2**. : _Figure 6 shows the automatically generated \(IPN\) control program (i.e., the synchronization of Specification and Controller) for the Plant of Figure 4 and the Specification of Figure 5. Let us explain the behavior of the closed-loop system. For this, keep in mind that the \(IPN\) Plant output symbols are read by the \(IPN\) control to enable control transitions, and vice versa. At the initial state, the Plant provides the sensor signals \(\{XA,YA,VB,ZA\}\) (operation HomeArm at the Specification tables). The first task (\(\text{In\_}2\_RFID\)) starts when the guard signals \(\{S1 On,TagOff,RFIDIdle\}\) are simultaneously active, leading to the firing of the control transition \(t_{1}\), removing tokens from \(p_{1}\) and \(p_{11}\) and marking control places \(p_{2}\) and \(p_{7}\).