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

By combining a large language model with a vector database and a knowledge graph database to generate and verify automated control codes, the problems of poor flexibility and low efficiency in existing technologies are solved, and efficient and reliable automated control code generation is achieved.

CN120406914BActive Publication Date: 2026-03-24HONG KONG UNIV OF SCI & TECH (GUANGZHOU) +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-09
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing automated control code generation technologies suffer from poor flexibility, insufficient accuracy, and low efficiency. They are difficult to adapt to personalized needs in complex scenarios, and repeated debugging and testing are required after generation to ensure security and reliability.

Method used

A large language model is used in combination with vector databases and knowledge graph databases to generate initial control code through natural language commands. Multi-level virtual operation verification is performed in the software motion control system, and target control code is generated after multiple confirmations by the user.

Benefits of technology

It improves code generation efficiency, reduces error rates, enhances code maintainability and reliability, avoids potential risks that may result from full automation, and increases users' trust in the generated code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406914B_ABST
    Figure CN120406914B_ABST
Patent Text Reader

Abstract

The application 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, receives a natural language command, performs matching and retrieval on a vector database according to the natural language command to obtain an example code segment, obtains API structured information corresponding to the example code segment from a knowledge graph database, generates an initial control code based on the example code segment and the API structured information, performs multi-level virtual running verification on the initial control code in a software motion control system, and generates a target control code according to multi-level verification results confirmed by a user multiple times and the initial control code. According to the application, the initial control code is automatically generated based on the double-database retrieval of the large language model, multi-level code verification is performed through the software motion control system, the target control code is generated in combination with the verification results confirmed by the user 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] This application relates to the field of automation control technology, and in particular to a method, apparatus, device and storage medium for generating and verifying automation control codes. Background Technology

[0002] Current programming methods for automated control systems mainly include manual programming and template-based programming, both of which face significant challenges in terms of complexity and safety. Manual programming is limited by the experience and ability of developers, as well as the extensive setup and learning of API functions, leading to issues such as a high risk of generation errors and long development and debugging cycles. Template-based programming, on the other hand, often struggles to handle complex scenarios or personalized requirements, limiting the system's adaptability and scalability. Furthermore, after the initial code generation, repeated debugging and testing of both hardware and code are required to determine the appropriate parameters before code generation is finally complete, resulting in a lengthy code synthesis process.

[0003] Therefore, current technologies for generating automated control codes suffer from a series of problems, including poor flexibility, insufficient accuracy, and low efficiency. Overcoming these technical challenges and improving the efficiency and reliability of automated control code generation has become a critical issue that urgently needs to be addressed in this field. Summary of the Invention

[0004] The main objective of this application is to provide an automated control code generation and verification method, apparatus, device, and storage medium, aiming to solve the technical problem of how to improve the efficiency and reliability of automated control code generation.

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

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

[0007] The vector database is matched and retrieved according to the natural language commands to obtain example code snippets;

[0008] Obtain the API structure information corresponding to the example code snippet from the knowledge graph database;

[0009] Initial control code is generated based on the example code snippet and the API structure information;

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

[0011] In one embodiment, the step of matching and retrieving a vector database based on the code generation statement to obtain an example code snippet includes:

[0012] Semantic parsing is performed on the code generation statements to obtain the main control task;

[0013] The main control task is decomposed to obtain several sub-control tasks;

[0014] The vector database is matched and retrieved according to the control subtask 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 of the initial control code in the software motion control system, and generating target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code, includes:

[0016] The initial control code is transmitted to the virtual motion engine for device simulation, the code execution result is obtained, and the code execution result is semantically matched with the natural language command to generate a first verification result.

[0017] After the user confirms the first verification result, the virtual motion engine drives the three-dimensional simulation model 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 action corresponding to the initial control code in the three-dimensional simulation model meets the control requirements through the second verification result.

[0018] After the user confirms the second verification result, motion process data of the virtual motion engine during operation is periodically collected, and a third verification result is generated 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;

[0019] After the user confirms the third verification result, the control code finally confirmed by the user will be used 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 running result and the natural language command is lower than a preset matching threshold, an error correction process is triggered;

[0022] Based on the runtime error information, the knowledge graph database is queried to obtain error API node information; the error API node information includes, but is not limited to, API explanation information, example error code, meaning of example error code, and optimization suggestions for example error code.

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

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

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

[0026] In response to the user's interactive adjustment instructions on the 3D simulation model, update the natural language commands;

[0027] The second correction control code is regenerated based on the updated natural language command, and the multi-level virtual operation verification is iteratively executed based on the second correction code.

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

[0029] The motion process data will be divided 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 ​​for 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 of the initial control code in the software motion control system, and generating target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code, the system further includes:

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

[0033] The control code is sent to the real-time motion engine so that the real-time motion engine can perform periodic control of the automated equipment based on the target control code.

[0034] Furthermore, to achieve the above objectives, this application also proposes an automated control code generation and verification device, which includes:

[0035] An interaction module is used to receive natural language commands; the natural language commands are used to instruct the large language model to output code text that meets the control requirements corresponding to the natural language commands.

[0036] The code location module is used to match and retrieve sample code snippets from the vector database based on the natural language commands.

[0037] The relationship acquisition module is used to obtain the API structure information corresponding to the example code snippet from the knowledge graph database;

[0038] The code generation module is used to generate initial control code based on the example code snippet and the API structure information;

[0039] The code execution module is used to perform multi-level virtual operation verification of the initial control code in the software motion control system, and generate target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code.

[0040] In addition, to achieve the above objectives, this application also proposes an automated control code generation and verification device, the device including: a memory, a processor, and an automated control code generation and verification program stored on the memory and capable of running on the processor, the automated control code generation and verification program being configured to implement the steps of the automated control code generation and verification method as described above;

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

[0042] In addition, to achieve the above objectives, this application also provides a storage medium, which is a computer-readable storage medium, on which a program implementing the automated control code generation and verification method is stored. The program 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] This application provides a method, apparatus, device, and storage medium for generating and verifying automated control code. The method is applied to a large language model and includes: receiving a natural language command; the natural language command instructing the large language model to output code text that meets the control requirements corresponding to the natural language command; performing a matching search on a vector database based on the natural language command to obtain example code snippets; retrieving the API structured information corresponding to the example code snippets from a knowledge graph database; generating initial control code based on the example code snippets 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 based on the multi-level verification results confirmed by the user and the initial control code.

