Search

CN-122018423-A - Programmable controller ladder diagram generation method based on large language model

CN122018423ACN 122018423 ACN122018423 ACN 122018423ACN-122018423-A

Abstract

The invention discloses a large language model-based programmable controller ladder diagram generation method, which belongs to the technical field of programmable controllers and comprises the steps of carrying out structural processing on logic control requirements, which are described by natural language and comprise I/O input, control logic relation and I/O output, through a first large language model, obtaining an I/O distribution table and an IL intermediate code through a pre-trained base large language model, wherein the I/O distribution table represents variable information and is converted into a first element in a specific format, the IL intermediate code is logic control information based on variable organization in the I/O distribution table, generating association relation of ladder diagram control represented by an AOV network through traversing the IL intermediate code, injecting relative position information of the ladder diagram control in the generation process, traversing the AOV network to generate a second element in the specific format, and combining and assembling the first element and the second element to form a file of a target ladder diagram code in the specific format.

Inventors

  • Xu Huangjie
  • Mao Zetao
  • CHEN BAIPING

Assignees

  • 杭州电子科技大学

Dates

Publication Date
20260512
Application Date
20260410

Claims (10)

  1. 1. The method for generating the ladder diagram of the programmable controller based on the large language model is characterized by comprising the following steps of: Pre-training a base large language model to generate a corresponding input-output allocation table and intermediate language codes through structural logic control requirements; acquiring logic control requirements of natural language description through a first large language model to perform structuring processing to generate structured logic control requirements; Generating a corresponding input/output allocation table and an intermediate language code according to the generated structured logic control requirement and a trained base large predictive model; Mapping the input-output allocation table into elements of an industrial control program exchange format; Generating a vertex representation active network based on a sequence based on the intermediate language code to obtain the association relation and the relative position information of the ladder diagram control, and then traversing the vertex representation active network to generate elements representing the ladder diagram control and the association relation and the relative position information of the ladder diagram control in an industrial control program exchange format so as to be applied to the intermediate language code of logic control; and combining the elements mapped by the input/output allocation table and the elements generated based on the intermediate language codes to generate an industrial control program exchange format file representing the target ladder diagram code.
  2. 2. The method for generating a ladder diagram of a programmable controller based on a large language model as set forth in claim 1, wherein said input/output allocation table contains a plurality of variables, the variable types include a pin type, a data type, the pin type includes an input pin, an output pin, a local variable, the data type includes an input class output switch trigger class, a time length class, and a delay timing class based on the trigger and the time length; the intermediate language code includes a set of network segments, each network segment including an intermediate language code segment of a plurality of intermediate language instructions, the intermediate language instructions corresponding to the variables.
  3. 3. The method for generating a ladder diagram of a programmable controller based on a large language model as set forth in claim 2, wherein for each variable in the input/output allocation table, a sub-element corresponding to an industrial control program exchange format is constructed, and for interface elements of the industrial control program exchange format, an input variable sub-element, an output variable sub-element, and a local variable sub-element are included, and an element representing a variable constructed for each line of data in the input/output allocation table is sequentially added to the corresponding sub-element according to the pin types according to the order of the input/output allocation table.
  4. 4. The method for generating a ladder diagram of a programmable controller based on a large language model according to claim 2, wherein the element generation process based on the intermediate language code is as follows: Dividing the intermediate language code into a plurality of network segments according to the network; defining elements describing the control of the ladder diagram, the connection line structure among the controls and the relative position relation, and adding a subelement representing the left guide rail under the elements; Defining a horizontal step count to represent parallel hierarchy of the controls in the ladder diagram, defining a vertical step count to represent series hierarchy of the controls in the ladder diagram, and clearing the horizontal step count when entering a new series hierarchy; constructing the vertex representation active network according to the network segment of the intermediate language code to graphically represent the ladder diagram, wherein nodes of the vertex representation active network correspond to the ladder diagram control, edges among the nodes correspond to the connecting structure of the ladder diagram control, a current active node chain and a last active node chain are defined, variables of the input/output allocation table are list data structures, and initial values are left guide rail nodes; Traversing vertexes corresponding to the network segments to represent the active network so as to add sub-elements; And adding the sub-elements representing the right guide rail after the parallel sub-elements to obtain the integrated element.
  5. 5. The method for generating the ladder diagram of the programmable controller based on the large language model of claim 4, wherein the node type comprises contacts, functional blocks and coils, and vertexes corresponding to the network segments are traversed one by one to represent an active network; if the contact type node is the contact type node, adding a contact sub-element under the element; if the function block type node is the function block type node, adding a function block sub-element under the element; If the coil type node is the coil type node, adding coil sub-elements under the elements; the node attributes of the contact sub-element, the function block sub-element and the coil sub-element all comprise variable names, polarities, reference nodes and relative position information.
  6. 6. The method for generating a large language model based programmable controller ladder diagram of claim 5 wherein, in the process of generating the active network, when the vertex represents a logic class instruction and/or a logic inverse class instruction and/or a non-class instruction for the intermediate language code segment: acquiring a new unique identifier by using an identifier generation method, generating a node, wherein the node represents a ladder diagram control of the contact type; clearing the transverse step count, increasing the longitudinal step count by 1, injecting the relative position into a new node, and connecting the new node with the nodes in the current active node chain in a bidirectional manner; And copying the nodes in the current active node chain to the last active node chain, and adding a new node after the current active node chain is emptied.
  7. 7. The method for generating a large language model based programmable controller ladder diagram of claim 5 wherein, in the process of generating the active network, when the vertex represents the intermediate language code segment is or class instruction and/or non-class instruction: acquiring a new unique identifier by using an identifier generation method, generating a node, wherein the node represents a ladder diagram control of the contact type; the transverse step count is increased by 1, the longitudinal step count is unchanged, the relative position is injected into a new node, and the new node is connected with the node in the last active node chain in a bidirectional manner; and keeping the last active node chain unchanged, and adding the current active node chain into a new node.
  8. 8. The method for generating a large language model based programmable controller ladder diagram of claim 5 wherein, in the process of generating the active network, when the vertex represents a set class instruction and/or a reset class instruction for the intermediate language code segment: acquiring a new unique identifier by using an identifier generation method, generating a node, wherein the node represents a ladder diagram control of the coil type; If the current coil is the first coil encountered by the network section, resetting the transverse step count, increasing the longitudinal step count by 1, injecting a new node at a relative position, and connecting the new node with the nodes in the current active node chain in a bidirectional manner; if the preamble coil exists, the transverse step count is increased by 1, the longitudinal step count is unchanged, a new node is injected at a relative position, and the new node is connected with the nodes in the last active node chain in a bidirectional manner.
  9. 9. The method for generating a large language model based programmable controller ladder diagram of claim 5 wherein, in the generating process of the active network, when the intermediate language code segment is a calling subroutine class instruction, the vertex represents: Analyzing the name and parameter list of the functional block, and identifying the input and output parameters of the functional block; if the input variable has no node, acquiring a new unique identifier by using an identifier generation method, generating a corresponding contact node, clearing a transverse step count, increasing a longitudinal step count by 1, injecting a new node at a relative position, and connecting the contact node with a node in a current active node chain in a bidirectional manner; copying the nodes in the current active node chain to the last active node chain, and adding the current active node chain into the contact node after the current active node chain is emptied; Otherwise, acquiring a new unique identifier by using an identifier generation method, generating a node, wherein the node type is the functional block, and recording input and output parameters of the node; clearing the transverse step count, increasing the longitudinal step count by 1, injecting new nodes at the relative positions, and connecting the functional block nodes with all nodes in the current active node chain in a bidirectional manner; and copying the nodes in the current active node chain to the last active node chain, and adding the current active node chain into the functional block node after the current active node chain is emptied.
  10. 10. The method for generating a ladder diagram of a programmable controller based on a large language model as set forth in claim 1, wherein said structured logic control requirements comprise a timing structure, a signal structure, a constraint structure; the logic control requirements of the natural language description comprise input, control logic relation and output; each network segment also comprises a network name and a network annotation, and before the traversing vertex represents the active network, a sub-element comprising the network annotation and a sub-element comprising the network name are added under the element; The identification generation method specifically comprises the steps of counting by using a global variable, wherein each time a node is newly built, the global variable count is increased by 1; the combined elements plus additional information are assembled into an industrial control program exchange format file, the additional information including, but not limited to, unit name, project name, creation time, program block name.

