Automatic control code generation and verification method and device, equipment and storage medium

Through a large language model combining vector database and knowledge graph database to generate and verify automated control codes, the problems of poor flexibility and inefficiency in the existing technology are solved, and efficient and reliable automated control code generation is achieved, suitable for complex scenarios and reduce debugging difficulty.

CN120406914AActive Publication Date: 2025-08-01HONG KONG UNIV OF SCI & TECH (GUANGZHOU) +1

Patent Information

Application Number
CN202510444191.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-09
Publication Date
2025-08-01
Estimated Expiration
2045-04-09

AI Technical Summary

Technical Problem

The existing automated control code generation technology has poor flexibility, insufficient accuracy and low efficiency, making it difficult to adapt and expand in complex scenarios, and it requires repeated debugging and testing after generation, which is time-consuming and error-prone.

Method used

A large language model is used to combine vector databases and knowledge graph databases, and initial control codes are generated through natural language commands, and multi-level virtual operation verification is performed in the software motion control system, and target control codes are generated based on multiple confirmations from users.

Benefits of technology

Improves code generation efficiency, reduces error rates, enhances code maintainability and reliability, ensures the applicability and security of the final code, and avoids the potential risks that may be caused by full automation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406914A_ABST
    Figure CN120406914A_ABST
Patent Text Reader

Abstract

The invention discloses an automatic control code generation and verification method and device, equipment and a storage medium, and relates to the technical field of automatic control, the method is applied to a large language model, and a natural language command is received; performing matching retrieval on the vector database according to the natural language command to obtain an example code snippet; obtaining API structured information corresponding to the example code snippets from a knowledge graph database; generating an initial control code based on the example code snippet and the API structured information; and performing multi-stage virtual operation verification on the initial control code in the software motion control system, and generating a target control code according to a multi-stage verification result confirmed by a user for multiple times and the initial control code. According to the method, the initial control code is automatically generated through double-database retrieval based on the large language model, then multi-stage code verification is performed through the software motion control system, the target control code is generated in combination with verification results confirmed by a user for multiple times, and the code generation speed and reliability are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of automated control technology, and in particular to an automated control code generation and verification method, apparatus, device, and storage medium. Background Art

[0002] Current automation control system programming methods primarily include manual programming and template-based programming, both of which present significant challenges in terms of complexity and safety. Manual programming is limited by the developer's experience and capabilities, as well as the extensive API function setup and learning required. This leads to generation errors and long development and debugging cycles. Template-based programming, on the other hand, often struggles with complex scenarios or personalized needs, limiting the system's adaptability and scalability. Furthermore, after initial code generation is complete, repeated debugging and testing of the hardware and code are required to determine the appropriate parameters for the code before code generation can be completed. This makes comprehensive code generation time-consuming.

[0003] Therefore, current automated control code generation technology suffers from a series of problems such as poor flexibility, insufficient accuracy, and low efficiency. How to overcome these technical difficulties and improve the efficiency and reliability of automated control code generation has become a key issue that needs to be addressed in this field. Summary of the Invention

[0004] The main purpose of this application is to provide a method, device, equipment and storage medium for automatic control code generation and verification, aiming to solve the technical problem of how to improve the efficiency and reliability of automatic control code generation.

[0005] To achieve the above objectives, this application proposes an automated control code generation and verification method, which is applied to a large language model and includes:

[0006] Receive a natural language command; the natural language command is used to instruct the large language model to output a code text that meets the control requirements corresponding to the natural language command;

[0007] Performing a matching search on a vector database according to the natural language command to obtain a sample code snippet;

[0008] Obtaining API structured information corresponding to the sample code snippet from the knowledge graph database;

[0009] generating an initial control code based on the sample code snippet and the API structured information;

[0010] The initial control code is subjected to multi-level virtual operation verification in the software motion control system, and a target control code is generated based on the multi-level verification results confirmed multiple times by the user and the initial control code.

[0011] In one embodiment, the step of performing matching retrieval on the vector database according to the code generation statement to obtain example code snippets includes:

[0012] Semantically parse the code generation statement to obtain the main control task;

[0013] Decompose the main control task to obtain a number of sub-control tasks;

[0014] Perform matching retrieval on the vector database according to the sub-control tasks to obtain example code snippets.

[0015] In one embodiment, the software motion control system includes a virtual motion engine; the step of performing multi-level virtual operation verification on the initial control code in the software motion control system and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code includes:

[0016] Transmit the initial control code to the virtual motion engine for device simulation operation, obtain the code execution result, and perform semantic matching between the code execution result and the natural language command to generate a first verification result;

[0017] After the user confirms the first verification result, drive the three-dimensional simulation model through the virtual motion engine to display the device motion process corresponding to the initial control code, and generate a second verification result, so that the user can intuitively observe whether the device actions corresponding to the initial control code in the three-dimensional simulation model meet the control requirements through the second verification result;

[0018] After the user confirms the second verification result, periodically collect the motion process data during the operation of the virtual motion engine, and generate a third verification result according to the motion process data; the motion process data includes but is not limited to the position, speed, current feedback, and IO status of the control axis;

[0019] After the user confirms the third verification result, use the control code finally confirmed by the user as the target control code.

[0020] In one embodiment, the step of generating the first verification result includes:

[0021] When the semantic matching degree between the operation result and the natural language command is lower than the preset matching threshold, trigger an error correction process;

[0022] Query the knowledge graph database based on the operation error information to obtain error API node information; the error API node information includes but is not limited to API explanation information, example error codes, example error code meanings, and example error code optimization suggestions;

[0023] Generate a first corrected control code based on the error API node information and the initial control code;

[0024] Re - execute the first corrected control code and update the first verification result.

[0025] In one embodiment, after generating the second verification result, it further includes:

[0026] In response to the user's interactive adjustment instruction for the 3D simulation model, update the natural language command;

[0027] Regenerate a second corrected control code according to the updated natural language command, and iteratively execute the multi - level virtual operation verification according to the second corrected code.

[0028] In one embodiment, the step of generating a third verification result according to the motion process data includes:

[0029] Divide the motion process data into multiple verification intervals according to a preset time stage;

[0030] Within each verification interval, the user compares the real - time parameters with the expected values of the corresponding stage to generate a third verification result.

[0031] In one embodiment, the software motion control system further includes a real - time motion engine; after performing multi - level virtual operation verification on the initial control code in the software motion control system and generating a target control code according to the multi - level verification results confirmed by the user multiple times and the initial control code, it further includes:

[0032] In response to the user's execution decision, synchronize the runtime environment configuration of the virtual motion engine to the real - time motion engine; after the configuration synchronization, the axis numbers of the virtual motion engine and the real - time motion engine correspond one by one, and the virtual motion engine and the real - time motion engine use the same motion control function library;

[0033] Send the control code to the real - time motion engine to perform periodic control on the automation device based on the target control code through the real - time motion engine.

[0034] In addition, to achieve the above object, the present application also proposes an automation control code generation and verification device, and this device includes:

[0035] An interaction module, configured to receive a natural language command; the natural language command is used to instruct the large - language model to output a code text that meets the control requirements corresponding to the natural language command;

[0036] A code positioning module, configured to perform matching retrieval on the vector database according to the natural language command to obtain an example code segment;

[0037] A relationship acquisition module, configured to acquire API structured information corresponding to the example code snippet from a knowledge graph database;

[0038] A code generation module, configured to generate initial control code based on the example code snippet and the API structured information;

[0039] A code execution module, configured to perform multi-level virtual operation verification on the initial control code in a software motion control system, and generate target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

[0040] In addition, to achieve the above object, the present application further provides an automated control code generation and verification device, which includes: a memory, a processor, and an automated control code generation and verification program stored on the memory and executable on the processor. The automated control code generation and verification program is configured to implement the steps of the automated control code generation and verification method as described above;

[0041] The device further includes a software motion control system, and the software motion control system includes a virtual motion engine and a real-time motion engine.

