Ladder diagram generation method for programmable controller based on large language model
By combining a large language model with a programmable logic controller (PLC) ladder diagram, the automatic conversion from natural language to ladder diagram control logic is realized, which solves the problem of low efficiency in ladder diagram program development, improves code generation efficiency, and reduces technical difficulty.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU DIANZI UNIV
- Filing Date
- 2026-04-10
- Publication Date
- 2026-06-30
Smart Images

Figure CN122018423B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of programmable controller technology, specifically relating to a method for generating ladder diagrams for programmable controllers based on a large language model. Background Technology
[0002] Ladder diagrams are a programming language for developing programmable logic controller (PLC) software. Their syntax rules and symbol system are based on relay circuit diagrams in traditional electrical control systems. They are intuitive and easy to understand, and have been widely used in the field of industrial control for a long time.
[0003] Currently, ladder diagram programming is primarily done by engineers, and code development efficiency and quality depend heavily on their experience. Developing control software typically requires a lengthy development period, resulting in high labor costs and low efficiency. In recent years, large language models have demonstrated significant advantages in natural language understanding and complex logical reasoning. How to combine large language models with programmable logic controller (PLC) ladder diagram generation to improve ladder diagram program generation efficiency has become one of the technical problems that needs to be solved in this field. Summary of the Invention
[0004] To address the shortcomings of existing technologies and achieve automatic conversion from natural language to ladder diagram control logic, thereby improving ladder diagram code generation efficiency and reducing the technical difficulty of ladder diagram programming, this invention adopts the following technical solution:
[0005] The method for generating ladder diagrams for programmable controllers based on a large language model includes the following steps:
[0006] A pre-trained base language model is used to generate corresponding input / output allocation tables and intermediate language codes through structured logic control requirements;
[0007] The logical control requirements described in natural language are obtained through the first major language model, and then structured processing is performed to generate structured logical control requirements.
[0008] The generated structured logic control requirements are used to generate corresponding input / output allocation tables and intermediate language code through the trained base oracle model;
[0009] Map the input / output assignment table to elements in the PLCopen XML format for industrial control program exchange. <interface>;
[0010] A sequence-based vertex representation activity network is generated based on intermediate language code to obtain the association and relative position information of ladder diagram controls. Then, by traversing the vertex representation activity network, elements representing ladder diagram controls and their association and relative position information in the industrial control program exchange format are generated to apply intermediate language code to logic control.
[0011] The elements obtained by combining the input / output allocation table mapping with the elements generated based on the intermediate language code, along with additional information, are assembled to generate an industrial control program exchange format XML file representing the target ladder diagram code.
[0012] Furthermore, according to reference 1, the input / output allocation table contains multiple variables, each row of data represents a variable, the variable type includes name, pin type, data type, comment, initial value, pin type includes input pin, output pin, local variable, data type includes input class output switch trigger class BOOL, time length class TIME, and delay timing class TON based on trigger and time length, and comments and initial values are allowed to be empty;
[0013] The intermediate language code includes a set of network segments, each network segment containing multiple intermediate language code segments of intermediate language instructions, and the intermediate language instructions correspond to the variables.
[0014] Furthermore, for each variable in the input / output allocation table, a sub-element corresponding to the industrial control program exchange format is constructed. For the interface element of the industrial control program exchange PLCopen XML format, which includes input variable sub-elements, output variable sub-elements, and local variable sub-elements, an element representing a variable is constructed from each row of data in the input / output allocation table and added sequentially to the corresponding sub-element according to the pin type in the order of the input / output allocation table. All elements conform to the PLCopen XML format.
[0015] Furthermore, the process of generating elements based on intermediate language code is as follows:
[0016] The intermediate language code is divided into multiple network segments according to the network;
[0017] Define an element that describes the ladder diagram control, the connection structure between the controls, and their relative positions. Add a child element representing the left guide rail under this element.
[0018] Define a horizontal step count x_level to represent the parallel level of controls in the ladder diagram, with an initial value of 0. Define a vertical step count y_level to represent the serial level of controls in the ladder diagram, with an initial value of 0. When entering a new serial level, clear the horizontal step count x_level to limit the parallel level to only the same serial level.
[0019] Based on the network segments of the intermediate language code, the vertex representation activity network is constructed to graphically represent the ladder diagram. The nodes of the vertex representation activity network correspond to the ladder diagram control and have a unique identifier ID. The edges between nodes correspond to the connection structure of the ladder diagram control. An AOV dependency network is constructed for any unprocessed network segment. The current active node chain last_nodes and the previous active node chain last_last_nodes are defined. The variables of the input / output allocation table are list data structures, and the initial value is the left guide rail node.
[0020] Traverse the vertices corresponding to the network segments to represent the active network, and add child elements;
[0021] Add a child element representing the right guide rail after the adjacent child elements to obtain the merged complete element.
[0022] Furthermore, the node types include contacts, functional blocks, and coils, and the active network is represented by traversing the vertices corresponding to the network segments one by one;
[0023] If it is a touch-type node, add a touch-child element under the element;
[0024] If it is a function block type node, add function block child elements under the element;
[0025] If it is a coil type node, add a coil sub-element under the element;
[0026] The node attributes of touch point sub-elements, function block sub-elements, and coil sub-elements all include variable name, polarity, referenced node, and relative position information.
[0027] Furthermore, during the vertex representation activity network generation process, when the intermediate language code segment is a logical take-LD type instruction and / or a logical take-NOT LDN type instruction and / or an AND type instruction and / or an AND non-ANDN type instruction:
[0028] Use the identifier generation method to obtain a new unique identifier ID, generate a node, and the node represents a ladder diagram control of the touch type;
[0029] The horizontal ladder count x_level is cleared to zero, the vertical ladder count y_level is incremented by 1, the relative position is injected into the new node, and the new node is bidirectionally connected to the nodes in the current active node chain last_nodes;
[0030] Copy the nodes from the current active node chain last_nodes to the previous active node chain last_last_nodes, and then clear the current active node chain last_nodes before adding the new node.
[0031] Furthermore, the vertex represents the process of generating the active network when the intermediate language code segment is an OR-type instruction and / or a non-ORN-type instruction:
[0032] Use the identifier generation method to obtain a new unique identifier ID, generate a node, and the node represents a ladder diagram control of the touch type;
[0033] The horizontal step count x_level is increased by 1, the vertical step count y_level remains unchanged, the relative position is injected into the new node, and the new node is bidirectionally connected to the node in the last active node chain last_last_nodes.
[0034] The last active node chain (last_last_nodes) remains unchanged, while the new node is added to the current active node chain (last_nodes).
[0035] Furthermore, during the vertex representation activity network generation process, when the intermediate language code segment is a set ST / S type instruction and / or a reset R type instruction:
[0036] Use the identifier generation method to obtain a new unique identifier ID, generate a node, and the node represents a ladder diagram control of the coil type;
[0037] If the current node is the first coil encountered by the network segment, the horizontal step count x_level is cleared to zero, the vertical step count y_level is increased by 1, a new node is injected at the relative position, and the new node is bidirectionally connected to the nodes in the current active node chain last_nodes.
[0038] If a preceding coil already exists, the horizontal step count x_level is increased by 1, the vertical step count y_level remains unchanged, a new node is injected at the relative position, and the new node is bidirectionally connected to the node in the last active node chain last_last_nodes. The display format of multiple coils in the same network segment is supported by the specific display environment.
[0039] Furthermore, during the generation of the vertex representation activity network, when the intermediate language code segment is a CAL-type instruction that calls a subroutine:
[0040] Parse the name and parameter list of the function block to identify its input and output parameters;
[0041] If the input variable does not yet have a node, the identifier generation method is used to obtain a new unique identifier ID, generate the corresponding touch node, clear the horizontal step count x_level to zero, increase the vertical step count y_level by 1, inject the new node at the relative position, and make a bidirectional connection between the touch node and the node in the current active node chain last_nodes.
[0042] Copy the nodes in the current active node chain last_nodes to the previous active node chain last_last_nodes, and then add the touch node after clearing the current active node chain last_nodes.
[0043] Otherwise, use the identifier generation method to obtain a new unique identifier ID, generate a node of type block, and record its input and output parameters;
[0044] The horizontal step count x_level is cleared to zero, the vertical step count y_level is incremented by 1, a new node is injected at the relative position, and the function block node is bidirectionally connected to all nodes in the current active node chain last_nodes.
[0045] Copy the nodes in the current active node chain last_nodes to the previous active node chain last_last_nodes, and then add the functional block node after clearing the current active node chain last_nodes.
[0046] Furthermore, the structured logic control requirements include sequential structures, signal structures, and constraint structures;
[0047] The logical control requirements described in the natural language include input, control logic relationships, and output;
[0048] Each network segment also includes a network name and a network annotation. Traversing vertices indicates the active network front, and a sub-element containing the network annotation and a sub-element containing the network name are added under the element.
[0049] The identifier generation method specifically includes using a global variable local_id for counting, and incrementing the count of the global variable local_id by 1 each time a new node is created;
[0050] The combined elements, along with additional information, are assembled into an industrial control program exchange format XML file. This additional information includes, but is not limited to, the unit name, project name, creation time, and program block POU name.
[0051] The advantages and beneficial effects of this invention are as follows:
[0052] The ladder diagram generation method for programmable controllers based on a large language model of the present invention combines the large language model with the generation of ladder diagrams for programmable controllers, realizing the automatic conversion from natural language to ladder diagram control logic, which can significantly improve the efficiency of ladder diagram code generation and reduce the technical difficulty of ladder diagram programming. Attached Figure Description
[0053] Figure 1 This is a flowchart of a method according to an embodiment of the present invention.
[0054] Figure 2 This is a schematic representation of I / O allocation in an embodiment of the present invention.
[0055] Figure 3 This is a schematic diagram of the intermediate IL code in an embodiment of the present invention.
[0056] Figure 4 These are elements in the embodiments of the present invention. <ld>The generated flowchart.
[0057] Figure 5 This is a schematic diagram of the AOV network in an embodiment of the present invention.
[0058] Figure 6 This is the target trapezoidal diagram in the embodiment of the present invention. Detailed Implementation
[0059] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0060] like Figure 1 As shown, the method for generating ladder diagrams for programmable controllers based on a large language model includes the following steps:
[0061] Step S1: Using a certain number of JSON structured logic control requirements and their corresponding I / O allocation tables and IL intermediate code as samples, pre-train the base large language model to generate the corresponding allocation tables and intermediate code through the structured logic control requirements.
[0062] The specific requirements for JSON structured logic control include timing, signals, and constraints. In this embodiment of the invention, regarding the JSON structured logic control requirements, wherein:
[0063] The timing structure code defines a 5-second delay;
[0064] The code for the signal structure defines a start button, where the interface type is input.
[0065] The code for the constraint structure defines a constraint for pressing the start button.
[0066] In this embodiment of the invention, regarding the I / O allocation table, each row of data includes a name, comment, pin type, data type, and initial value; only the comment and initial value can be empty; the pin type includes input pins, output pins, and local variables; the data type includes BOOL, TIME, and TON.
[0067] In this embodiment of the invention, regarding the IL intermediate code, the IL intermediate code is divided into multiple network segments by the network. Each network segment includes a network name, network comments, and an IL code segment. Each line of the IL code segment represents an IL instruction, including the instruction code and variables, separated by spaces.
[0068] Step S2: Select a general-purpose large language model as the first large language model, receive the logical control requirements described in natural language, perform structured processing, and generate JSON structured logical control requirements.
[0069] In this embodiment of the invention, the DeepSeek-V3.2 model is selected as the primary language model.
[0070] In this embodiment of the invention, the logic control requirements described in natural language consist of I / O inputs, control logic relationships, and I / O outputs, and are described in a complete and coherent natural language; for example, "when input I1 is turned on and input I2 is turned off, timer T1 is activated; when the timer of T1 expires, the output coil Q1 is energized."
[0071] Step S3: Input the JSON structured logic control requirements generated in Step S2 into the pre-trained base language model in Step S1, and output the corresponding I / O allocation table and IL intermediate code.
[0072] like Figure 2 As shown, this embodiment defines four variables: I1, I2, T1, and Q1. I1 is a BOOL type input pin with an initial value of 0, I2 is a BOOL type input pin with an initial value of 1, T1 is a TON type local variable with no initial value, and Q1 is a BOOL type output pin with an initial value of 0.
[0073] like Figure 3 As shown in the diagram, this embodiment provides an intermediate IL code illustration. This embodiment has one network segment, and the code segment of this network segment uses four common instructions: LD, ORN, CAL, and R. Furthermore, the variables following each instruction are already defined... Figure 2 The I / O allocation table shown defines that when using the CAL instruction, the input and output parameters need to be listed on separate lines after the variable and enclosed in parentheses. TIME#3S0MS represents a time value of 3 seconds.
[0074] Step S4: Convert the I / O allocation table mapping obtained in step S3 into elements represented in PLCopen XML format. <interface>, and its corresponding set of variables.
[0075] In this embodiment of the invention, the I / O allocation table mapping conversion further includes:
[0076] Define a <interface>Elements, containing <inputvars>Sub-elements <outputvars>Sub-elements <localvars>Child elements, where elements <interface>Indicates interface, child element <inputvars>Indicates input variables and child elements. <outputvars>Indicates output variable, child element <localvars>Represents local variables;
[0077] Each row of data in the I / O allocation table constructs an element representing a variable. <variable>;
[0078] Scan the I / O allocation table from top to bottom, and assign the elements according to pin type. <variable>Add to the corresponding <inputvars> 、 <outputvars>or <localvars>Under element;
[0079] All elements conform to the PLCopen XML format.
[0080] In this embodiment of the invention, the element <variable>A variable control representing a ladder diagram.
[0081] Step S5: Traverse the intermediate IL code obtained in Step S3 to generate an AOV (Activity On Vertex) net. This AOV net represents the association and relative position information of the ladder diagram controls. Then, traverse the AOV net to generate elements represented in PLCopen XML format. <ld>, and its corresponding logic control code.
[0082] like Figure 4 As shown, the elements provided in the embodiments of the present invention <ld>The generation method specifically includes the following steps:
[0083] Step S501: Initialization.
[0084] The intermediate IL code is divided into multiple network segments according to the network;
[0085] Define an element <ld>Describes the ladder diagram control, the connection structure between the controls, and their relative positional relationships;
[0086] In the element <ld>Add a child element below <leftpowerrail>, used to indicate the left guide rail;
[0087] Define a horizontal step count x_level to represent the parallel level of controls in the ladder diagram, with an initial value of 0. Define a vertical step count y_level to represent the series level of controls in the ladder diagram, with an initial value of 0. When entering a new series level, the horizontal step count x_level is cleared to ensure that the parallel level only applies to the same series level.
[0088] Step S502: Construct the AOV dependency network based on the network segments.
[0089] Build an AOV dependency network for any unprocessed network segment.
[0090] Define the current active node chain last_nodes and the last active node chain last_last_nodes. Both variables are list data structures, and their initial values are the left guide nodes.
[0091] Scan the IL code segment of the network segment and generate the AOV network according to the following algorithm:
[0092] (1) LD / LDN instruction class:
[0093] ① Use the identifier generation method to obtain a new unique identifier ID.
[0094] ② Generate a node, which represents a ladder diagram control of the touch type.
[0095] ③ Clear x_level to zero, increment y_level by 1, and inject the relative position into the new node.
[0096] ④ Connect the new node bidirectionally with the nodes in last_nodes.
[0097] ⑤ Copy the nodes in last_nodes to last_last_nodes.
[0098] ⑥ Clear last_nodes and add the new node.
[0099] (2) AND / ANDN type instructions:
[0100] ① Use the identifier generation method to obtain a new unique identifier ID.
[0101] ② Generate a node, which represents a ladder diagram control of the touch type.
[0102] ③ Clear x_level to zero, increment y_level by 1, and inject the relative position into the new node.
[0103] ④ Connect the new node bidirectionally with the nodes in last_nodes.
[0104] ⑤ Copy the nodes in last_nodes to last_last_nodes.
[0105] ⑥ Clear last_nodes and add the new node.
[0106] (3) OR / ORN commands:
[0107] ① Use the identifier generation method to obtain a new unique identifier ID.
[0108] ② Generate a node, which represents a ladder diagram control of the touch type.
[0109] ③Increase x_level by 1, keep y_level unchanged, and inject the relative position into the new node.
[0110] ④ Connect the new node bidirectionally to the nodes in last_last_nodes.
[0111] ⑤ The last_last_nodes remain unchanged, while the last_nodes are added to the new node.
[0112] (4) ST / S / R type instructions:
[0113] ① Use the identifier generation method to obtain a new unique identifier ID.
[0114] ② Generate a node, which represents a ladder diagram control of type coil.
[0115] ③ If the current node is the first coil encountered in the network segment, x_level is cleared to zero, y_level is increased by 1, the relative position is injected into the new node, and the new node is bidirectionally connected to the nodes in last_nodes.
[0116] ④ If a preceding coil already exists, increase x_level by 1, keep y_level unchanged, inject the relative position into the new node, and make a bidirectional connection between the new node and the nodes in last_last_nodes. The display format of multiple coils in the same network segment is supported by the specific display environment.
[0117] (5) CAL commands:
[0118] ① Parse the function block name and parameter list to identify its input and output parameters.
[0119] ② If the input variable does not yet have a node, use the identifier generation method to obtain a new unique ID, generate the corresponding touch node, clear x_level to zero, increase y_level by 1, inject the relative position into the new node, make a bidirectional connection between the touch node and the nodes in last_nodes, copy the nodes in last_nodes to last_last_nodes, clear last_nodes, and add the new touch.
[0120] ③ Use the identifier generation method to obtain a new unique ID.
[0121] ④ Generate a node of type block and record its input and output parameters.
[0122] ⑤ Clear x_level to zero, increment y_level by 1, and inject the relative position into the new node.
[0123] ⑥ Connect the function block node bidirectionally to all nodes in last_nodes.
[0124] ⑦ Copy the nodes in last_nodes to last_last_nodes.
[0125] ⑧ Clear last_nodes and add the function block node.
[0126] Specifically, the identifier generation method includes: using a global variable local_id, incrementing the local_id count by 1 whenever a new node is created.
[0127] The AOV dependency network is a graphical representation of a ladder diagram; the nodes of the AOV dependency network correspond to the ladder diagram controls, and a unique identifier ID is obtained using an identifier generation method; the node types include contacts, function blocks, and coils; the node attributes include variable name, polarity, and relative position; the edges of the AOV dependency network correspond to the connection structure of the ladder diagram controls.
[0128] like Figure 5 As shown, the AOV dependency network in this embodiment has six nodes: leftPowerRail, I1, I2, T1, Q1, and rightPowerRail. Except for the left guide rail leftPowerRail, all nodes have left dependencies; the square brackets contain unique identifiers (IDs); the node types are shown below; all other node information is hidden.
[0129] Step S503: Traverse the AOV dependency network.
[0130] Before traversing the AOV dependency network, the elements described in step S501... <ld>Add a child element below <comment>and a child element <vendorelement>The element <comment>Including network annotations, the elements <vendorelement>Including network name;
[0131] Traverse the AOV dependency network corresponding to each network segment one by one;
[0132] (1) If it is a contact type node, in the element <ld>Add a child element below <contact>;
[0133] (2) If it is a function block type node, in the element <ld>Add a child element below <block>;
[0134] (3) If it is a coil type node, in the element <ld>Add a child element below <coil>;
[0135] Wherein, the element <contact>and <coil>Each element includes a variable name, polarity, reference node ID, and relative position; <block>This includes variable name, function block type, reference node ID, and relative position;
[0136] If there are still unprocessed network segments, proceed to step S502; otherwise, proceed to step S504.
[0137] Step S504: Output elements <ld>.
[0138] In elements <ld>Add a child element below <rightpowerrail>Indicates the right guide rail;
[0139] The element <ld>All the added child elements are in a parallel relationship, and together they form a complete element. <ld>;
[0140] All elements conform to the PLCopen XML format.
[0141] In this embodiment of the invention, the elements in the above steps correspond to ladder diagram controls and conform to the PLCopen XML format, such as... Figure 5 As shown:
[0142] Node 1 represents the left guide rail control, which contains elements <leftpowerrail>;
[0143] Node 2 represents the contact point, which contains elements <contact>;
[0144] Node 3 represents the timer function block, which contains elements <block>;
[0145] Node 4 represents the coil, which contains elements <coil>;
[0146] Regarding the connection structure between elements, firstly, each element defines a localId, which corresponds to and is unique to the node's unique identifier ID in the AOV dependency network; secondly, each element defines the connection point from the left, indicating which control on the left it is connected to.
[0147] like Figure 5 As shown, the localId of node 4 is 7; where, <connectionpointin>The structure represents the case where the connection comes from the left. <connection>The structure represents a connection to the element with localId 6, i.e., node 3; <connectionpointout>The structure represents the connection from the right; in practical applications, to avoid repetition, all elements only need to describe the connection from the left, without describing which element is connected to the right.
[0148] Step S6: Take the elements from step S4 above. <interface>and the elements of step S5 <ld>Combined with additional information such as creation time, they are merged and assembled into an XML file, which records the target ladder diagram code represented in PLCopen XML format.
[0149] In this embodiment of the invention, the additional information includes the company name, project name, creation time, and POU name.
[0150] In this embodiment of the invention, the target ladder diagram code is an XML file conforming to the PLCopen XML format. If the programmable controller programming platform supports ladder diagram programs represented in the PLCopen XML format, it can import the XML file to display the complete ladder diagram code; then, the ladder diagram code can be compiled (e.g., ...). Figure 6 As shown in the figure, an executable program can be obtained for running on the target PLC.
[0151] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.< / ld> < / interface> < / connectionpointout> < / connection> < / connectionpointin> < / coil> < / block> < / contact> < / leftpowerrail> < / ld> < / ld> < / rightpowerrail> < / ld> < / ld> < / block> < / coil> < / contact> < / coil> < / ld> < / block> < / ld> < / contact> < / ld> < / vendorelement> < / comment> < / vendorelement> < / comment> < / ld> < / leftpowerrail> < / ld> < / ld> < / ld> < / ld> < / variable> < / localvars> < / outputvars> < / inputvars> < / variable> < / variable> < / localvars> < / outputvars> < / inputvars> < / interface> < / localvars> < / outputvars> < / inputvars> < / interface> < / interface> < / ld> < / interface>
Claims
1. A method for generating ladder diagrams for programmable controllers based on a large language model, characterized in that: A pre-trained base language model is used to generate corresponding input / output allocation tables and intermediate language codes through structured logic control requirements; The logical control requirements described in natural language are obtained through the first major language model, and then structured processing is performed to generate structured logical control requirements. The generated structured logic control requirements are used to generate corresponding input / output allocation tables and intermediate language code through the trained base oracle model; Map the input / output allocation table to elements of the industrial control program exchange format; A sequence-based vertex representation activity network is generated based on intermediate language code to obtain the association and relative position information of ladder diagram controls. Then, by traversing the vertex representation activity network, elements representing ladder diagram controls and their association and relative position information in the industrial control program exchange format are generated to apply intermediate language code to logic control. By combining the elements obtained from the input / output allocation table mapping with the elements generated based on the intermediate language code, an industrial control program exchange format file representing the target ladder diagram code is generated.
2. The programmable controller ladder diagram generation method based on a large language model according to claim 1, characterized in that: The input / output allocation table contains multiple variables, including pin types and data types. Pin types include input pins, output pins, and local variables. Data types include input-type output switch trigger types, time-length types, and delay-time types based on triggers and time-length. The intermediate language code includes a set of network segments, each network segment containing multiple intermediate language code segments of intermediate language instructions, and the intermediate language instructions correspond to the variables.
3. The programmable controller ladder diagram generation method based on a large language model according to claim 2, characterized in that: For each variable in the input / output allocation table, construct a sub-element corresponding to the industrial control program exchange format. For the interface element of the industrial control program exchange format, which includes input variable sub-elements, output variable sub-elements, and local variable sub-elements, construct an element representing a variable from each row of data in the input / output allocation table and add it to the corresponding sub-element in sequence according to the pin type, following the order of the input / output allocation table.
4. The programmable controller ladder diagram generation method based on a large language model according to claim 2, characterized in that: The process of generating elements based on intermediate language code is as follows: The intermediate language code is divided into multiple network segments according to the network; Define an element that describes the ladder diagram control, the connection structure between the controls, and their relative positions. Add a child element representing the left guide rail under this element. Define a horizontal step count to represent the parallel hierarchy of controls in the ladder diagram, and define a vertical step count to represent the serial hierarchy of controls in the ladder diagram. When entering a new serial hierarchy, the horizontal step count is reset to zero. Based on the network segment of the intermediate language code, the vertex representation activity network is constructed to graphically represent the ladder diagram. The nodes of the vertex representation activity network correspond to the ladder diagram control, and the edges between nodes correspond to the connection structure of the ladder diagram control. The current active node chain and the previous active node chain are defined. The variables of the input / output allocation table are list data structures, and the initial value is the left guide rail node. Traverse the vertices corresponding to the network segments to represent the active network, and add child elements; Add a child element representing the right guide rail after the adjacent child elements to obtain the merged complete element.
5. The programmable controller ladder diagram generation method based on a large language model according to claim 4, characterized in that: Node types include contacts, function blocks, and coils. Traversing the network segments one by one, the corresponding vertices represent the active network. If it is a touch-type node, add a touch-child element under the element; If it is a function block type node, add function block child elements under the element; If it is a coil type node, add a coil sub-element under the element; The node attributes of touch point sub-elements, function block sub-elements, and coil sub-elements all include variable name, polarity, referenced node, and relative position information.
6. The programmable controller ladder diagram generation method based on a large language model according to claim 5, characterized in that: During the generation of the vertex representation activity network, when the intermediate language code segment is a logical classification instruction and / or a logical negation instruction and / or an AND instruction and / or a NAND instruction: Use the identifier generation method to obtain a new unique identifier, generate a node, and the node represents a ladder diagram control of the touch type; The horizontal step count is reset to zero, the vertical step count is incremented by 1, the relative position is injected into the new node, and the new node is bidirectionally connected to the nodes in the currently active node chain. Copy the nodes from the current active node chain to the previous active node chain, and then clear the current active node chain before adding the new node.
7. The programmable controller ladder diagram generation method based on a large language model according to claim 5, characterized in that: Vertex representation refers to the process of generating an active network, where the intermediate language code segment is an OR-type instruction and / or an OR-non-type instruction: Use the identifier generation method to obtain a new unique identifier, generate a node, and the node represents a ladder diagram control of the touch type; The horizontal step count is increased by 1, the vertical step count remains unchanged, the relative position is injected into the new node, and the new node is bidirectionally connected to the node in the last active node chain. The previous active node chain remains unchanged, and new nodes are added to the current active node chain.
8. The method for generating ladder diagrams for programmable controllers based on a large language model according to claim 5, characterized in that: Vertex representation refers to the process of generating an active network, where the intermediate language code segment is a set instruction and / or a reset instruction: Use the identifier generation method to obtain a new unique identifier, generate a node, and the node represents a ladder diagram control of the coil type; If the current node is the first coil encountered by the network segment, the horizontal step count is reset to zero, the vertical step count is incremented by 1, a new node is injected at the relative position, and the new node is bidirectionally connected to the node in the currently active node chain. If a preceding coil already exists, the horizontal step count is increased by 1, the vertical step count remains unchanged, a new node is injected at the relative position, and the new node is bidirectionally connected to the node in the previously active node chain.
9. The method for generating ladder diagrams for programmable controllers based on a large language model according to claim 5, characterized in that: Vertex representation refers to the process of generating an active network, specifically when the intermediate language code segment is a subroutine call instruction: Parse the name and parameter list of the function block to identify its input and output parameters; If the input variable does not yet have a node, a new unique identifier is obtained using the identifier generation method, the corresponding touch node is generated, the horizontal step count is cleared to zero, the vertical step count is increased by 1, the new node is injected at the relative position, and the touch node is bidirectionally connected to the node in the currently active node chain. Copy the nodes in the current active node chain to the previous active node chain, and add the touch node after clearing the current active node chain; Otherwise, use the identifier generation method to obtain a new unique identifier, generate a node of type the aforementioned functional block, and record its input and output parameters; The horizontal step count is reset to zero, the vertical step count is incremented by 1, a new node is injected at the relative position, and the function block node is bidirectionally connected to all nodes in the currently active node chain. Copy the nodes from the current active node chain to the previous active node chain, and then add the functional block node after clearing the current active node chain.
10. The method for generating ladder diagrams for programmable controllers based on a large language model according to any one of claims 6 to 9, characterized in that: The structured logic control requirements include sequential structures, signal structures, and constraint structures. The logical control requirements described in the natural language include input, control logic relationships, and output; Each network segment also includes a network name and a network annotation. Traversing vertices indicates the active network front, and a sub-element containing the network annotation and a sub-element containing the network name are added under the element. The identifier generation method specifically includes using a global variable for counting, and incrementing the global variable count by 1 each time a new node is created; The combined elements, along with additional information, are assembled into an industrial control program exchange format file. This additional information includes, but is not limited to, the organization name, project name, creation time, and program block name.