Description

Programmable controller ladder diagram generation method based on large language model Technical Field The invention belongs to the technical field of programmable controllers, and particularly relates to a large language model-based programmable controller ladder diagram generation method. Background The ladder diagram is a programming language for the software development of the programmable controller, and the grammar rules and the symbology of the ladder diagram reference the relay circuit diagram in the traditional electric control system, and the ladder diagram has the characteristics of intuitiveness, easy understanding and the like, and is widely applied in the field of industrial control for a long time. At present, the development of the ladder diagram program is mainly performed by engineers, the code development efficiency, the code quality and the like depend on the experience of the engineers, and a control software is usually required to be developed for a long time, so that the defects of high labor cost, low development efficiency and the like exist. In recent years, large language models have demonstrated significant advantages in terms of natural language understanding, complex logic reasoning, and the like. How to combine a large language model with the generation of a ladder diagram of a programmable controller to improve the generation efficiency of a ladder diagram program has become one of the technical problems to be solved in the art. Disclosure of Invention In order to solve the defects in the prior art and realize the automatic conversion from natural language to ladder diagram control logic so as to improve the ladder diagram code generation efficiency and reduce the ladder diagram programming technical difficulty, the invention adopts the following technical scheme: the programmable controller ladder diagram generating method based on the large language model comprises the following steps: Pre-training a base large language model to generate a corresponding input-output allocation table and intermediate language codes through structural logic control requirements; acquiring logic control requirements of natural language description through a first large language model to perform structuring processing to generate structured logic control requirements; Generating a corresponding input/output allocation table and an intermediate language code according to the generated structured logic control requirement and a trained base large predictive model; Mapping the input-output allocation table to an element < interface > in the PLCopen XML format of the industrial control program exchange; Generating a vertex representation active network based on a sequence based on the intermediate language code to obtain the association relation and the relative position information of the ladder diagram control, and then traversing the vertex representation active network to generate elements representing the ladder diagram control and the association relation and the relative position information of the ladder diagram control in an industrial control program exchange format so as to be applied to the intermediate language code of logic control; And combining the elements mapped by the input/output allocation table with elements generated based on the intermediate language codes and adding additional information to assemble the elements so as to generate the industrial control program exchange format XML file for representing the target ladder diagram codes. Further, the reference 1, the input/output allocation table contains a plurality of variables, each row of data represents a variable, the variable types include a name, a pin type, a data type, a comment and an initial value, the pin type includes an input pin, an output pin and a local variable, the data type includes an input class output switch trigger class BOOL, a TIME length class TIME and a TIME delay timing class TON based on trigger and TIME length, and the comment and the initial value are allowed to be null; the intermediate language code includes a set of network segments, each network segment including an intermediate language code segment of a plurality of intermediate language instructions, the intermediate language instructions corresponding to the variables. Further, for each variable in the input/output allocation table, constructing a sub-element corresponding to the exchange format of the industrial control program, for the interface element of the industrial control program exchange PLCopen XML format, including an input variable sub-element, an output variable sub-element and a local variable sub-element, sequentially adding an element representing the variable constructed by each line of data in the input/output allocation table to the corresponding sub-element according to the pin types according to the order of the input/output allocation table, wherein the elements all conform to the PLCopen XML format. Further, the