[0042] In addition, to achieve the above object, the present application further provides a storage medium, which is a computer-readable storage medium. A program for implementing the automated control code generation and verification method is stored on the computer-readable storage medium, and the program for implementing the automated control code generation and verification method is executed by a processor to implement the steps of the automated control code generation and verification method as described above.

[0043] The present application provides an automated control code generation and verification method, device, equipment, and storage medium. The method is applied to a large language model, and the method includes: receiving a natural language command; the natural language command is used to instruct the large language model to output a code text that meets the control requirements corresponding to the natural language command; performing a matching search on a vector database according to the natural language command to obtain an example code snippet; acquiring API structured information corresponding to the example code snippet from a knowledge graph database; generating initial control code based on the example code snippet and the API structured information; performing multi-level virtual operation verification on the initial control code in a software motion control system, and generating target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

[0044] This application can perform dual-database retrieval based on large language models, obtain example code snippets and API structured information related to natural language command control requirements, automatically generate accurate and logical initial control code, and perform multi-level code verification on the initial control code through a software motion control system. Combining the multi-level verification results confirmed by the user multiple times, it can quickly generate highly reliable automated control code that meets the user's needs. Compared with the prior art, this application can automatically generate and verify automated control code through large language models, which not only improves the code generation efficiency, reduces the error rate, but also enhances the maintainability of the code. At the same time, this application effectively avoids potential risks that may be caused by full automation through the introduction of multi-level virtual verification that combines user judgment and decision-making steps, while enhancing the user's trust in the generated code and its execution effect, and ensuring the reliability and applicability of the final code. It solves the deficiencies in the prior art that are difficult to guarantee in terms of generation speed and security, and provides a more efficient and reliable automated control coding generation method. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The drawings herein are incorporated into and constitute a part of this specification, showing embodiments consistent with this application, and are used together with the specification to explain the principles of this application.

[0046] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0047] Figure 1 It is a schematic flowchart of the first embodiment of the automated control code generation and verification method of this application;

[0048] Figure 2 It is a schematic flowchart of the second embodiment of the automated control code generation and verification method of this application;

[0049] Figure 3 It is a structural control block diagram of the second embodiment of the automated control code generation and verification method of this application;

[0050] Figure 4 It is a schematic flowchart of the brief process of the automated control code generation and verification method of this application;

[0051] Figure 5 It is a schematic diagram of the module structure of the automated control code generation and verification device in the embodiment of this application;

[0052] Figure 6 It is a schematic diagram of the device structure of the hardware operating environment involved in the automated control code generation and verification method in the embodiment of this application.

[0053] The realization of the purpose, functional features and advantages of this application will be further described in conjunction with embodiments with reference to the accompanying drawings. Specific embodiments

[0054] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of this application and are not used to limit this application.

[0055] In order to better understand the technical solutions of this application, the following will be described in detail in conjunction with the accompanying drawings of the specification and specific embodiments.

[0056] The main solution of this application is as follows: receiving a natural language command; the natural language command is used to instruct a large language model to output a code text that meets the control requirements corresponding to the natural language command; performing a matching search on a vector database according to the natural language command to obtain an example code snippet; obtaining API structured information corresponding to the example code snippet from a knowledge graph database; generating an initial control code based on the example code snippet and the API structured information; performing multi-level virtual operation verification on the initial control code in a software motion control system, and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

[0057] The current programming methods for automated control systems mainly include manual programming and templated programming, and the corresponding problems are as follows:

[0058] 1) Manual programming usually uses PLC language or high-level programming languages (such as Python, C++, C#, etc.). Although high-level languages have high flexibility and functionality, their programming complexity is relatively high, and extremely high professional knowledge of engineers is required. In order to meet the high safety requirements of the system, engineers tend to write code manually to ensure reliability. However, this method is not only inefficient and has a long development cycle, but also easily leads to code quality problems due to human errors, and lacks flexibility in the face of changing requirements. Templated programming reduces the programming difficulty and improves the development efficiency through predefined code templates, but its template design usually has difficulty coping with complex scenarios or personalized requirements, and easily leads to a rigid code structure, restricting the adaptability and scalability of the system. Therefore, neither manual programming nor templated programming can balance complexity and safety, and more advanced programming methods are urgently needed to break through these bottlenecks.

[0059] 2) In the field of motion control, many dedicated motion control function libraries contain thousands of API functions, and the parameter settings of each API are complex, which greatly increases the learning cost and usage difficulty. Engineers need to spend a lot of time learning and understanding these APIs, and often have difficulty making flexible adjustments according to specific scenarios. This makes traditional manual and automatic programming tools difficult to be widely used and inefficient.

[0060] 3) After the initial generation of automated control code, repeated testing is still required to ensure that the code works properly with the hardware. During the control execution and optimization of electrical and mechanical components, parameters often need to be gradually adjusted and multiple tests performed to ensure optimal motion performance while eliminating potential safety hazards. This debugging process is time-consuming, tedious, and prone to errors. However, only after debugging to ensure that the code parameters are safe and correct can the control code be applied to the actual equipment.

[0061] Therefore, the current technology in the field of automatic control has a series of problems such as poor flexibility, insufficient accuracy and low efficiency. How to overcome these technical difficulties has become a key issue that needs to be solved urgently in this field.

[0062] In order to solve the above problems, the present application attempts to combine a large language model for intelligent generation of automated control codes. Specifically, the present application first obtains the natural language commands that the user inputs through natural language to describe his or her control needs, and then intelligently parses the natural language commands input by the user, and searches the vector database based on the parsing results to obtain similar codes for the tasks corresponding to the natural language commands, that is, sample code snippets and complete information support associated with the sample code snippets obtained through the knowledge graph database, that is, API structured information, which may include API definitions, parameter interpretations, call constraints, and reference relationships in documents, etc. The large language model then forms a global understanding of the control tasks corresponding to the natural language commands based on the sample code snippets and API structured information, and generates the initial control code. Finally, the present application performs multi-level code verification on the initial control code through a software motion control system, and combines the multi-level verification results confirmed by the user for multiple times to quickly generate highly reliable automated control code that meets user needs.

[0063] Compared with the existing technology, this application can automatically generate and verify automated control code through a large language model, which not only improves the efficiency of code generation, reduces the error rate, but also enhances the maintainability of the code. At the same time, this application effectively avoids the potential risks that may be caused by full automation by introducing multi-level virtual verification that combines user judgment and decision-making steps. At the same time, it enhances the user's trust in the generated code and its execution effect, and ensures the reliability and applicability of the final code. It solves the shortcomings of the existing technology in terms of generation speed and security, and provides a more efficient and reliable method for generating automated control code.

[0064] It should be noted that the execution subject of this embodiment can be an automated control code generation and verification system, or a computing service device with data processing, network communication, and program execution functions, and pre-installed with a large language model (LLM), such as a tablet computer, personal computer, mobile phone, etc., or an automated control code generation and verification device capable of implementing the above functions, etc. This embodiment does not specifically limit this. The following uses the automated control code generation and verification device (hereinafter referred to as the generation and verification device) as the execution subject as an example to illustrate this embodiment and the following embodiments.

[0065] Based on this, the embodiment of the present application provides an automatic control code generation and verification method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the method for automatic control code generation and verification of this application.

[0066] In this embodiment, the automatic control code generation and verification method is applied to a large language model. The method includes steps S10 to S50:

[0067] Step S10: receiving a natural language command; the natural language command is used to instruct the large language model to output a code text that meets the control requirements corresponding to the natural language command;

[0068] It should be understood that the time that existing automation control code developers spend on debugging, document review and architecture design when manually generating code accounts for too high a proportion. Templated code relies on fixed rules and is difficult to handle complex scenarios (such as nested exception handling and multi-threaded collaboration). In order to effectively improve the efficiency of automation control code generation, this embodiment attempts to combine a large language model to achieve intelligent generation of automation control code through semantic understanding and knowledge reasoning, breaking through the boundaries of static rules. Therefore, the above-mentioned natural language commands can be the natural language format input by the user into the large language model dialogue human-computer interface, representing the command statement of its automation control requirements, which can instruct the large language model to output code text that meets the control requirements corresponding to the natural language command after inputting it into the large language model.

