## 5 Application Examples
### Tank Filling Process  
This example exhibits the use of \(RCPetri\) for the design and simulation of a logic controller for a tank filling process, simulated in the SCADA software LabVIEW(r), in real-time through the Modbus TCP/IP protocol.  
The tank filling process considered here (adapted from [35]) is described by the piping and instrumentation diagram (P&ID) of Figure 9. The Plant model was obtained by using the industrial process modeling methodology presented in [21]. In this case, the sensors and actuators were modeled as two-state devices. Tank levels were model as variables with three discrete states (empty, low, high), excepting the water tank that also includes the state medium. These states can be inferred by level sensors LT, for instance, for Soap Tank 101, both sensor LT-1 and sensor LT-2 are inactive when the tank is at the empty state, named T1 empty; sensor LT-1 is active and LT-2 is inactive at low state, named T1 low; both sensors LT-1 and LT-2 are active at the high state, named T1 high. In order to ensure controllability, additional input symbols \(\delta\) were added to transitions representing a level change, these  
Figure 8: Displacement-time diagrams showing the sequences performed by each actuator during each of the four tasks defined in the Specification. Times are approximated, obtained by visual inspection.  
allow actuators' controllable transitions to preempt level transitions (\(\delta\) means waiting until the level change).  
For the Specification, two different filling sequences were considered. In the first one, called \"Small\", Soap Tank 103 is supplied by Soap Tank 101, the Water Tank 104 is supplied up to the middle level, next the fluids of Soap Tank 103 and Water Tank 104 are mixed in the Mixing Tank 105. In the second sequence, called \"Large\", Soap Tank 103 is filled by both Soap Tank 101 and Soap Tank 102, while Water Tank 104 is filled up to the high level, then the fluids are mixed in the Mixing Tank 105. The Specification is described in the tables in Figure 10.  
Once the \(IPN\) Specification was synthesized, the Controller was computed. The \(IPN\) closed-loop system is validated by simulation for implementation. The Plant was simulated on LabVIEW(r) as a hybrid dynamical system (the tank levels evolve with continuous dynamics while pumps, valves and sensors evolve as state machines). Figure 11 depicts the tank filling dynamics during the \"Large\" sequence, under the control program being simulated in the app and connected through Modbus TCP/IP. Note that at the end of the filling of Tank 101, the control program allows the Tank 102 to start filling immediately. The simulation showed the effectiveness of the control program, as well as the interaction between \(RCPatri\) and other software (in this case LabVIEW(r)) in real-time. Figure 12 shows the simulation of the Plant synchronized through Modbus TCP/IP with the \(IPN\) control program, when the Water tank is filling the Mixing Tank during the \"Large\" task sequence.  
Figure 10: Tasks, Subtasks, and Shortcuts tables describing the Specification for the Plant of Figure 9.  
Figure 9: \(P\&ID\) of a tank filling process (Plant for the tank filling process example).  
Figure 11: Dynamic behavior of the tanks levels through the “Large” sequence. First, Soap Tank 1 (blue) is filled until sensor LT-2 101 is active; next, Soap Tank 2 (orange) is filled until LT-2 102 is active; then, Water Tank (violet) is filled until LT-3 104 is active; then, both Soap Tank 1 and Soap Tank 2 are drained into Soap Tank 3 (yellow); after this, both Soap Tank 3 and water Tank are drained into Mixing Tank (green); finally the Mixing Tank is drained and the system returns to the initial state.  
Figure 12: Simulation and control of the tank filling process. When the high-level sensor LT2-105 is activated, it will send a signal for the enabled transition to be fired. On the other hand, in the “Simulation Tab” the user can see the output symbols present in the plant.