[0044] This application utilizes a large language model to perform dual-database retrieval, obtaining example code snippets and API structured information relevant to natural language command control requirements. It automatically generates accurate and logical initial control code and performs multi-level verification of this initial control code through a software motion control system. Combining the multi-level verification results with multiple user confirmations, it rapidly generates highly reliable automated control code that meets user needs. Compared to existing technologies, this application automates the generation and verification of automated control code through a large language model, improving code generation efficiency, reducing error rates, and enhancing code maintainability. Furthermore, by introducing multi-level virtual verification that incorporates user judgment and decision-making steps, this application effectively avoids potential risks associated with full automation, enhances user trust in the generated code and its execution effects, and ensures the reliability and applicability of the final code. This addresses the shortcomings of existing technologies in guaranteeing generation speed and security, providing a more efficient and reliable method for generating automated control codes. Attached Figure Description

[0045] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve 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 drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

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

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

[0049] Figure 3 This 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 This is a simplified flowchart illustrating the automated control code generation and verification method of this application;

[0051] 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 this application;

[0052] Figure 6 This 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 embodiments of this application.

[0053] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

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

[0055] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0056] The main solution of this application is as follows: receiving natural language commands; the natural language commands instructing a large language model to output code text that meets the control requirements corresponding to the natural language commands; matching and retrieving sample code snippets from a vector database based on the natural language commands; obtaining API structured information corresponding to the sample code snippets from a knowledge graph database; generating initial control code based on the sample code snippets and 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 based on the multi-level verification results confirmed by the user multiple times and the initial control code.

[0057] Current programming methods for automated control systems mainly include manual programming and template-based programming, which have the following problems:

[0058] 1) Manual programming typically uses PLC languages ​​or high-level programming languages ​​(such as Python, C++, C#, etc.). While high-level languages ​​offer greater flexibility and functionality, their programming complexity is high, requiring a high level of expertise from engineers. To meet the high security requirements of the system, engineers often prefer to write code manually to ensure reliability. However, this method is not only inefficient and time-consuming, but also prone to code quality issues due to human error, and lacks flexibility in the face of changing requirements. Template-based programming reduces programming difficulty and improves development efficiency through predefined code templates, but its template design often struggles to handle complex scenarios or personalized needs, and can easily lead to rigid code structures, limiting the system's adaptability and scalability. Therefore, neither manual nor template-based programming can reconcile complexity and security, necessitating more advanced programming methods to overcome these bottlenecks.

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

[0060] 3) Even after initial generation, the automated control code still requires repeated testing to ensure seamless integration with the hardware. During the control and optimization of electrical and mechanical components, parameters are often adjusted incrementally, and multiple tests are conducted to ensure optimal motion performance while eliminating potential safety hazards. This debugging process is time-consuming, tedious, and error-prone. However, the control code can only be implemented on physical equipment after debugging has ensured that the code parameters are safe and correct.

[0061] Therefore, current technologies in the field of automation control suffer from a series of problems, including poor flexibility, insufficient accuracy, and low efficiency. Overcoming these technical challenges has become a critical issue that urgently needs to be addressed in this field.

[0062] To address the aforementioned issues, this application attempts to intelligently generate automated control code by combining a large language model. Specifically, this application first obtains the natural language commands input by the user describing their control requirements. Then, it intelligently parses the user-input natural language commands and, based on the parsing results, searches a vector database to obtain similar code corresponding to the natural language commands—i.e., example code snippets—as well as complete information supporting the example code snippets through a knowledge graph database—i.e., API structured information, which may include API definitions, parameter explanations, calling constraints, and reference relationships in the documentation. Then, the large language model forms a global understanding of the control task corresponding to the natural language commands based on the example code snippets and API structured information, generating initial control code. Finally, this application performs multi-level code verification on the initial control code through a software motion control system and, combined with the multi-level verification results confirmed by the user multiple times, quickly generates highly reliable automated control code that meets the user's requirements.

[0063] Compared to existing technologies, this application can automatically generate and verify automated control code through a large language model, which not only improves code generation efficiency and reduces error rate, but also enhances code maintainability. Furthermore, by introducing multi-level virtual verification that combines user judgment and decision-making steps, this application effectively avoids the potential risks that full automation may cause, while enhancing user trust in the generated code and its execution effects, and ensuring the reliability and applicability of the final code. This addresses the shortcomings of existing technologies in guaranteeing generation speed and security, providing a more efficient and reliable method for generating automated control codes.

[0064] It should be noted that the execution entity in 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, or mobile phone, or an automated control code generation and verification device capable of performing the above functions. This embodiment does not specifically limit it in this way. The following uses an automated control code generation and verification device (hereinafter referred to as the generation and verification device) as the execution entity to describe this embodiment and the following embodiments.

[0065] Based on this, embodiments of this application provide an automated control code generation and verification method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the automated control code generation and verification method of this application.

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

[0067] Step S10: Receive 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;

[0068] It's important to understand that developers of existing automated control code spend an excessive amount of time on debugging, documentation review, and architecture design when manually generating code. Furthermore, templated code relies on fixed rules, making it difficult to handle complex scenarios (such as nested exception handling and multi-threaded collaboration). To effectively improve the efficiency of automated control code generation, this embodiment attempts to combine a large language model to achieve intelligent generation of automated control code through semantic understanding and knowledge reasoning, breaking through the boundaries of static rules. Therefore, the aforementioned natural language commands can be natural language formats input by the user into the large language model's dialogue interface, representing their automated control needs. After being input into the large language model, these commands can instruct the model to output code text that meets the corresponding control requirements of the natural language commands.

[0069] Therefore, in this embodiment, the natural language commands input by the user can be intelligently parsed using a large language model, and similar codes related to the control requirements corresponding to the natural language commands can be obtained based on the parsing results.

[0070] Step S20: Match and retrieve the vector database according to the natural language command to obtain example code snippets;