[0069] Therefore, this embodiment can subsequently perform intelligent analysis on the natural language commands input by the user through the large language model, and obtain similar codes related to the control requirements corresponding to the natural language commands based on the analysis results.

[0070] Step S20: performing a matching search on a vector database according to the natural language command to obtain a sample code snippet;

[0071] It is easy to understand that in this embodiment, the motion API documents corresponding to different motion control functions can be pre-parsed, and the example code in the motion API documents can be segmented into independent code snippets. After each code snippet is extracted with function descriptions and code content, it can be stored in a vector database using vectorization technology to form a highly retrievable semantic structure. Thus, in actual applications, code snippets related to natural language commands can be quickly retrieved according to user needs, thereby improving the efficiency of code snippet positioning and reducing search time, especially when dealing with a large number of code snippets.

[0072] In a feasible implementation manner, in this embodiment, step S20 includes steps A1 to A3:

[0073] Step A1, perform semantic parsing on the code generation statement to obtain the control main task;

[0074] Step A2, decompose the control main task to obtain several control subtasks;

[0075] Step A3, perform matching retrieval on the vector database according to the control subtasks to obtain example code snippets.

[0076] It should be understood that in order to quickly and accurately locate similar codes related to the control requirements corresponding to natural language commands, this embodiment can perform semantic parsing on the code generation statement by combining the natural language parsing ability of a large language model to obtain the corresponding control main task, and then automatically decompose the complex control main task into several logically clear control subtasks; finally, based on each control subtask, accurately locate example code snippets related to the control requirements of natural language commands from the vector database to improve the high flexibility and adaptability of the code generation method, so that the technical solution proposed in this embodiment can be applied to complex scenarios of multi-module collaboration.

[0077] In one embodiment, assume that the received natural language command is: "Move axis 0 and axis 1 to positions 100 and 150 at a speed of 100 and an S-shaped acceleration of 1000, and set the input signal I0.2 to 1, and then perform spline interpolation on axis 2 and axis 3 to positions 200 and 300". At this time, this embodiment can first parse the user's natural language command through a large language model and decompose the control main task into the following three control subtasks: 1) Control axis 0 and axis 1 to move to the target position at a speed of 100 and an S-shaped acceleration of 1000; 2) Set the input signal I0.2 to 1; 3) Control axis 2 and axis 3 to perform spline interpolation to the target position.

[0078] Then, this embodiment can retrieve code snippets with the highest semantic similarity to each subtask from a pre-constructed vector database, and return codes C1, C2, C3, C4, C5, C6, etc. related to the above three control subtasks. At this time, the obtained codes C1 to C6 together constitute the above example code snippets.

[0079] Step S30, obtain the API structured information corresponding to the example code snippets from the knowledge graph database;

[0080] Step S40, generate initial control codes based on the example code snippets and the API structured information;

[0081] It should be noted that different from the code combination generation in other scenarios, the parameter combinations of the codes in the motion control field are too complex, and tiny parameter changes will also lead to huge changes in the motion control results. Therefore, after determining the example code snippets, the reasonable setting of the function parameters in the example code snippets and the effective sorting and combination of the example code snippets are very complicated.

[0082] Therefore, during the process of pre-parsing the motion API documents of each motion control function in this embodiment, the content including system installation guides, programming tutorials, and the definitions, variables, function names, and function explanations of the APIs can also be summarized into a knowledge graph database for the large language model to learn. For API parameters, such as acceleration and deceleration types, the definitions of these parameters are usually stored in the pre-stored motion API documents and are accompanied by complex graphic explanations. The knowledge graph database can establish reference relationships between these relevant chapter contents and each API function. This database construction method enables users and the large language model to clearly understand the dependency relationships and reference logics between APIs through the knowledge graph, especially in complex scenarios involving cross-references between multiple documents, thus ensuring the safe and effective invocation of automated motion control.

[0083] It can be understood that after obtaining the example code snippets from the vector database, this embodiment can also obtain the associated complete information support from the knowledge graph database, that is, the above API structured information. The API structured information can include the API definitions, parameter explanations, call constraints corresponding to the example code snippets, and reference relationships with other nodes in the document, such as the definitions of various acceleration and deceleration types, overloaded versions of functions, and usage scenarios.

[0084] It should be understood that in this embodiment, there is a mutual mapping relationship between the vector database and the knowledge graph database. During the construction of the knowledge graph database, each API in each code snippet can be regarded as an independent node, and its attributes include the definition of the API, parameter types, function descriptions, call constraints, etc. Each code snippet of the sample code in the vector database can be used as a node to establish a direct association with the APIs and related parameters it uses, thus forming a complete call link, so that the large language model can perform joint retrieval between the two to achieve the rapid generation of the initial control code.

[0085] In one embodiment, in this embodiment, the steps to construct the knowledge graph database can be: parsing the motion control API document into independent nodes, each node containing the API definition, parameter types, and call constraints; establishing the hierarchical relationship between API nodes, including overloaded version associations, parameter dependency references, and sample code call links; performing a two-way mapping between the hierarchical relationship and the semantic vectors in the vector database to form a joint retrieval index.

[0086] Therefore, this embodiment can associate different control nodes through the knowledge graph database, support the flexible splicing of complex functional modules based on the dynamic combination ability of the knowledge graph database, enable the system to handle diverse programming requirements (such as cross-language, multi-platform), and there is no need to redesign the algorithm for a specific scenario. In addition, the unified knowledge graph specification and verification standard can enforce the best coding practices to ensure the maintainability of the project.

[0087] It can be understood that after the large language model obtains the sample code snippet and its corresponding API structure information, it can form a global understanding of the above control main task based on this comprehensive information, thereby quickly generating a more accurate complete control code, that is, the above initial control code, and can ensure that the code logic and practicality of the initial control code are much higher than the traditional generation method based on single similarity semantic search. Through this process, the large language model can comprehensively understand the context and details of each control subtask, combine the sample code in the vector database with the API node information in the knowledge graph database to ensure that the generated initial control code not only contains the logical implementation of the user's requirements but also complies with the rules and call constraints of the API.

[0088] In summary, in this embodiment, the combination of the vector database and the knowledge graph database provides the system with powerful retrieval capabilities and structured analysis capabilities. The vector database is responsible for efficient semantic queries, while the knowledge graph provides hierarchical logical dependency analysis, compensating for the deficiencies of semantic retrieval in complex scenarios. Especially in the field of motion control, this dual-database architecture solves the core problems of document complexity and information relevance, providing users with transparent and efficient technical support. In addition, this embodiment designs a dynamic update mechanism for the vector database and the knowledge graph database, which can be continuously improved as the document content expands and user requirements change, thus ensuring long-term applicability and efficiency. This architecture not only improves the efficiency of document management and code generation, but also provides a solid technical foundation for the decomposition and implementation of complex tasks.

[0089] Step S50, perform multi-level virtual operation verification on the initial control code in the software motion control system, and generate the target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

[0090] It should be understood that to ensure the reliability of the motion control code, in this embodiment, after the large language model automatically generates the initial control code, the software motion control system can perform multi-level virtual operation verification on the initial control code. This software motion control system is pre-loaded in the generation and verification device, can convert an ordinary PC into a real-time system, and does not require a dedicated control chip, but runs on the general CPU of the PC. The software motion control system has a high degree of modularity, powerful available computing power, and high execution efficiency, and can be seamlessly combined with the large language model of AI to quickly run and verify the generated control code and perform process sampling and feedback of the execution results in real time, having advantages that hardware controllers do not have. Therefore, in this embodiment, multi-level virtual operation verification can be performed through the software motion control system to detect whether there are code logic conflicts, syntax errors, and security risks in the initial control code, thereby reducing code defects caused by human negligence and improving code reliability. And the verification results at each level can be confirmed by the user. Finally, based on the multi-level verification results confirmed by the user multiple times and the initial control code, the target control code that finally meets the user's control requirements is generated, avoiding potential risks that may be caused by full automation, enhancing the user's trust in the generated code and its execution effect, and ensuring the reliability and applicability of the final code.

