Algorithm to Convert Signal Interpreted Petri Net models to Programmable Logic Controller Ladder Logic Diagram Models

Signal Interpreted Petri Nets (SIPN) modeling has been proposed as an alternative to Ladder Logic Diagram (LLD) modeling for programming complex programmable logic controllers (PLCs) due to its high level of abstraction and functionalities. This paper proposes an algorithm to efficiently convert existing SIPN models to their LLD models equivalences. In order to automate and speed up the conversion process, matrix calculation approach is used. A complex SIPN model was used to show that existing conversion technique must be expanded in order to cater for a more complex SIPN models.

. LLD for a simple safety circuit evolves into a very important tool in PLC implementation, research on both areas started to merge together at the end of 1990's.

Ladder Logic Diagram
An LLD models the actual combination of relay contacts. A relay contact or a step in LLD is either normally closed (NC) such as alarm, or normally open (NO) such as main in Figure 1. They are controlled by logical inputs and state variables which are represented by labels. When an input triggers the step, the corresponding relay state changes to the opposite state, i.e., the NC step is turned ON while the NO step is turned OFF. The combination of NC and NO will affect the Output Coil which corresponds to a relay state.
In any LLD such as in Figure 1, the rungs are connecting the power source represented by the vertical bar on the left, and the ground represented by the vertical bar on the right. Each rung can be divided into two parts: at the end of the rungs on the right are the outputs, while the rest on the left are the step inputs. The combination of the step inputs in a rung is also known as the network input. The combination of all rung outputs in a LLD represents a state. The state can change if any of the output changes due to changes in any of the step input. Thus, the LLD state varies depending on the steps combination. The step inputs change either changes directly from external or physical inputs or due to the feedback from the other rungs outputs.
This LLD implements the synchronous assignments of the Boolean equations as: start = main • safe • alarm stop = emgcy + power + pause run = (start + run) • stop Further, these output changes can be classified either as synchronous process, sequential process, or combination of both. Sometimes, the difference is hard to notice without any systematic analysis.

Signal Interpreted Petri Net
Signal Interpreted Petri Nets (SIPN) is an extension of Condition/Event Petri Nets which allows the handling of binary I/O-signals in a well-defined way. They are well suited to design control algorithms for discrete event systems resulting in languages standardized in IEC 61131-3. SIPN are defined as a 10-tupel SIPN = {P, T, F, m0, I, O, φ, ω, Ω, v} where {P, T, F, m0} is ordinary Petri Net. To become SIPN, the extensions are as: I -input signals, |I| > 0, φ -Boolean function in I at T, Ω -output function combines the output ω of all marked places O -output signals, |O| > 0 and I ∩ O = Ø ω -a mapping associating evert Place with an output v -variable definition assigns a numerical data type

907
For a more formal definition of SIPN, see [1], [5] and [18]. The dynamic Behavior of an SIPN is given by the firing process defined by four rules: 1. A transition is enabled, if all its pre-places are marked and firing ensures binary marking of all its postplaces. 2. A transition fires immediately, if it is enabled and its firing condition is fulfilled. 3. All transitions that can fire and are not in conflict with other transitions fire simultaneously.
The firing process is iterated until a stable marking is reached (i.e. until no transition can fire anymore). Since firing of a transition is supposed to take no time, iterative firing is interpreted as simultaneous, too. For that reason, no changes of input signals may occur during the firing process. After a new stable marking is reached, the output signals are computed according to the marking and the signal algebra.

RELATED WORK
Although PN has many advantages over LLD, PLC with LLD as the design entry is the most widely available in the world. In order to make PN being accepted by existing LLD users, it is important existing PLC tools and common design techniques can still be reused.

PN to LLD
There are many works related to PN to LLD conversion e.g. [1], [3], [8]- [16]. Work [9] is an important survey on all related works on LLD. After some comparison on various techniques in [1], [3], [10], [11], [14]- [16], the work done in [1] is the best for the job. Their method provides systematic conversion, isolation from input and output networks, and make the LLD program more readable in order to locate the fault in LLDs which is a vital issue. These consideration is important to reduce design time and also debugging and maintenance time. Their method can be extended for SIPN, Timed and Coloured PN.
The conversion process is important due to two important factors: maintaining LLD modeling paradigm so that users can verify their work using known concept, and validate the PN model that it is constructed as it was intended to be. Another important thing about their method is the LLD outcome is very neat and systematic.

Previous PN to LLD Conversion
The method proposed in [1] was to identify PN subnets for four different patterns as summarized in Figure 3. The patterns can be divided into four types in two pairs of set and reset a rung. The set rule is the condition to activate a rung while the reset rule is the condition to deactivate a rung. The set rules consist of two general structures known as Type I and Type II. Meanwhile the reset rules consist of two general structures known as Type III and Type IV. The detail explanation of the rules can be referred in [1].