[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 processed. The example code in the motion API documents is divided into independent code fragments. Each code fragment can be extracted with a function description and code content and then stored in a vector database using vectorization technology to form a highly searchable semantic structure. Thus, in practical applications, code fragments related to natural language commands can be quickly retrieved according to user needs, thereby improving code fragment location efficiency and reducing search time, especially when processing a large number of code fragments.

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

[0073] Step A1: Perform semantic parsing on the code generation statements to obtain the main control task;

[0074] Step A2: Decompose the main control task to obtain several control sub-tasks;

[0075] Step A3: Perform a matching search on the vector database according to the control subtask to obtain example code snippets.

[0076] It is important to understand that, in order to quickly and accurately locate similar code related to control requirements corresponding to natural language commands, this embodiment can combine the natural language parsing capabilities of a large language model to perform semantic parsing on the code generation statements, obtain the corresponding main control task, and then automatically decompose the complex main control task into several logically clear sub-tasks; finally, based on each sub-task, it can accurately locate example code fragments related to the control requirements of natural language commands from the vector database, so as to improve the high flexibility and adaptability of the code generation method, and make the technical solution proposed in this embodiment applicable to complex scenarios with multi-module collaboration.

[0077] In one embodiment, suppose the received natural language command is: "Move axes 0 and 1 to positions 100 and 150 with a speed of 100 and an S-curve acceleration of 1000, and set the input signal I0.2 to 1, then perform spline interpolation on axes 2 and 3 to positions 200 and 300." In this embodiment, the user's natural language command can first be parsed using a large language model, and the main control task can be decomposed into the following three control sub-tasks: 1) Control axes 0 and 1 to move to the target positions with a speed of 100 and an S-curve acceleration of 1000; 2) Set the input signal I0.2 to 1; 3) Control axes 2 and 3 to perform spline interpolation on the target positions.

[0078] Then, in this embodiment, the code snippet with the highest semantic similarity to each subtask can be retrieved from the pre-built vector database, and the code C1, C2, C3, C4, C5, C6, etc. related to the above three control subtasks can be returned. At this time, the obtained code C1 to C6 together constitute the above example code snippet.

[0079] Step S30: Obtain the API structured information corresponding to the example code snippet from the knowledge graph database;

[0080] Step S40: Generate initial control code based on the example code snippet and the API structured information;

[0081] It should be noted that, unlike code generation in other scenarios, the parameter combinations in motion control code are extremely complex. Even small parameter changes can lead to drastic changes in motion control results. Therefore, after determining the example code snippet, the reasonable setting of function parameters in the example code snippet and the effective sorting and combination of the example code snippet are very complicated.

[0082] Therefore, in this embodiment, during the pre-parse of the motion API documentation for each motion control function, the system installation guide, programming tutorials, and API definitions, variables, function names, and function explanations are also compiled into a knowledge graph database for the large language model to learn from. For API parameters, such as acceleration / deceleration types, the definitions of these parameters are usually also present in the pre-stored motion API documentation, accompanied by complex graphical explanations. The knowledge graph database can establish reference relationships between these relevant sections and each API function. This database construction method allows users and the large language model to clearly understand the dependencies and referencing logic between APIs through the knowledge graph, especially in complex scenarios involving cross-references of multiple documents, thereby ensuring the safe and effective invocation of automated motion control.

[0083] Understandably, after obtaining the example code snippet from the vector database, this embodiment can also obtain its associated complete information support from the knowledge graph database, namely the aforementioned API structured information. This API structured information may include the API definition, parameter explanation, calling constraints, and reference relationships with other nodes in the document corresponding to the example code snippet, such as the definitions of various acceleration and deceleration types, overloaded versions of functions, and usage scenarios.

[0084] It is important to understand 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, whose attributes include the API definition, parameter type, function description, and calling constraints. Each code snippet of the example code in the vector database can be directly associated with its used API and related parameters as a node, thereby forming a complete call chain. This allows the large language model to perform joint retrieval between the two, enabling the rapid generation of initial control code.

[0085] In one embodiment, the steps of constructing the knowledge graph database may be: parsing the motion control API document into independent nodes, each node containing API definition, parameter type and calling constraints; establishing hierarchical relationships between API nodes, including overload version association, parameter dependency reference and example code call chain; and bidirectionally mapping the hierarchical relationships with semantic vectors in the vector database to form a joint retrieval index.

[0086] Therefore, this embodiment can connect different control nodes through a knowledge graph database. Based on the dynamic combination capabilities of the knowledge graph database, it supports the flexible assembly of complex functional modules, enabling the system to cope with diverse programming needs (such as cross-language and multi-platform compatibility) without requiring algorithm redesign for specific scenarios. Furthermore, unified knowledge graph specifications and verification standards can enforce best coding practices, ensuring project maintainability.

[0087] Understandably, after acquiring example code snippets and their corresponding API structure information, the large language model can form a global understanding of the aforementioned main control task based on this comprehensive information. This allows it to quickly generate more accurate and complete control code—the initial control code—and ensures that the logic and usability of the initial control code are far superior to traditional generation methods based on single similarity semantic lookups. Through this process, the large language model can fully understand the context and details of each control subtask, combining the example code from the vector database with the API node information from the knowledge graph database. This ensures that the generated initial control code not only includes the logical implementation of user requirements but also conforms to API rules and calling constraints.

[0088] In summary, this embodiment provides the system with powerful retrieval and structured analysis capabilities by combining a vector database and a knowledge graph database. The vector database handles efficient semantic queries, while the knowledge graph provides hierarchical logical dependency analysis, compensating for the shortcomings of semantic retrieval in complex scenarios. Particularly 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. Furthermore, this embodiment designs a dynamic update mechanism for both the vector database and the knowledge graph database, enabling continuous improvement as document content expands and user needs 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 target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code.

[0090] It is important to understand that, to ensure the reliability of the motion control code, this embodiment can perform multi-level virtual operation verification of the initial control code after it is automatically generated by the large language model, through a software-based motion control system. This software motion control system is pre-installed in the generation and verification equipment, converting a regular PC into a real-time system. It does not require a dedicated control chip but runs on the PC's general-purpose CPU. The software motion control system is highly modular, possesses powerful computing capabilities, and has high execution efficiency. It can seamlessly integrate with the AI's large language model to quickly run and verify the generated control code, and perform real-time process sampling and feedback of execution results, offering advantages that hardware controllers lack. Therefore, this embodiment can perform multi-level virtual operation verification through the software-based motion control system to detect whether the initial control code has logical conflicts, syntax errors, and security risks, thereby reducing code defects caused by human error and improving code reliability. Furthermore, the verification results at each level can be confirmed by the user. Finally, based on the multi-level verification results confirmed by the user and the initial control code, the final target control code that meets the user's control requirements is generated. This avoids the potential risks that may arise from full automation, enhances the user's trust in the generated code and its execution effect, and ensures the reliability and applicability of the final code.

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

[0092] Meanwhile, this embodiment pre-constructs a vector database and a knowledge graph database for complex API documents and code in the field of motion control. The vector database stores function definitions, parameter descriptions, and example code from the API documents using semantic vectorization, enabling efficient retrieval of code fragments semantically similar to user input commands. The knowledge graph database stores structured information about the API corresponding to each code fragment in the form of nodes and relationships, including function overload versions, parameter dependencies, calling constraints, and cross-document reference relationships.

[0093] Therefore, once 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 can be further analyzed using a knowledge graph database. This includes information such as parameter type definitions, function overload versions, and call dependencies. This allows the large language model to automatically generate initial control code based on the example code snippets and the API structured information. This automated code generation method, which provides both rapid retrieval and in-depth analysis of complex dependencies between APIs, not only supports comprehensive analysis of complex API scenarios but also provides more accurate contextual support for the large language model, thereby significantly improving the accuracy and logical consistency of the generated control code.

[0094] Finally, this embodiment combines the software motion control system to perform multi-level virtual operation verification of 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 intelligently generating automated control code based on a large language model, this embodiment can query example code snippets related to the user's input natural language command control requirements from a vector database, and retrieve nodes and relationships of all relevant motion control APIs from a knowledge graph database as references. Then, the large language model automatically generates the corresponding initial control code based on the user's natural language commands, the retrieved example code snippets, and the knowledge graph nodes and relationships. Finally, the initial control code undergoes multi-level verification through a software motion control system, and the results of multiple user confirmations are combined to quickly generate highly reliable automated control code that meets the user's needs. Compared to existing technologies, this embodiment can automatically generate and verify automated control code through a large language model, which not only improves code generation efficiency and reduces error rates, but also enhances the adaptability and maintainability of the code. Furthermore, by introducing multi-level virtual verification that combines user judgment and decision-making steps, this embodiment effectively avoids potential risks that may arise from full automation, enhances user trust in the generated code and its execution effects, and ensures the reliability and applicability of the final code. This addresses the shortcomings of existing technologies in terms of generation speed and security, providing a more efficient and reliable method for generating automated control codes.

[0096] This embodiment discloses an automated control code generation and verification method. The method includes: acquiring natural language commands; the natural language commands instructing a large language model to output code text that meets the control requirements corresponding to the natural language commands; performing semantic parsing on the code generation statements to obtain the main control task; decomposing the main control task to obtain several control sub-tasks; matching and retrieving example code snippets from a preset vector library based on the control sub-tasks; 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 target control code based on the multi-level verification results confirmed by the user and the initial control code. In the process of intelligently generating automated control code based on a large language model, this embodiment can query example code snippets related to the control requirements of the user-input natural language commands from the vector database, and search for nodes and relationships of all relevant motion control APIs of the example code snippets from the knowledge graph database as references. Then, the large language model automatically generates the corresponding initial control code based on the user's natural language commands, the queried example code snippets, and the knowledge graph node and relationship data. Finally, the initial control code is verified at multiple levels through a software motion control system. Combined with the results of these verifications (multiple confirmations by the user), highly reliable automated control code that meets user requirements is quickly generated. Compared to existing technologies, this embodiment can automatically generate and verify automated control code using a large language model, which not only improves code generation efficiency and reduces error rates but also enhances code adaptability and maintainability. Furthermore, by introducing multi-level virtual verification that incorporates user judgment and decision-making steps, this embodiment effectively avoids potential risks associated with full automation, enhances user trust in the generated code and its execution effects, and ensures the reliability and applicability of the final code. This addresses the shortcomings of existing technologies in guaranteeing generation speed and security, providing a more efficient and reliable method for generating automated control codes.

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

[0098] Reference Figure 2 , Figure 2 This is a flowchart illustrating the second embodiment of the automated control code generation and verification method of this 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: The initial control code is transmitted to the virtual motion engine for device simulation, the code execution result is obtained, and the code execution result is semantically matched with the natural language command to generate a first verification result;

[0100] It should be noted that, typically, control code needs to be actually run in a hardware motion controller to verify its effectiveness. This often requires significant time and hardware resources, and carries the risk of equipment damage or safety hazards during the debugging process. To ensure the security of the initial control code, this embodiment introduces a virtual motion engine, enabling the generated initial control code to run and be verified in a virtual environment. This 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 of the automated equipment under the action of the initial control code, that is, it performs the above-mentioned equipment simulation operation, and then records the code execution results corresponding to the equipment simulation operation, including key data such as the position, speed, and I / O feedback of the control axis.

[0102] Understandably, after obtaining the code execution result, the execution result can be compared with the user's original natural language command to perform preliminary code verification. Based on the virtual run comparison result corresponding to the preliminary verification, it can be determined whether the initial control code can be used as the target control code for the final execution. The comparison method can be to feed the execution result back to the large language model and perform semantic matching with the user's natural language command to obtain the current semantic matching degree, and then determine the first verification result based on the current semantic matching degree.

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

[0104] Step B11: When the semantic matching degree between the running result and the natural language command is lower than a preset matching threshold, the error correction process is triggered.

[0105] Step B12: Query the knowledge graph database based on the runtime 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;

[0106] Step B13: Generate a first correction control code based on the error API node information and the initial control code;

[0107] Step B14: Re-execute the first correction control code and update the first verification result.

[0108] Understandably, if the large language model finds a problem after comparing the code execution result with the natural language command, such as the code execution result not matching the target position required by the user (e.g., the target position is 300, but the actual result is 200), or the generated code has a syntax error, then the current semantic matching degree is lower than the preset matching degree. In this case, the first verification result corresponding to the virtual run comparison result can be that the large model verification has failed, and it can trigger an error correction process that combines the knowledge graph database to automatically correct the code.

[0109] At this point, the code snippets corresponding to the syntax errors or incorrect execution results identified from the virtual runtime comparison results can be determined first, i.e., the aforementioned runtime error information. Then, the runtime error information is fed back to the knowledge graph database to query relevant correction information, such as detailed API explanations, example error codes, the meaning of example error codes, and optimization suggestions for example error codes. This correction information is then passed to the large language model, allowing it to quickly correct the initial control code based on the error API node information and re-verify it based on the corrected first-correction control code. Through this feedback mechanism, this embodiment can dynamically correct and optimize initial control code that fails the virtual motion engine verification until the generated code can execute correctly and meet user needs, 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 drives the three-dimensional simulation model to display the device motion process corresponding to the initial control code, and generates a second verification result, so that the user can intuitively observe whether the device action corresponding to the initial control code in the three-dimensional simulation model meets 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 considered as the large model verification passing. After the user confirms that the running result of the virtual motion engine is correct, further simulation verification can be performed to improve the reliability of the code. At this time, this embodiment can also use the virtual motion engine to drive the three-dimensional simulation model corresponding to the automated equipment to display the equipment movement process corresponding to the initial control code, so that the user can intuitively observe whether the simulated running action of the automated equipment meets the expected control requirements through the three-dimensional simulation model and perform further simulation verification.

[0112] In one embodiment, this embodiment uses object mapping to map virtual control axes and I / O entities to virtual axes and virtual devices in a 3D simulation model, generating real-time 3D execution results that demonstrate the motion of the virtual axes and devices. For example, the axis numbers of the virtual motion engine can start from axis 100, axis 101, and axis 102, mapping to virtual axes in the 3D simulation model, allowing the virtual motion engine to control the corresponding 3D simulation model during runtime. Therefore, the 3D simulation model can reflect the effects of code execution in real time, including axis position, speed, and motion trajectory, presented through 3D visualization.

[0113] In one feasible implementation, in this embodiment, step B2 is followed by steps B21 to B22:

[0114] Step B21: In response to the user's interactive adjustment command on the 3D simulation model, update the natural language command;

[0115] Step B22: Regenerate the second correction control code based on the updated natural language command, and iteratively execute the multi-level virtual operation verification based on the second correction code.

[0116] It is easy to understand that when users intuitively observe the equipment's actions through the 3D simulation model and find that they do not meet the control requirements, the problems in the code can be quickly identified and interactive adjustment instructions can be fed back. These interactive adjustment instructions may contain instructions for adjustment or improvement. After the large language model analyzes the interactive adjustment instructions, it can trigger the optimization of the natural language instructions. Then, based on the optimized and updated natural language commands, a new second correction control code is generated. Finally, multi-level virtual operation verification is performed again based on the updated second correction code, thereby further improving the high reliability of the code generation process.

[0117] In this embodiment, object mapping technology combining a virtual motion engine and 3D simulation is used to dynamically visualize the motion process executed by the generated control code. This, combined with further simulation verification, allows users to intuitively observe whether the device's actions under the initial control code meet requirements through 3D simulation, thus verifying the correctness of the generated code in advance. This enables rapid identification and optimization of problems within the code. This dynamic visualization method significantly improves the transparency of the control code generation and verification process, allowing users to more efficiently adjust and optimize the generated code, thereby improving development efficiency and the accuracy of results.

[0118] Step B3: After the user confirms the second verification result, periodically collect motion process data of the virtual motion engine during operation, 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;

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

[0120] It is easy to understand that if the simulation results displayed by the 3D simulation model meet the user's control requirements, the generation and verification equipment can perform more refined process verification after the user confirms the second verification result. At this time, this embodiment can periodically sample 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 is running based on the initial control code. This motion process data is provided to the user to determine whether it meets the overall requirements. Then, by comparing the preset stage running data and the motion process data, the trajectory and endpoint of the code execution can be further verified to ensure they are consistent with expectations, generating a third verification result.

[0121] In one feasible implementation, 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: Within each verification interval, the user compares the real-time parameters with the expected values ​​for the corresponding stage to generate a third verification result.

[0124] It should be understood that, in order to perform detailed code execution comparison, this embodiment can divide the collected motion process data into multiple verification intervals according to time stages. Each verification interval can contain corresponding real-time motion parameters, and the real-time motion parameters are displayed to the user for comparison and verification according to different verification intervals. This allows the user to verify whether the trajectory and endpoint of the code execution are consistent with expectations based on these data. If there are problems, the natural language commands are corrected, and the generation and verification device can regenerate the control code and perform multi-level virtual operation verification again.

[0125] For example, within each verification interval, the user can compare the displayed real-time parameters with the expected values ​​for the corresponding stage, and generate a third verification result based on the comparison results. Understandably, if the user finds that the difference between the real-time parameters and the corresponding expected values ​​in any verification interval exceeds a safety threshold, it can be determined that the preset stage running data and the motion process data are inconsistent, the third verification result is a process verification failure, and a code iteration process based on the user's correction instructions is triggered; if the differences between the real-time parameters and the corresponding expected values ​​in all verification intervals meet the safety threshold, the third verification result is a process verification success.

[0126] At this point, the code iteration process described above can be as follows: trigger a user alert and pause subsequent code deployment, while waiting for the user to input adjusted and optimized natural language commands based on the third verification result. Then, the initial control code is further optimized based on these adjusted and optimized natural language commands until the optimized control code can pass the process data verification. This process verification method significantly improves the accuracy of problem diagnosis, enabling users to scientifically adjust control strategies, thereby effectively optimizing the code generation process. Simultaneously, this mechanism further enhances the transparency and interpretability of the code generation system.

[0127] Understandably, after the initial control code has undergone the above-mentioned large model verification, simulation verification, and process verification in sequence, and the verification results at each level have been 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 one feasible implementation, the software motion control system further includes a real-time motion engine; in this embodiment, after step S50, it further includes:

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

[0130] Step S70: The control code is sent to the real-time motion engine so that the real-time motion engine can perform periodic control on the automated equipment based on the target control code.

[0131] It is easy to understand that in this embodiment, after confirming that the control code generated by the large language model has passed the aforementioned large model verification, process verification, and simulation verification, the user can make an execution decision based on the target control code that has passed multi-level virtual operation verification. For ease of understanding, refer to... Figure 3 To illustrate, Figure 3 This is a structural control block diagram of the second embodiment of the automated control code generation and verification method of this application. Figure 3 As shown. After the initial control code passes multi-level verification, the user can decide whether to deploy the control code to the actual device.

[0132] Once the user inputs the execution decision to deploy, the target control code generated by MCCoder (Motion Control Coder, motion control programming device), which has passed multi-level verification and user confirmation, can be transferred from the software motion control system (such as...). Figure 3The virtual motion engine (Softmotion) is transferred to a real-time motion engine, which can also run on a dedicated CPU core. In this embodiment, target control code can be periodically sent to the real-time motion engine to enable the real-time motion engine to perform periodic control of the automated equipment based on the target control code.

[0133] It should be noted that before code transfer, this embodiment can synchronize the runtime environment configuration of the virtual motion engine to the real-time motion engine, thereby ensuring consistency between the virtual motion engine and the real-time motion engine. This ensures that the results of code execution in both are completely consistent at the logical level, thus ensuring that the simulation results generated by the virtual motion engine can be directly transferred to the actual equipment. This significantly reduces errors caused by inconsistencies between simulation and reality in traditional methods, ensures the reliability of control code from generation to deployment, and reduces the trial and error costs during deployment. It provides a solid guarantee for high-precision motion control tasks and reduces the equipment damage and personnel risks that may result from running erroneous code directly on automated equipment.

[0134] It's important to understand that in this embodiment, after successful configuration and synchronization, the axis numbers of the virtual motion engine and the real-time motion engine correspond one-to-one, and both engines can call the same motion control function library, ensuring consistency in their operating mechanisms and algorithms. Simultaneously, the axis numbers controlled by the real-time motion engine can start from axis 0, axis 1, axis 2, and axis 3, directly binding to the actual axes on the automated equipment. Therefore, when the real-time motion engine runs, the actual automated equipment executes immediately according to the control commands; when the virtual motion engine runs, it can manipulate the corresponding 3D simulation model. Especially in complex motion logic or high-risk scenarios, the simulation model visually demonstrates the motion effects, allowing users to identify potential problems before the code actually runs on the automated equipment. Finally, only after the virtual engine passes verification is the code handed over to the real-time motion engine for execution on the actual automated equipment. This mechanism ensures consistency between the virtual environment and the actual equipment operation while providing users with a safe and reliable code verification process, significantly reducing operational risks.

[0135] In this embodiment, multi-level verification through virtual motion engine verification, simulation verification, and process data verification, along with multiple iterative optimizations, significantly improves the reliability of the final target control code. Simultaneously, when all multi-level verifications pass, the iteratively optimized target control code can be transferred from the virtual motion engine to the real-time motion engine, and the automated equipment can be controlled through the output of periodic control commands. Since both the virtual motion engine and the real-time motion engine operate in a real-time environment, and the consistency of their operating mechanisms and execution results is strictly guaranteed at the underlying level, users can make judgments and decisions based on accurate and reliable feedback. Therefore, this embodiment reduces dependence on actual hardware, lowers the complexity and potential risks during the debugging process, and improves development efficiency.

[0136] Overall, this embodiment achieves precise control of automated equipment through automatic code generation, multiple verifications, and error correction, improving engineers' work efficiency, reducing error rates, and providing an innovative and comprehensive solution for highly secure and reliable automated control. Through this process, this embodiment realizes the automatic generation and execution of motion control code from natural language commands, lowering the technical threshold for users and enhancing the reliability and flexibility of the automated control code generation and verification method proposed in this embodiment.

[0137] Furthermore, this embodiment introduces user judgment and decision-making steps into key stages such as code generation, simulation verification, and execution decision-making, enabling users to monitor and intervene in the entire code generation and verification process in real time. This human-machine collaborative mechanism effectively avoids the potential risks that may arise from full automation, while enhancing users' trust in the generated code and its execution effects. In control scenarios with high security requirements, user participation not only improves system transparency but also ensures the reliability and applicability of the final code.

[0138] This embodiment discloses a process of transmitting initial control code to a virtual motion engine for device simulation, obtaining code execution results, semantically matching the execution results with natural language commands, and generating a first verification result. When the semantic matching degree between the execution result and the natural language commands is lower than a preset matching threshold, an error correction process is triggered. Error API node information is obtained by querying a knowledge graph database based on the error information. This error API node information includes, but is not limited to, API explanation information, example error codes, the meaning of the example error codes, and optimization suggestions for the example error codes. A first corrected control code is generated based on the error API node information and the initial control code. The first corrected control code is re-executed, and the first verification result is updated. After the user confirms the first verification result, the virtual motion engine drives a 3D simulation model to display the device motion process corresponding to the initial control code, generating a second verification result. This allows the user to visually observe whether the device actions corresponding to the initial control code in the 3D simulation model meet the control requirements. In response to the user's interactive adjustment commands to the 3D simulation model, the natural language commands are updated. The second corrected control code is regenerated based on the updated natural language commands, and multi-level virtual operation verification is iteratively executed based on the second corrected code. After the user confirms the second verification result, motion process data during the virtual motion engine's operation is periodically collected, and a third verification result is generated based on this data. The motion process data includes, but is not limited to, the position, speed, current feedback, and I / O status of the control axes. The motion process data is divided into multiple verification intervals according to preset time stages. Within each verification interval, the user compares the real-time parameters with the expected values ​​for the corresponding stage to generate the third verification result. After the user confirms the third verification result, the control code finally confirmed by the user is used as the target control code.

[0139] Furthermore, in this embodiment, the software motion control system also includes a real-time motion engine; in response to the user's execution decision, the runtime environment configuration of the virtual motion engine is synchronized to the real-time motion engine; after the configuration is synchronized, the axis numbers of the virtual motion engine and the real-time motion engine correspond one-to-one, and the virtual motion engine and the real-time motion engine use the same motion control function library; the control code is sent to the real-time motion engine so that the real-time motion engine can perform periodic control of the automated equipment based on the target control code.

[0140] This embodiment significantly improves the reliability of the final target control code through multi-level verification and iterative optimization, including virtual motion engine verification, simulation verification, and process data verification. Simultaneously, when all multi-level verifications pass, the target control code can be transferred from the virtual motion engine to the real-time motion engine, and the automated equipment can be controlled by the output of periodic control commands. Since both the virtual motion engine and the real-time motion engine run in a real-time environment, and the consistency of their operating mechanisms and execution results is strictly guaranteed at the underlying level, users can make judgments and decisions based on accurate and reliable feedback. Therefore, this embodiment reduces dependence on actual hardware, lowers the complexity and potential risks during the debugging process, and improves development efficiency.

[0141] For example, to help understand the technical concept or principle of the automated control code generation and verification method after combining this embodiment with the above-described Embodiments 1 and 2, please refer to Figure 4 , Figure 4 The following is a simplified flowchart of the automated control code generation and verification method of this application:

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

[0143] 2. User input of natural language commands: The user inputs natural language commands through the dialogue human-computer interface, and the system receives and performs semantic parsing on the instructions.

[0144] 3. Decompose the main task into sub-tasks: After the large language model performs semantic parsing of the natural language commands input by the user, the corresponding main control task is decomposed into multiple control sub-tasks for further processing.

[0145] 4. Search for subtask-related code in the vector database: Query code examples or modules related to controlling subtasks from the constructed vector database, i.e., sample code snippets for reference when generating code.

[0146] 5. Find API-related nodes and relationships in the knowledge graph database: Use the knowledge graph to extract the API nodes and their calling relationships corresponding to the example code snippets involved in the control subtasks, i.e., the API structured information, to support the overall and structured analysis of code generation.

[0147] 6. Large Language Model Generates Control Code: The large language model combines the user's input natural language commands, sample code snippets matched from the vector database, and API structured information found in the knowledge graph database to automatically generate initial control code.

[0148] 7. Virtual motion engine executes code: The generated initial control code is executed by the virtual motion engine to simulate the actions of automated equipment and record feedback information, i.e., the code execution result.

[0149] 8. Run 3D simulation: After the system maps virtual control axes and I / O entities to the virtual axes and virtual devices in the 3D simulation model generated after modeling the automated equipment through object mapping, it runs the 3D simulation model using the results of the virtual motion engine to intuitively display the equipment operation process and provide users with visual verification.

[0150] 9. Execution results are fed back to the large language model for comparison with the user's natural language commands: The execution results of the virtual motion engine running according to the initial control code are compared with the natural language commands entered by the user to verify whether the code execution results and syntax are correct.

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

[0152] 11. 3D simulation process monitoring is error-free (second simulation verification): The user monitors the equipment operation and key information in the 3D simulation model in real time to verify whether the motion behavior meets expectations; if there is a problem, the user puts forward a correction command, namely the above interactive adjustment instruction, to regenerate the second correction control code and verify it.

[0153] 12. Virtual motion engine sampling data is correct (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 values ​​with the expected values ​​to ensure that the data is correct; if there is a problem, the user needs to revise the instructions again.

[0154] 13. User makes execution decisions: The system presents the simulation results and sampled data to the user, who then makes the execution decision on whether to deploy the control code to the actual device.

[0155] 14. Real-time motion engine sends control commands to automated equipment: After user confirmation, the system sends control commands to automated equipment through the real-time motion engine to ensure that the actual equipment behavior is consistent with the simulation.

[0156] 15. End: Task completed, 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 automated control code generation and verification method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.

[0158] This application also provides an automated control code generation and verification device; please refer to... Figure 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 this application. In this embodiment, the automated control code generation and verification device includes:

[0159] Interaction module 501 is used to receive natural language commands; the natural language commands are used to instruct the large language model to output code text that meets the control requirements corresponding to the natural language commands;

[0160] The code location module 502 is used to match and retrieve the vector database according to the natural language command to obtain example code snippets;

[0161] The relationship acquisition module 503 is used to obtain the API structure information corresponding to the example code fragment from the knowledge graph database;

[0162] Code generation module 504 is used to generate initial control code based on the example code snippet and the API structured information;

[0163] The code execution module 505 is used to perform multi-level virtual operation verification of the initial control code in the software motion control system, and generate target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code.

[0164] As one possible implementation, in this embodiment, the code location module 502 is also used to perform semantic parsing on the code generation statement to obtain the main control task;

[0165] The code location module 502 is also used to decompose the main control task to obtain several control sub-tasks;

[0166] The code location module 502 is also used to perform matching and retrieval of the vector database according to the control subtask to obtain example code snippets.

[0167] As one possible implementation, 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 the code execution result, and perform semantic matching between the code execution result and the natural language command to generate a first verification result;

[0168] The code execution module 505 is also used to, 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 action corresponding to the initial control code in the three-dimensional simulation model meets the control requirements through the second verification result.

[0169] The code execution module 505 is also used to periodically collect motion process data of the virtual motion engine during operation 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 also used to take the control code finally confirmed by the user as the target control code after the user confirms the third verification result.

[0171] As one possible implementation, in this embodiment, the code execution module 505 is further configured to trigger an error correction process when the semantic matching degree between the running result and the natural language command is lower than a preset matching threshold.

[0172] The code execution module 505 is also used to query the knowledge graph database based on the runtime error information to obtain error API node information; the error API node information includes, but is not limited to, API explanation information, example error code, meaning of example error code, and optimization suggestions for example error code;

[0173] The code execution module 505 is also used to generate a first correction control code based on the error API node information and the initial control code;

[0174] The code execution module 505 is also used to re-execute the first correction control code and update the first verification result.

[0175] As one possible implementation, in this embodiment, the code execution module 505 is also used to update the natural language command in response to the user's interactive adjustment command on the three-dimensional simulation model;

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

[0177] As one possible implementation, in this embodiment, the code execution module 505 is further used to divide the motion process data into multiple verification intervals according to a preset time stage;

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

[0179] As one possible implementation, in this embodiment, the software motion control system further includes a real-time motion engine; the code execution module 505 is also used to synchronize the runtime environment configuration of the virtual motion engine to the real-time motion engine in response to the user's execution decision; after the configuration is synchronized, the axis numbers of the virtual motion engine and the real-time motion engine correspond one-to-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 that the real-time motion engine can perform periodic control on the automated equipment based on the target control code.

[0181] The automated control code generation and verification apparatus provided in this application, employing the automated control code generation and verification method described in the above embodiments, can solve the technical problem of automated control code generation. Compared with the prior art, the beneficial effects of the automated control code generation and verification apparatus provided in this application are the same as those of the automated control code generation and verification method provided in the above embodiments, and other technical features in the automated control code generation and verification apparatus are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.

[0182] This application provides an automated 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 to enable the at least one processor to execute the automated control code generation and verification method in the above embodiment;

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

[0184] The following is for reference. Figure 6 The diagram illustrates a structural schematic suitable for implementing the automated control code generation and verification device in the embodiments of this application. The automated control code generation and verification device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 6The automated control code generation and verification device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0185] like Figure 6 As shown, the automated control code generation and verification device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The random access memory 1004 also stores various programs and data required for the operation of the automated control code generation and verification device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; communication devices 1009; and software motion control systems 1010. Communication device 1009 allows the automation control code generation and verification device to communicate wirelessly or wiredly with other devices to exchange data. Software motion control system 1010 can convert a regular PC into a real-time system, requiring no dedicated control chip, but running on the PC's general-purpose CPU, where the virtual motion engine and real-time motion control engine run on dedicated CPU cores (Windows and other programs run on other CPU cores). Software motion control system 1010 is highly modular, has powerful computing capabilities, and high execution efficiency. It can seamlessly integrate with large AI language models to quickly run and verify its generated control code and perform real-time process sampling and feedback of execution results, possessing advantages that hardware controllers do not have. Although the diagram shows automated control code generation and verification equipment with various systems, it should be understood that implementation or having all of the systems shown is not required. More or fewer systems may be implemented alternatively.

[0186] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment disclosed in this application includes 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 containing 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 via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the automated control code generation and verification program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0187] The automated control code generation and verification device provided in this application, employing the automated control code generation and verification method described in the above embodiments, can solve the technical problem of automated control code generation. Compared with the prior art, the beneficial effects of the automated control code generation and verification device provided in this application are the same as those of the automated control code generation and verification method provided in the above embodiments, and other technical features of this automated control code generation and verification device are the same as those disclosed in the method of the previous embodiment, and will not be repeated here.

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