[0091] In summary, in this embodiment, the natural language command input by the user through the dialogue human-machine interface is first obtained, and the large language model can perform semantic parsing on the natural language command to obtain the control main task, and decompose the control main task into multiple control sub-tasks.

[0092] Meanwhile, in this embodiment, a vector database and a knowledge graph database can be pre-constructed for complex API documents and codes in the field of motion control. Among them, the vector database stores function definitions, parameter descriptions, and example codes in the API documents through semantic vectorization, and is used to efficiently retrieve code snippets semantically similar to the user input instructions; while the knowledge graph database stores the structured information of the APIs corresponding to each code snippet in the form of nodes and relationships, including overloaded versions of functions, parameter dependencies, call constraints, and cross-document reference relationships.

[0093] Therefore, after the vector database returns example code snippets related to the natural language command task, the structured information of the APIs involved in the example code snippets, such as the definition of parameter types, overloaded versions of functions, and call dependencies, can be further analyzed through the knowledge graph database, so that the large language model can automatically generate initial control code based on the example code snippets and API structured information. This code automation generation method that not only provides a fast retrieval function but also supports in-depth analysis of complex dependencies between APIs not only supports comprehensive analysis of complex API scenarios but also provides more accurate context support for the large language model, thereby significantly improving the accuracy and logic of the generated control code.

[0094] Finally, this embodiment combines the software motion control system to perform multi-level virtual operation verification on the initial control code, and generates accurate and error-free target control code by combining the initial control code and the multi-level verification results confirmed by the user multiple times.

[0095] Therefore, in the process of realizing the intelligent generation of automated control code based on the large language model in this embodiment, example code snippets related to the control requirements of the natural language command input by the user can be queried from the vector database, and the nodes and relationships of all relevant motion control APIs of the example code snippets can be found from the knowledge graph database as a reference. Then, the large language model automatically generates the corresponding initial control code according to the user's natural language command, the queried example code snippets, and the knowledge graph node and relationship data. Finally, the software motion control system performs multi-level code verification on the initial control code, and quickly generates highly reliable automated control code that meets the user's needs by combining the multi-level verification results confirmed by the user multiple times. Compared with the prior art, this embodiment can automatically generate and verify automated control code through the large language model, which not only improves the code generation efficiency, reduces the error rate, but also enhances the adaptability and maintainability of the code. At the same time, this embodiment effectively avoids potential risks that may be caused by full automation by introducing multi-level virtual verification that combines user judgment and decision-making steps, while enhancing the user's trust in the generated code and its execution effect, and ensuring the reliability and applicability of the final code, solving the deficiencies in the prior art that are difficult to guarantee the generation speed and security, and providing a more efficient and reliable automated control coding generation method.

[0096] This embodiment discloses an automated control code generation and verification method, which includes: obtaining a natural language command; the natural language command is used to instruct a large language model to output a code text that meets the control requirements corresponding to the natural language command; performing semantic parsing on the code generation statement to obtain a control main task; decomposing the control main task to obtain several control sub-tasks; performing matching retrieval on a preset vector library according to the control sub-tasks to obtain example code snippets; obtaining the API structured information corresponding to the example code snippets from a knowledge graph database; performing multi-level virtual operation verification on the initial control code in a software motion control system, and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code. In the process of realizing the intelligent generation of automated control code based on a large language model in this embodiment, example code snippets related to the control requirements of the natural language command input by the user can be queried from the vector database, and the nodes and relationships of all relevant motion control APIs of the example code snippets can be found from the knowledge graph database as a reference. Then, according to the user's natural language command, the queried example code snippets, and the knowledge graph node and relationship data, the large language model automatically generates the corresponding initial control code. Finally, the software motion control system performs multi-level code verification on the initial control code, and quickly generates highly reliable automated control code that meets the user's requirements in combination with the multi-level verification results confirmed by the user multiple times. Compared with the prior art, this embodiment can automatically generate and verify automated control code through a large language model, which not only improves the code generation efficiency, reduces the error rate, but also enhances the adaptability and maintainability of the code. At the same time, this embodiment effectively avoids potential risks that may be caused by full automation by introducing multi-level virtual verification that combines user judgment and decision-making steps, while enhancing the user's trust in the generated code and its execution effect, and ensuring the reliability and applicability of the final code, solving the deficiencies in the prior art that are difficult to guarantee the generation speed and security, and providing a more efficient and reliable automated control coding generation method.

[0097] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar content as the above first embodiment can be referred to the above introduction and will not be repeated hereinafter.

[0098] Referring to Figure 2 , Figure 2 is a schematic flowchart of the second embodiment of the automated control code generation and verification method of the present application. The software motion control system includes a virtual motion engine; in this embodiment, step S50 may include steps B1 to B4:

[0099] Step B1, transmitting the initial control code to the virtual motion engine for device simulation operation, obtaining a code execution result, and performing semantic matching on the code execution result and the natural language command to generate a first verification result;

[0100] It should be noted that, usually, the control code needs to be actually run in the hardware motion controller to verify its effect, which often requires a large amount of time and hardware resources, and there is a risk of device damage or safety hazards caused by the debugging process. To ensure the security of the initial control code, in this embodiment, by introducing a virtual motion engine, the generated initial control code can be run and verified in a virtual environment, and the virtual motion engine can run on a dedicated CPU core (Windows and other programs run on other CPU cores). The virtual motion engine can provide accurate simulation results during operation and generate feedback information for the large language model to judge and correct errors in the code.

[0101] Therefore, in this embodiment, the initial control code can be passed to the virtual motion engine for execution. The virtual motion engine simulates the operation process of the automation device under the action of the initial control code, that is, performs the above-mentioned device simulation operation, and then records the code execution results corresponding to the device simulation operation, including key data such as the position of the control axis, speed, I / O feedback, etc.

[0102] It can be understood that after obtaining the code execution results, the execution results can be compared with the user's original natural language command for preliminary code verification, and it can be determined whether the initial control code can be used as the target control code for final operation according to the virtual operation comparison results corresponding to the preliminary verification. Among them, the comparison method can be to feedback the execution results to the large language model and the user's natural language command for semantic matching to obtain the current semantic matching degree, and then determine the first verification result based on the current semantic matching degree.

[0103] In a feasible implementation manner, in this embodiment, step B1 includes steps B11 to B14:

[0104] Step B11, when the semantic matching degree between the operation result and the natural language command is lower than the preset matching threshold, trigger an error correction process;

[0105] Step B12, query the knowledge graph database based on the operation error information to obtain error API node information; the error API node information includes but is not limited to API interpretation information, example error codes, example error code meanings, and example error code optimization suggestions;

[0106] Step B13, generate a first corrected control code according to the error API node information and the initial control code;

[0107] Step B14, re-execute the first corrected control code and update the first verification result.

[0108] It is understandable that after the large language model compares the code execution result with the natural language command, if problems are found, such as the code execution result does not match the target position required by the user (for example, the target position is 300 and the actual result is 200), or there are syntax errors in the generated code, and the current semantic matching degree is lower than the preset matching degree, the first verification result corresponding to the virtual operation comparison result can be that the large model verification fails, and an error correction process for automatically correcting the code by combining with the knowledge graph database can be triggered.