PROPOSED PN TO LLD CONVERSION
In order to automate and speed up the conversion process, both PN and LLD subnets were analyzed in their equivalent sub-Incidence Matrices (sub-IM) and sub-Boolean equations (sub-BE) as shown in the sub-sections 4.1.

Incident Matrices Method
The output coil in a PLC is denoted by a place, P is renamed as Pj, the k-th feedback input step is P k , the n-th step inputs t as T 1 , T 2 , to tn as T n , the analysis on the sub-IM and sub-BE were done on all types of pattern as illustrated in Figure 3. By referring to previous researcher [1], basically there are four types of patterns to be identified in the PN. These incudes Type I, Type II, Type III and Type IV. The rule is the value '1' is the output of the transition, (P j ), while the value '-1' is the input of the transition, (P k ). The subincidence matrix and sub-Boolean equation for each Type is discussed: i. The sub-incidence matrix for Type I: ii. The sub-incidence matrix for Type II: iii. The sub-incidence matrix for Type III: The sub-Boolean equation for Type I can be written as: P j = (P 1 .P 2 .P 3 . ... .P k ).T 1 The Boolean equation is generalized as : The sub-Boolean equation for Type II can be written as: The Boolean equation is generalized as : ( 2 ) P 0 P 1 P 2 P 3 ... P n T 1 -1 1 1 1 ... 1 The sub-Boolean equation for Type III can be written as: P 0 = ... + P 0 .(P k + T 1 ) The Boolean equation is generalized as : ) Where,

,
The equations are analyzed column by column (k) and row by row (i) starting with the top row (i=0). These general forms equations are important in the subsequent analysis.

Custom Transition for LLD
For PLC implementation using LLD model, it is a common practice to have a single step input to activate or deactivate a rung. In a PN model, the equivalent element to activate or deactivate an output coil is done by source and sinks transitions respectively. By using them, there is no need to initialize any place with a token. But this will result in the PN sub-net incomparable with any of pattern types proposed in [1]. Previous analysis shows that the Boolean equation can be automated only if there are value '1' as the output/input and value '-1' as input/output respectively in a row. The algorithm does not have a solution if in the row there is only positive numbers or negative numbers as shown in example LLD Type I in Figure 4 and LLD Type II in Figure 7. The patterns do not exist in the PN model to be converted due to; a) All positive or all negative coefficients which indicate the source transition or sink transition only. However, these types of incomplete pattern always exist in PLC applications. b) Meanwhile, for Type I or Type III does not exist complete pair of transition c) On the other hand, Type II or Type IV does not have complete pair of input and output transition.
In order to obtain the correct results, PN models should have the complete pair of transition. Meanwhile, to generate a Boolean equation if there are only value '1' and value '0', or value '-1' and value '0' is by adding a temporary (temp) Place in Petri Nets and it will become wire in the Ladder Logic Diagram.

Type I
Type I PN subnet presented in [1] consists of one transition, one place and one arc as shown in Figure 4 which has incomplete pair of arc.
In order to solve the problem, the incident matrices is used to provide complete pair of input and output arcs by adding a temporary (Temp) Place in Petri Nets as illustrated in Figure 5. The temporary place also acts as the current activated place denoted by a token.
The equivalent LLD rung by using type I is shown in Figure 6 on the left. Since step Temp is always ON, the input is always connected and acts as a wire as shown in Figure 6 on the right. This procedure will P 0 P 1 P 2 P 3 ... P n T 1 -1 1 0 0 ... 0 T 2 -1 0 1 0 ... 0 ... T n -1 0 0 0 ... 1 The sub-Boolean equation for Type IV can be written as: P 0 = + P 0 .(P 1 + T 1 ).(P 2 + T 2 ).(P 3 + T 3 ). ... .(P n + T n ) The Boolean equation is generalized as :   [1] can always be used in a source transition. The similar procedure is also applied for Type II pattern where the temporary input step will be replaced with a wire. Figure 6. Final LLD rung for PN subnet Type I

Type III
Type III PN subnet presented in [1] consists of one transition, one place and one arc as shown in Figure 7 which has incomplete pair of arc.

Figure 7. A PN subnet with a sink transition
In order to solve this problem, the incident matrices is used to provide a complete pair of the arcs by adding temporary (Temp) Place in Petri Nets as depicted in Figure 8. The temporary place also acts as the token destination when the current token is removed from the active place.

Figure 8. A subnet to be deactivated by T1
Since it is a reset activity, the equivalent LLD rung by using type III is shown in Figure 9 on the left. Since step Temp will be OFF when it is activated, the input is always opened and acts as an open connection as shown in Figure 9 on the right. This procedure will ensure technique in [1] can always be used in a sink transition. The similar procedure is also applied for Type IV pattern where the temporary input step will be replaced with an open connection. The technique to use temporary step in generating the equivalent subnet LLD is important to ensure consistency in the original algorithm in [1]. Once it is consistent, it is easier to develop the program in a computer.