[0189] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

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

[0191] The storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of storage media may 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 thereof. In this embodiment, the storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0192] The aforementioned storage medium may be included in the automated control code generation and verification device; or it may exist independently and not be assembled into the automated control code generation and verification device.

[0193] The aforementioned storage medium carries one or more programs. When the aforementioned one or more programs are executed by the automated control code generation and verification device, the automated control code generation and verification device generates 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 a combination thereof. These programming languages ​​include object-oriented programming languages—such as Java, Python, and C++—as well as 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, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

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

[0196] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

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

[0198] The above are only some embodiments of this application and do not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A method for generating and verifying automated control codes, characterized in that, The method is applied to a large language model, and the method includes: Receive natural language commands; the natural language commands are used to instruct the large language model to output code text that meets the control requirements corresponding to the natural language commands; The vector database is matched and retrieved according to the natural language commands to obtain example code snippets; Obtain the API structure information corresponding to the example code snippet from the knowledge graph database; Initial control code is generated based on the example code snippet and the API structure information; The initial control code is verified through multi-level virtual operation in the software motion control system, and the target control code is generated based on the multi-level verification results confirmed by the user and the initial control code. The software motion control system includes a virtual motion engine; the step of performing multi-level virtual operation verification of the initial control code in the software motion control system, and generating target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code, includes: The initial control code is transmitted to the virtual motion engine for device simulation, the code execution result is obtained, and the code execution result is semantically matched with the natural language command to generate a first verification result. After the user confirms the first verification result, the virtual motion engine drives the three-dimensional simulation model 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 action corresponding to the initial control code in the three-dimensional simulation model meets the control requirements through the second verification result. After the user confirms the second verification result, motion process data of the virtual motion engine during operation is periodically collected, and a third verification result is generated 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; After the user confirms the third verification result, the control code finally confirmed by the user will be used as the target control code.