[0109] At this time, the code segment corresponding to the syntax error code or error execution result determined from the virtual operation comparison result, that is, the above-mentioned running error information, can be determined first. Then, the running error information is fed back to the knowledge graph database to query relevant correction information, such as detailed explanation information of APIs, example error codes, meanings of example error codes, and optimization suggestions for example error codes, etc., and the relevant correction information is passed to the large language model, so that the large language model can quickly correct the initial control code based on the error API node information and re-verify based on the corrected first corrected control code. Through this feedback mechanism, this embodiment can dynamically correct and optimize the initial control code that fails to pass the virtual motion engine verification until the generated code can be correctly executed and meet the user's requirements, thereby gradually improving the accuracy and task adaptability of the code.

[0110] Step B2, after the user confirms the first verification result, the virtual motion engine is used to drive the three-dimensional simulation model to display the device movement process corresponding to the initial control code, and a second verification result is generated, so that the user can intuitively observe whether the device actions corresponding to the initial control code in the three-dimensional simulation model meet the control requirements through the second verification result;

[0111] It is easy to understand that if the user observes that the current semantic matching degree is not lower than the preset matching degree, the first verification result corresponding to the virtual operation comparison can be that the large model verification passes. After the user confirms that the operation result of the virtual motion engine is correct, further simulation verification can be carried out to improve the code reliability. At this time, this embodiment can also drive the three-dimensional simulation model corresponding to the automated device through the virtual motion engine to display the device movement process corresponding to the initial control code, so that the user can intuitively observe whether the simulation operation actions of the automated device meet the expected control requirements through the three-dimensional simulation model for further simulation verification.

[0112] In one embodiment, this embodiment can complete the correspondence between entity objects such as virtual control axes and I / O and virtual axes and virtual devices in the 3D simulation model through object mapping, and generate a 3D execution result that presents the motion process of the virtual axes and virtual devices in real time. For example, the axis numbers of the virtual motion engine can start from axis 100, axis 101, axis 102, and be mapped to the virtual axes in the 3D simulation model, so that the virtual motion engine can control the corresponding 3D simulation model during operation. Therefore, the 3D simulation model can reflect the effect of code execution in real time, including the position, speed, motion trajectory, etc. of the axes, and present them in a 3D visualization manner.

[0113] In a feasible implementation manner, in this embodiment, after step B2, steps B21 to B22 are included:

[0114] Step B21, in response to the user's interactive adjustment instruction for the 3D simulation model, update the natural language command;

[0115] Step B22, regenerate the second corrected control code according to the updated natural language command, and iteratively execute the multi-level virtual operation verification according to the second corrected code.

[0116] It is easy to understand that when the user intuitively observes that the device action does not meet the control requirements through the 3D simulation model, the problems in the code can be quickly identified and an interactive adjustment instruction can be fed back. The interactive adjustment instruction can include instruction adjustment or improvement requirements. After analyzing the interactive adjustment instruction, the large language model can trigger the optimization of the natural language instruction, and then generate a new second corrected control code according to the optimized and updated natural language command, and then re-perform the multi-level virtual operation verification based on the updated second corrected code, so as to further improve the high reliability of the code generation process.

[0117] In this implementation manner, by using the object mapping technology that combines the virtual motion engine and 3D simulation, the motion process executed by the generated control code is presented to the user in a dynamic visualization manner, so that through further simulation verification, the user can intuitively observe through the 3D simulation whether the device action under the initial control code meets the requirements, and verify the running correctness of the generated code in advance, so as to quickly identify the problems in the code and optimize them. This dynamic visualization method significantly improves the transparency of the control code generation and verification process, enabling users to more efficiently adjust and optimize the generated code, thereby improving the development efficiency and the accuracy of the results.

[0118] Step B3, after the user confirms the second verification result, periodically collect the motion process data during the operation of the virtual motion engine, and generate a third verification result according to the motion process data; the motion process data includes but is not limited to the position, speed, current feedback of the control axis, and I / O status;

[0119] Step B4. After the user confirms the third verification result, use the control code finally confirmed by the user as the target control code.

[0120] It is easy to understand that if the simulation result shown by the three-dimensional simulation model meets the user's control requirements, after the user confirms the second verification result, a more refined process verification can be performed with the verification device. At this time, this embodiment can perform periodic sampling on the execution process of the virtual motion engine to obtain dynamic information such as the actual position, speed, current feedback, and I / O status of each control axis when the virtual motion engine runs based on the initial control code, that is, the above-mentioned motion process data for the user to judge whether it meets the overall requirements. At this time, the comparison between the preset stage operation data and the motion process data can be further used to verify whether the trajectory and end point of the code execution are consistent with the expectation, and a third verification result is generated.

[0121] In a feasible implementation manner, in this embodiment, step B3 includes steps B31 to B32:

[0122] Step B31. Divide the motion process data into multiple verification intervals according to a preset time stage;

[0123] Step B32. In each verification interval, the user compares the real-time parameters with the expected values of the corresponding stage to generate a third verification result.

[0124] It should be understood that for a fine comparison of code execution, this embodiment can divide the collected motion process data into multiple verification intervals according to time stages. Each verification interval can include corresponding real-time motion parameters, and the real-time motion parameters are displayed to the user in different verification intervals for comparison and verification, so that the user can verify whether the trajectory and end point of the code execution are consistent with the expectation based on these data. If there is a problem, the natural language command is corrected, and the verification device can regenerate the control code and perform multi-level virtual operation verification again.

[0125] Exemplarily, in each verification interval, the user can compare the displayed real-time parameters with the expected values of the corresponding stage and generate a third verification result according to the comparison result. It can be understood that at this time, if the user finds that the difference between the real-time parameters and the corresponding expected values in any verification interval exceeds the safety threshold, it can be determined that the preset stage operation data and the motion process data are inconsistent, and the third verification result is that the process verification fails, and a code iteration process based on the user's correction instruction is triggered; if the differences between the real-time parameters and the corresponding expected values in all verification intervals meet the safety threshold, it can be determined that the third verification result is that the process verification passes.

[0126] At this time, the above code iteration process can be to trigger a user alert and pause subsequent code deployment, while waiting for the user to input natural language commands for adjustment and optimization based on the third verification result, and then further optimize the initial control code according to the adjusted and optimized natural language commands until the optimized control code can pass the above process data verification. This process verification method significantly improves the accuracy of problem diagnosis, enables the user to scientifically adjust the control strategy, and thus effectively optimizes the code generation process. At the same time, this mechanism further enhances the transparency and interpretability of the code generation system.

[0127] It can be understood that when the above large model verification, simulation verification, and process verification are sequentially performed on the initial control code, and the verification results at all levels are confirmed under the real-time supervision and intervention of the user, this embodiment can use the latest control code corresponding to the third verification result finally confirmed by the user as the final target control code.

[0128] In a feasible implementation manner, the software motion control system further includes a real-time motion engine; in this embodiment, after step S50, the following steps are further included:

[0129] Step S60, in response to the user's execution decision, synchronize the runtime environment configuration of the virtual motion engine to the real-time motion engine; after the configuration synchronization, the axis numbers of the virtual motion engine and the real-time motion engine correspond one by one, and the virtual motion engine and the real-time motion engine use the same motion control function library;

[0130] Step S70, send the control code to the real-time motion engine to perform periodic control on the automation device based on the target control code through the real-time motion engine.

[0131] It is easy to understand that in this embodiment, after the user confirms that the control code generated by the large language model passes the above large model verification, process verification, and simulation verification, the user can make an execution decision based on the target control code that has passed multiple levels of virtual operation verification. For ease of understanding, refer to Figure 3 for an example. Figure 3 This is the structural control block diagram of the second embodiment of the automation control code generation and verification method of the present application. As Figure 3 shown. After the initial control code passes multiple levels of verification, the user can decide whether to deploy the control code to the actual device.

[0132] When the user inputs an execution decision to decide to deploy, the target control code generated by MCCoder (Motion Control Coder) that has passed multiple levels of verification and is confirmed by the user can be obtained from the software motion control system (such as Figure 3Transfer the virtual motion engine in Softmotion) to the real-time motion engine, which can also run on a dedicated CPU core. At this time, this embodiment can periodically send target control codes to the real-time motion engine to perform periodic control on the automation device based on the target control codes through the real-time motion engine.