Critically Unavailable Pattern
In a complicated PN model such as in Figure 2, certain places cannot be converted since the subnets do not resemble any existing pattern types in [1]. Previous proposed technique in Section 4.2 cannot be applied since the subnets in Figure 2 are complete subnets. Thus, further adjustment is needed.
i. SET Figure 10 shows a P 4 subnet of SIPN from Figure 2. The subnet is going to be activated or set at P 5 . This type of structure does not exist in type I, II, III and IV. If the process is automated, the pattern can be wrongly interpreted as Type III since both look similar. But Type III is for reset.
There is more than a single place connected to transition TP1. If the transition is activated, all the places connected to the transition will be activated. This also means P9 can be ignored since the place to be set is P5. Based on this assumption, the subnet has become a Type I pattern. ii.
RESET Figure 11 shows a subnet of SIPN from Figure 2. The pattern can be wrongly interpreted as Type I since both look similar. But Type I is for set while this is a reset. Figure 11. A PN subnet from Figure 2 for reset A transition at T6 is shared with P1 and P7. To disable P1, P7 must also active so that T6 can be activated. Using transformation technique, one of the place can be combined with the transition and eliminate the combined place from the subnet as shown in Figure 11 on the right. After the transformation process, the PN can be categorized as Type III. Now, result from transformation is no longer pure PN, it is known as signal interpreted petri net (SIPN). The subnet IM is as: The subnet IM is as: P 4 P 5 P 9 TP 1 -1 1 1 The subnet IM can be generalized further as: Given one or more source places, P s and a set of destination places, P d a single destination place, P j can be converted at a time by transforming other source places so that Type III subnet can be generalized as:
SET Figure 12 shows a subnet of SIPN from Figure 2. The subnet is going to be activated or set at P 4 . This type of structure does not exist in type I, II, III and IV. To simplify the subnet, place P 8 can be ignored for the same reason as in Type I. P1 and P7 places are combined to transform into a new subnet as shown in Figure 12 on the right. The transformation is like in Type III but the subnet is more complicated than the example in Type III.  Given one or more source places, P s for one transition, P j can be converted at a time by transforming other source places so that Type II subnet can be generalized as: Where: , Analyze column by column (k) and row by row (i) starting with the top row (i=0) iv.
RESET Figure 13 shows a subnet of SIPN from Figure 3. The subnet in Figure 13 is the most complex subnet due to feedback places and shared transitions at T 7 .P 5 . Due to feedback places and shared transitions, the PN can be seen as Type I due to two input transitions which indicates the SET rung. However, Figure 13 (middle) shows the RESET rung, and the simplification and by eliminating redundant of P 5 , the Figure 13 (right) gives the correct interpretation of Type IV RESET rung Figure 13. PN for Type IV Given one or more source places, Ps for one transition and one or more destination places, P d for one transition, P j can be converted at a time by transforming other source and destination places so that Type IV subnet can be generalized as: The sub-BE can be written as: a) P 0 = (P 1 .T 1 ) + (P 2 .T 2 ) + (P 3 .T 3 ) + ... (P n .T n ) b) The Boolean equation can be generalized by following this formula: Original subnet IM is as below: P 4 P 5 P 9 P 11 T 2 -1 1 1 0 T 7 -1 -1 0 1 After transformation: P 4 TP 4 P 11 T 2 -1 1 0 TT 4 -1 0 1 The subnet IM can be generalized further as below: By using matrix calculation, the results is shown: Where: , Figure 14. LLD for robot arm system from SIPN in Figure 2 Indonesian  Figure 2 is a complete and complex SIPN model which is used to control a robot arm. The controller was developed using a PLC. SIPN modeling was used so that any change can be done quickly using a high level abstraction. Then, the SIPN model will be converted to the equivalent LLD model using the proposed algorithm in Section 4.3. Figure 14 shows the equivalent LLD for the SIPN in Figure 2 which was converted using the proposed algorithm. The LLD model was simulated and tested on an actual robot arm machine to verify the design. This LLD shows 13 of rungs that indicates the solution for each Place. Looking at equation (5), (6), (7) and (8), the proposed algorithm used existing equation as in [1]. However, several techniques to identify unavailable patterns and how to simplify them so that existing formula in [1] can still be reused.

CONCLUSION AND FUTURE WORKS
SIPN model for PLC applications are more complicated than the example used in [1]. However, their PN to LLD conversion method is good enough to be used in an extended work for a more complex models. This research has shown that in a complete system design, SIPN modeling is useful to model a complete system and the proposed conversion process can be used by extending the work done previously. To make the extension work more easily being adopted, and to avoid using two different set of formulas, the formulas used in previous work were expanded so that the proposed algorithm can be used in both simple and complex SIPN models. The proposed algorithm also ensures there is only a single set of formulas to be used at any time to reduce software development complexity.