2. The automated control code generation and verification method as described in claim 1, characterized in that, The step of matching and retrieving the vector database according to the natural language command to obtain the example code snippet includes: Semantic parsing of the natural language commands yields the main control task; The main control task is decomposed to obtain several sub-control tasks; The vector database is matched and retrieved according to the control subtask to obtain example code snippets.

3. The automated control code generation and verification method as described in claim 1, characterized in that, The step of generating the first verification result includes: When the semantic matching degree between the code execution result and the natural language command is lower than a preset matching threshold, an error correction process is triggered; Based on the runtime error information, the knowledge graph database is queried to obtain error API node information; the error API node information includes, but is not limited to, API explanation information, example error code, meaning of example error code, and optimization suggestions for example error code. Generate a first correction control code based on the error API node information and the initial control code; Re-execute the first corrective control code and update the first verification result.

4. The automated control code generation and verification method as described in claim 1, characterized in that, After generating the second verification result, the process also includes: In response to the user's interactive adjustment instructions on the 3D simulation model, update the natural language commands; The second correction control code is regenerated based on the updated natural language command, and the multi-level virtual operation verification is iteratively executed based on the second correction code.

5. The automated control code generation and verification method as described in claim 1, characterized in that, The step of generating a third verification result based on the motion process data includes: The motion process data is divided 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 ​​for the corresponding stage to generate a third verification result.