[0133] It should be noted that before the code transfer, this embodiment can synchronize the runtime environment configuration of the virtual motion engine to the real-time motion engine, so as to ensure the consistency between the virtual motion engine and the real-time motion engine, ensure that the results of code execution between the two are exactly the same at the logical level, and further ensure that the simulation results generated by the virtual motion engine can be directly migrated to the actual device, greatly reducing the errors caused by the inconsistency between simulation and reality in the traditional method, ensuring the reliability of the control code from generation to deployment, reducing the trial-and-error cost during the deployment process at the same time, providing a solid guarantee for high-precision motion control tasks, and reducing the equipment damage and personnel risks that may be brought by running incorrect codes directly on the automation device.

[0134] It should be understood that in this embodiment, after the configuration synchronization is successful, the axis numbers of the virtual motion engine and the real-time motion engine correspond one by one, and the virtual motion engine and the real-time motion engine can call the same set of motion control function libraries to ensure the same operation mechanism and algorithm. At the same time, the axis numbers controlled by the real-time motion engine can start from axis 0, axis 1, axis 2, axis 3 and be directly bound to the actual axes on the automation device. Therefore, when the real-time motion engine runs, the actual automation device will execute immediately according to the control instructions; when the virtual motion engine runs, it can control the corresponding 3D simulation model. Especially in complex motion logic or high-risk scenarios, the motion effect can be intuitively displayed through the simulation model, and users can discover potential problems before the code actually runs on the automation device. Finally, when the virtual engine passes the verification, the code will be handed over to the real-time motion engine for execution on the actual automation device. This mechanism not only ensures the consistency between the virtual environment and the actual device operation, but also provides a safe and reliable code verification process for users, greatly reducing the operation risk.

[0135] In this embodiment, through multi-level verification and multiple iterative optimizations including virtual motion engine verification, simulation verification, and process data verification, the reliability of the finally determined target control code can be significantly improved. Meanwhile, when all levels of verification are passed, the iteratively optimized target control code can be transferred from the virtual motion engine to the real-time motion engine, and the operation of the automation device can be controlled by outputting periodic control instructions. Since both the virtual motion engine and the real-time motion engine operate in a real-time environment and strictly ensure the consistency of the operation mechanism and execution results at the bottom layer, it ensures that users can make judgments and decisions based on accurate and reliable feedback. Therefore, this embodiment reduces the dependence on actual hardware, reduces the complexity and potential risks during the debugging process, and improves the development efficiency at the same time.

[0136] Generally speaking, this embodiment can achieve precise control of automation devices through automatic code generation, multiple verifications, and error correction, improve the work efficiency of engineers, reduce the error rate, and provide an innovative and perfect solution for highly secure and highly reliable automation control at the same time. Through this process, this embodiment realizes the automatic generation and execution of natural language commands into motion control codes, reduces the technical threshold for users, and improves the reliability and flexibility of the automation control code generation and verification method proposed in this embodiment.

[0137] Meanwhile, this embodiment also introduces user judgment and decision-making steps in key links such as control code generation, simulation verification, and execution decision-making, enabling users to supervise and intervene in the entire code generation and verification process in real time. This human-machine collaboration mechanism effectively avoids potential risks that may be caused by full automation, and at the same time enhances users' trust in the generated code and its execution effect. In control scenarios with high security requirements, the participation of users not only improves the transparency of the system but also ensures the reliability and applicability of the final code.

[0138] This embodiment discloses transmitting initial control code to a virtual motion engine for device simulation operation, obtaining the code execution result, semantically matching the code execution result with a natural language command to generate a first verification result; when the semantic matching degree between the operation result and the natural language command is lower than a preset matching threshold, triggering an error correction process; querying a knowledge graph database based on the operation error information to obtain error API node information; the error API node information includes but is not limited to API interpretation information, example error codes, example error code meanings, and example error code optimization suggestions; generating a first corrected control code according to the error API node information and the initial control code; re-executing the first corrected control code and updating the first verification result. After the user confirms the first verification result, driving a 3D simulation model through the virtual motion engine to display the device motion process corresponding to the initial control code, generating a second verification result, so that the user can intuitively observe whether the device actions corresponding to the initial control code in the 3D simulation model meet the control requirements through the second verification result; in response to the user's interactive adjustment instruction for the 3D simulation model, updating the natural language command; regenerating a second corrected control code according to the updated natural language command, and iteratively performing multi-level virtual operation verification according to the second corrected code. After the user confirms the second verification result, periodically collecting motion process data during the operation of the virtual motion engine, and generating a third verification result according to the motion process data; the motion process data includes but is not limited to the position, speed, current feedback, and IO status of the control axis; dividing the motion process data into multiple verification intervals according to a preset time stage; within each verification interval, the user compares the real-time parameters with the expected values of the corresponding stage to generate a third verification result. After the user confirms the third verification result, taking the control code finally confirmed by the user as the target control code.

[0139] In addition, in this embodiment, the software motion control system further includes a real-time motion engine; in response to the user's execution decision, synchronizing the runtime environment configuration of the virtual motion engine to the real-time motion engine; after the configuration synchronization, the axis numbers of the virtual motion engine and the real-time motion engine correspond one by one, and the virtual motion engine and the real-time motion engine use the same motion control function library; sending the control code to the real-time motion engine to perform periodic control on the automation device based on the target control code through the real-time motion engine.

[0140] In this embodiment, through multi-level verification and multiple iterative optimizations of virtual motion engine verification, simulation verification, and process data verification, the reliability of the finally determined target control code is significantly improved. At the same time, when all levels of verification are passed, the target control code can be transferred from the virtual motion engine to the real-time motion engine, and the operation of the automation device is controlled by the output of periodic control instructions. Since both the virtual motion engine and the real-time motion engine run in a real-time environment and strictly ensure the consistency of the operation mechanism and execution results at the bottom layer, it is ensured that users can make judgments and decisions based on accurate and reliable feedback. Therefore, this embodiment reduces the dependence on actual hardware, reduces the complexity and potential risks during the debugging process, and improves the development efficiency at the same time.

[0141] Exemplarily, to help understand the technical concept or technical principle of the automated control code generation and verification method after combining this embodiment with the above-mentioned Embodiment 1 and Embodiment 2, please refer to Figure 4 , Figure 4 which is a schematic flowchart of the brief process of the automated control code generation and verification method of this application, specifically as follows:

[0142] 1. Start: The system starts the task processing flow.

[0143] 2. User inputs a natural language command: The user inputs a natural language command through the dialogue human-machine interface, and the system receives and performs semantic parsing on the command.

[0144] 3. The main task is decomposed into subtasks: After the large language model performs semantic parsing on the natural language command input by the user, the corresponding control main task is decomposed into multiple control subtasks for further processing.

[0145] 4. Search for subtask-related code in the vector database: Query code examples or modules related to the control subtasks from the constructed vector database, that is, example code snippets for reference in code generation.

[0146] 5. Search for API-related nodes and relationships in the knowledge graph database: Using the knowledge graph, extract the API nodes corresponding to the example code snippets involved in the control subtasks and their call relationships, that is, API structured information, to support the overall and structured analysis of code generation.

[0147] 6. The large language model generates control code: The large language model combines the natural language command input by the user, the example code snippets matched in the vector database, and the API structured information found in the knowledge graph database to automatically generate the initial control code.

[0148] 7. The virtual motion engine executes the code: The generated initial control code is executed by the virtual motion engine to simulate the actions of the automation device and record the feedback information, that is, the code execution result.

[0149] 8. Run 3D simulation: After the system completes the correspondence between the virtual control axes and virtual devices in the three-dimensional (3D) simulation model generated by modeling entity objects such as virtual control axes and I / O with the automation device through object mapping, it uses the results of the virtual motion engine to run the 3D simulation model, visually demonstrating the device operation process and providing visual verification for users.

[0150] 9. Feed the execution result back to the large language model for comparison with the user's natural language command: Compare the code execution result of the virtual motion engine running according to the initial control code with the natural language command input by the user to verify whether the code execution result and syntax are correct.

[0151] 10. No syntax error and consistent result (the first large model verification): Verify whether the syntax of the generated code is correct and whether the execution result conforms to the user's natural language command; if passed, proceed to the next simulation verification, otherwise, search for relevant content in the vector and knowledge graph database according to the running error information, obtain the error API section information, and return to regenerate the code.

[0152] 11. The 3D simulation process is monitored without error (the second simulation verification): The user monitors the device operation actions and key information in the 3D simulation model in real time to verify whether the motion behavior meets the expectations; if there are problems, the user issues correction commands, that is, the above-mentioned interactive adjustment instructions, regenerate the second corrected control code and verify it.

[0153] 12. The sampling data of the virtual motion engine is correct (the third process verification): The virtual motion engine periodically collects motion process data (such as control axis position, speed, current feedback, etc.), and the user compares the numerical values with the expected values to ensure that the data is correct; if there are problems, the user needs to correct the instructions again.

[0154] 13. The user makes an execution decision: The system presents the simulation result and sampling data to the user, and the user makes an execution decision to determine whether to deploy the control code to the actual device.

[0155] 14. The real-time motion engine sends control instructions to the automation device: After the user confirms, the system sends the control instructions to the automation device through the real-time motion engine to ensure that the actual device behavior is consistent with the simulation.

[0156] 15. End: The task is completed and the process ends.

[0157] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the automation control code generation and verification method of this application. Based on this technical concept, more forms of simple transformations are within the protection scope of this application.

[0158] This application also provides an automation control code generation and verification device, please refer toFigure 5 , Figure 5 This is a schematic diagram of the module structure of the automated control code generation and verification device according to an embodiment of the present application. In this embodiment, the automated control code generation and verification device includes:

[0159] An interaction module 501, configured to receive a natural language command; the natural language command is used to instruct a large language model to output a code text that meets the control requirements corresponding to the natural language command;

[0160] A code location module 502, configured to perform a matching search on a vector database according to the natural language command to obtain an example code snippet;

[0161] A relationship acquisition module 503, configured to obtain API structured information corresponding to the example code snippet from a knowledge graph database;

[0162] A code generation module 504, configured to generate an initial control code based on the example code snippet and the API structured information;

[0163] A code execution module 505, configured to perform multi-level virtual operation verification on the initial control code in a software motion control system, and generate a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

[0164] As an implementable manner, in this embodiment, the code location module 502 is further configured to perform semantic parsing on the code generation statement to obtain a control main task;

[0165] The code location module 502 is further configured to decompose the control main task to obtain a plurality of control subtasks;

[0166] The code location module 502 is further configured to perform a matching search on the vector database according to the control subtasks to obtain an example code snippet.

[0167] As an implementable manner, in this embodiment, the code execution module 505 is further configured to transmit the initial control code to the virtual motion engine for device simulation operation, obtain a code execution result, and perform semantic matching on the code execution result and the natural language command to generate a first verification result;

[0168] The code execution module 505 is further configured to, after the user confirms the first verification result, drive a three-dimensional simulation model through the virtual motion engine to display the device motion process corresponding to the initial control code, and generate a second verification result, so that the user can intuitively observe whether the device actions corresponding to the initial control code in the three-dimensional simulation model meet the control requirements through the second verification result;

[0169] The code execution module 505 is further configured to periodically collect the motion process data during the operation of the virtual motion engine after the user confirms the second verification result, and generate a third verification result based on the motion process data; the motion process data includes, but is not limited to, the position, speed, current feedback, and IO status of the control axis.

[0170] The code execution module 505 is further configured to use the control code finally confirmed by the user as the target control code after the user confirms the third verification result.

[0171] As an implementable manner, in this embodiment, the code execution module 505 is further configured to trigger an error correction process when the matching degree between the operation result and the semantics of the natural language command is lower than a preset matching threshold.

[0172] The code execution module 505 is further configured to query the knowledge graph database based on the operation error information to obtain error API node information; the error API node information includes, but is not limited to, API explanation information, example error codes, meanings of example error codes, and optimization suggestions for example error codes.

[0173] The code execution module 505 is further configured to generate a first corrected control code based on the error API node information and the initial control code.

[0174] The code execution module 505 is further configured to re-execute the first corrected control code and update the first verification result.

[0175] As an implementable manner, in this embodiment, the code execution module 505 is further configured to update the natural language command in response to an interactive adjustment instruction of the user for the three-dimensional simulation model.

[0176] The code execution module 505 is further configured to regenerate a second corrected control code according to the updated natural language command, and iteratively execute the multi-level virtual operation verification according to the second corrected code.

[0177] As an implementable manner, in this embodiment, the code execution module 505 is further configured to divide the motion process data into multiple verification intervals according to a preset time stage.

[0178] The code execution module 505 is further configured to, within each verification interval, have the user compare the real-time parameters with the expected values of the corresponding stage to generate a third verification result.

[0179] As an implementable manner, in this embodiment, the software motion control system further includes a real-time motion engine; the code execution module 505 is further configured to synchronize the runtime environment configuration of the virtual motion engine to the real-time motion engine in response to the execution decision of the user; after the configuration synchronization, the axis numbers of the virtual motion engine and the real-time motion engine correspond one by one, and the virtual motion engine and the real-time motion engine use the same motion control function library;

[0180] The code execution module 505 is further configured to send the control code to the real-time motion engine, so as to perform periodic control on the automation device based on the target control code through the real-time motion engine.

[0181] The automation control code generation and verification device provided by the present application adopts the automation control code generation and verification method in the above embodiment, and can solve the technical problem of automation control code generation. Compared with the prior art, the beneficial effects of the automation control code generation and verification device provided by the present application are the same as those of the automation control code generation and verification method provided by the above embodiment, and other technical features in the automation control code generation and verification device are the same as the features disclosed in the method of the above embodiment, and will not be elaborated here.

[0182] The present application provides an automation control code generation and verification device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute the automation control code generation and verification method in the above embodiment;

[0183] The device further includes a software motion control system, and the software motion control system includes a virtual motion engine and a real-time motion engine.

[0184] Next, refer to Figure 6 , which shows a schematic structural diagram of an automation control code generation and verification device suitable for implementing the embodiments of the present application. The automation control code generation and verification device in the embodiments of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6The illustrated automated control code generation and verification device is merely an example and should not impose any restrictions on the functions and scope of use of the embodiments of this application.

[0185] As Figure 6 shown, the automated control code generation and verification device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM: Random Access Memory) 1004. In the random access memory 1004, various programs and data required for the operation of the automated control code generation and verification device are also stored. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; a communication device 1009; and a software motion control system 1010. The communication device 1009 can allow the automated control code generation and verification device to communicate with other devices wirelessly or wiredly to exchange data. The software motion control system 1010 can convert an ordinary PC into a real-time system. It does not require a dedicated control chip but runs on the general-purpose CPU of the PC, where the virtual motion engine and the real-time motion control engine run on a dedicated CPU core (Windows and other programs run on other CPU cores). The software motion control system 1010 has a high degree of modularity, powerful available computing power, and high execution efficiency. It can be seamlessly combined with the large language model of AI to quickly run and verify the generated control code and perform process sampling and feedback of the execution results in real time, having advantages that a hardware controller does not possess. Although the figure shows an automated control code generation and verification device with various systems, it should be understood that it is not required to implement or have all the shown systems. Instead, more or fewer systems can be implemented or had.