6. The automated control code generation and verification method as described in claim 5, characterized in that, The software motion control system further includes a real-time motion engine; after performing multi-level virtual operation verification of the initial control code in the software motion control system, and generating target control code based on 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, the runtime environment configuration of the virtual motion engine is synchronized to the real-time motion engine; after the configuration is synchronized, the axis numbers of the virtual motion engine and the real-time motion engine correspond one-to-one, and the virtual motion engine and the real-time motion engine use the same motion control function library; The control code is sent to the real-time motion engine so that the real-time motion engine can perform periodic control of the automated equipment based on the target control code.

7. An automated control code generation and verification device, characterized in that, The automated control code generation and verification device includes: The interaction module is used to receive natural language commands; the natural language commands are used to instruct the large language model to output code text that meets the control requirements corresponding to the natural language commands. The code location module is used to match and retrieve sample code snippets from the vector database based on the natural language commands. The relationship acquisition module is used to obtain the API structure information corresponding to the example code snippet from the knowledge graph database; The code generation module is used to generate initial control code based on the example code snippet and the API structure information; The code execution module is used to perform multi-level virtual operation verification of the initial control code in the software motion control system, and generate target control code based on the multi-level verification results confirmed by the user multiple times and the initial control code; the software motion control system includes a virtual motion engine; The code execution module is further configured to transmit the initial control code to the virtual motion engine for device simulation, 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; after the user confirms the first verification result, the virtual motion engine drives a 3D simulation model 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 action corresponding to the initial control code in the 3D simulation model meets the control requirements through the second verification result; after the user confirms the second verification result, the motion process data of the virtual motion engine during operation is periodically collected, and a third verification result is generated 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; after the user confirms the third verification result, the control code finally confirmed by the user is used as the target control code.

8. An automated control code generation and verification device, characterized in that, The automated control code generation and verification device includes: a memory, a processor, and an automated control code generation and verification program stored in the memory and executable on the processor, wherein 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 in any one of claims 1 to 6; The device also includes a software motion control system, which includes a virtual motion engine and a real-time motion engine.

9. A storage medium, characterized in that, The storage medium is a computer storage medium, and the storage medium stores an automated control code generation and verification program. When the automated control code generation and verification program is executed by a processor, it implements the steps of the automated control code generation and verification method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Retrieval-enhanced structured code generation system and method

    CN116909574A

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

    CN119201059A