[0186] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include an automated control code generation and verification program product, which includes an automated control code generation and verification program carried on a computer-readable medium. The automated control code generation and verification program contains program code for performing the methods shown in the flowcharts. In such an embodiment, the automated control code generation and verification program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a read-only memory 1002. When the automated control code generation and verification program is executed by a processing device 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are performed.

[0187] The automated control code generation and verification device provided by the present application adopts the automated control code generation and verification method in the above-mentioned embodiment, and can solve the technical problems of automated control code generation. Compared with the prior art, the beneficial effects of the automated control code generation and verification device provided by the present application are the same as those of the automated control code generation and verification method provided by the above-mentioned embodiment, and other technical features in the automated control code generation and verification device are the same as the features disclosed in the method of the previous embodiment, and will not be described in detail here.

[0188] It should be understood that the various parts disclosed in the present application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in a suitable manner in any one or more embodiments or examples.

[0189] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application, and all should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

[0190] The present application provides a storage medium having computer-readable program instructions stored thereon (i.e., an automated control code generation and verification program), and the computer-readable program instructions are used to execute the automated control code generation and verification method in the above-mentioned embodiment.

[0191] The storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or components, or any combination of the above. More specific examples of storage media can include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution system, device, or component. The program code contained on the storage medium can be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0192] The above storage medium can be included in an automated control code generation and verification device; it can also exist independently and not be assembled into an automated control code generation and verification device.

[0193] The above storage medium carries one or more programs. When the above one or more programs are executed by an automated control code generation and verification device, the automated control code generation and verification device is caused to: generate automated control code.

[0194] The automated control code generation and verification program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The above programming languages include object-oriented programming languages - such as Java, Python, C++; they also include conventional procedural programming languages - such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network - including a local area network (LAN) or a wide area network (WAN) - or can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).

[0195] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and automated control code generation and verification program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0196] The modules involved in the embodiments of the present application can be implemented in software or in hardware. In some cases, the name of the module does not constitute a limitation on the unit itself.

[0197] The readable storage medium provided by the present application is a storage medium that stores computer-readable program instructions (i.e., the automated control code generation and verification program) for executing the above-mentioned automated control code generation and verification method, and can solve the technical problems of automated control code generation. Compared with the prior art, the beneficial effects of the storage medium provided by the present application are the same as those of the automated control code generation and verification method provided in the above embodiments, and will not be elaborated herein.

[0198] The above are only some embodiments of the present application, and do not limit the patent scope of the present application. Any equivalent structural transformation made by using the content of the specification and the accompanying drawings of the present application under the technical concept of the present application, or any direct / indirect application in other related technical fields, is included in the patent protection scope of the present application.

Claims

1. An automated control code generation and verification method, characterized in that, The method is applied to a large language model, and the method includes: Receiving a natural language command; the natural language command is used to instruct the large language model to output code text that meets the control requirements corresponding to the natural language command; Performing a matching search on the vector database according to the natural language command to obtain example code snippets; Obtaining the API structured information corresponding to the example code snippet from the knowledge graph database; Generating an initial control code based on the example code snippet and the API structured information; Performing multi-level virtual operation verification on the initial control code in a software motion control system, and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

2. The automated control code generation and verification method according to claim 1, wherein The step of performing a matching search on the vector database according to the code generation statement to obtain example code snippets includes: Performing semantic parsing on the code generation statement to obtain the main control task; Decomposing the main control task to obtain a number of control subtasks; Performing a matching search on the vector database according to the control subtasks to obtain example code snippets.

3. The automated control code generation and verification method according to claim 1, wherein The software motion control system includes a virtual motion engine; the step of performing multi-level virtual operation verification on the initial control code in the software motion control system and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code includes: Transmitting the initial control code to the virtual motion engine for device simulation operation, obtaining the code execution result, and performing semantic matching between the code execution result and the natural language command to generate a first verification result; After the user confirms the first verification result, driving a 3D simulation model through the virtual motion engine to display the device motion process corresponding to the initial control code, generating a second verification result, so that the user can intuitively observe whether the device actions corresponding to the initial control code in the 3D simulation model meet the control requirements through the second verification result; After the user confirms the second verification result, periodically collecting the motion process data during the operation of the virtual motion engine, and generating a third verification result according to the motion process data; the motion process data includes but is not limited to the position, speed, current feedback, and IO status of the control axis; After the user confirms the third verification result, taking the control code finally confirmed by the user as the target control code.

4. The automated control code generation and verification method according to claim 3, wherein The step of generating the first verification result includes: When the semantic matching degree between the operation result and the natural language command is lower than a preset matching threshold, triggering an error correction process; Querying the knowledge graph database based on the operation error information to obtain error API node information; the error API node information includes but is not limited to API explanation information, example error codes, example error code meanings, and example error code optimization suggestions; Generating a first corrected control code according to the error API node information and the initial control code; Re-executing the first corrected control code and updating the first verification result.

5. The automated control code generation and verification method according to claim 3, wherein After generating the second verification result, it further includes: Update the natural language command in response to an interactive adjustment instruction from the user for the 3D simulation model; Regenerate the second correction control code according to the updated natural language command, and iteratively execute the multi-level virtual operation verification according to the second correction code.

6. The automated control code generation and verification method according to claim 3, wherein The step of generating the third verification result according to the motion process data includes: Dividing the motion process data into multiple verification intervals according to a preset time stage; Within each verification interval, the user compares the real-time parameters with the expected values of the corresponding stage to generate the third verification result.

7. The automated control code generation and verification method according to claim 6, wherein The software motion control system further includes a real-time motion engine; after performing multi-level virtual operation verification on the initial control code in the software motion control system and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code, it further includes: In response to the user's execution decision, synchronize the runtime environment configuration of the virtual motion engine to the real-time motion engine; after the configuration synchronization, the axis numbers of the virtual motion engine and the real-time motion engine correspond one by one, and the virtual motion engine and the real-time motion engine use the same motion control function library; Send the control code to the real-time motion engine to perform periodic control on the automation device by the real-time motion engine based on the target control code.

8. An automated control code generation and verification device, characterized in that, The automation control code generation and verification device includes: An interaction module for receiving natural language commands; the natural language commands are used to instruct the large language model to output code texts that meet the control requirements corresponding to the natural language commands; A code positioning module for performing matching retrieval on the vector database according to the natural language command to obtain example code snippets; A relationship acquisition module for obtaining API structured information corresponding to the example code snippets from the knowledge graph database; A code generation module for generating an initial control code based on the example code snippets and the API structured information; A code execution module for performing multi-level virtual operation verification on the initial control code in the software motion control system and generating a target control code according to the multi-level verification results confirmed by the user multiple times and the initial control code.

9. An automated control code generation and verification device, characterized in that, The automation control code generation and verification device includes: a memory, a processor, and an automation control code generation and verification program stored on the memory and executable on the processor, and the automation control code generation and verification program is configured to implement the steps of the automation control code generation and verification method according to any one of claims 1 to 7; The device further includes a software motion control system, and the software motion control system includes a virtual motion engine and a real-time motion engine.

10. A storage medium, characterized in that, The storage medium is a computer storage medium, and an automation control code generation and verification program is stored on the storage medium. When the automation control code generation and verification program is executed by the processor, it implements the steps of the automation control code generation and verification method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method for rapid generation of three-dimensional surface model through numerical control processing program codes

    CN101751005A

  • Excavator control program PLC code automatic generation method, test method and visual test system

    CN113885426A

  • Retrieval-enhanced structured code generation system and method

    CN116909574A

  • Java code generation and self-repairing system

    CN119149042A

  • PLC code generation and verification method based on large language model

    CN119201059A

Cited By

  • Code generation method and computing device

    CN121166525A

  • Code generation method and computing device

    CN121166525B

  • Heating ventilation and air conditioning system control code automatic modification method based on large language model

    CN121233090A

  • Heating ventilation and air conditioning system control code automatic generation method based on large language model

    CN121277068A

  • Industrial control instruction security verification method based on neural symbol multi-layer interception

    CN121956787A