Multi-script execution method of virtual controller

By designing a unified intermediate execution structure of scripts and a unified interactive environment of models in the virtual controller, the programming and execution problems of various virtual controllers are solved, and the high reliability and low-cost use of the virtual production line are achieved.

CN119356817AActive Publication Date: 2025-01-24GUANGDONG UNIV OF TECH

Patent Information

Application Number
CN202411459142.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-01-24
Estimated Expiration
2044-10-18

AI Technical Summary

Technical Problem

The prior art is difficult to effectively support the programming and execution of multiple virtual controllers in the production line simulation platform, resulting in increased development workload and inconsistent script management.

Method used

提出一种虚拟控制器的多脚本执行方法,通过设定脚本结构、图模型结构和图节点结构,将脚本数据转换为有向无环图,并利用FIFO算法和点火规则进行脚本对象的调度和 Explain execution.

Benefits of technology

Improve the reliability of the virtual production line, reduce the cost of the platform, support the programming language of a variety of equipment controllers, adapt to the type of control script type, and improve the efficiency and optimization of resource use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119356817A_ABST
    Figure CN119356817A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of script execution, and provides a multi-script execution method for a virtual controller, and the method comprises the steps: setting a script structure, a graph model structure and a graph node structure; the method comprises the following steps: performing grammar and semantic check on script data to be executed, converting the script data into a script object according to a script structure, converting the script data into a directed acyclic graph according to a graph model structure, and traversing the directed acyclic graph to obtain an execution sequence of graphs in each level of the directed acyclic graph; and scheduling the script object according to an FIFO algorithm, traversing the directed acyclic graph during scheduling to obtain graph nodes in each execution sequence, and performing interpretive execution on the script object according to an ignition rule and the graph nodes in each execution sequence. The method aims at analyzing and executing various scripts, the reliability of the virtual production line is further improved, and the use cost of the platform is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of script execution, in particular to a multi-script execution method for a virtual controller. Background Art

[0002] Control scripts can be written in two ways: text and graphical. The programming languages ​​used are diverse, including general high-level languages ​​such as Java, C++, and C#, as well as languages ​​dedicated to physical device controllers and custom languages ​​for simulation platforms. Language diversity brings two challenges: first, users need to master different programming languages, which increases learning costs; second, the selected language must meet the specific requirements of the model because different languages ​​differ in function and applicability.

[0003] For production line simulation platforms, it is particularly important to speed up the process of building virtual production lines while simulating real production lines as much as possible. This is especially important for companies that frequently change production lines. However, there are multiple controllers in real production lines that need to execute different control programs. If the simulation platform also needs to support multiple virtual controllers, it will inevitably increase the development workload and is not conducive to the unified management of scripts.

[0004] Therefore, it is particularly necessary to study general virtual controller technology and design a unified intermediate execution structure of scripts and a unified interactive environment of models in virtual controllers. Summary of the invention

[0005] In view of the above-mentioned defects, the purpose of the present invention is to propose a multi-script execution method for a virtual controller, aiming to parse and execute multiple scripts, further improve the reliability of the virtual production line and reduce the cost of using the platform.

[0006] To achieve this object, the present invention adopts the following technical solutions:

[0007] A multi-script execution method for a virtual controller, the multi-script execution method comprising:

[0008] Set the script structure, graph model structure and graph node structure, where the graph model structure includes a main graph and several levels of sub-graphs, the main graph and sub-graphs include multiple graph nodes, each graph node structure includes information required for storing the corresponding script instruction interpretation and execution and the ignition rule for determining whether the graph node can be executed, and the script structure includes graph model structure information;

[0009] Performing a syntax and semantic check on the script data to be executed, converting the script data into a script object according to the script structure, converting the script data into a directed acyclic graph according to the graph model structure, and traversing the directed acyclic graph to obtain an execution sequence of the graph at each level of the directed acyclic graph;

[0010] The script objects are scheduled according to the FIFO algorithm. During scheduling, the directed acyclic graph is traversed to obtain the graph nodes in each execution sequence. The script objects are interpreted and executed according to the ignition rules and the graph nodes in each execution sequence.

[0011] Preferably, the directed acyclic graph is stored in a cross linked list method, and the graphs at any level in the directed acyclic graph satisfy the relationship:

[0012] g=<id,N,E,ES,ptr> ;

[0013] Where g represents a graph of any level in a directed acyclic graph, id represents a graph identifier, N represents a graph node set, E represents a connection edge set, ES represents an execution sequence of the graph, and ptr represents an execution pointer;

[0014] A basic node N' in the graph node set N satisfies the relationship:

[0015] N′= <id′,e fi ,e fo ,ib,ir,d,eb,init,res>;

[0016] Among them, id′ represents the graph node identifier, e fi represents the first incoming edge, e fo represents the first outgoing edge, ib represents the ignition variable, ir represents the ignition rule, d represents the execution data, eb represents the execution behavior, init represents the initialization behavior, res represents the reset behavior, and the first incoming edge e fi and the first outgoing edge e fo It is the way to define graph nodes in the cross-linked list method;

[0017] A connecting edge E′ in the connecting edge set E satisfies the relationship:

[0018] E′= <n t ,n h ,e nt ,e nh ,bti>;

[0019] Among them, n t Represents the tail graph node connected by the edge, n h The graph node representing the head to which the edge connects, e nt Indicates the next connecting edge with the same tail node, e nh Indicates the next connecting edge with the same head node, bti indicates breadth timing information;

[0020] The graph node set N also includes control nodes N″;

[0021] The control node N″ is extended from the basic node N′ and includes:

[0022] The execution data d in the control node N″ is composed of the control condition set CS and the graph set G cn (G cn ∈G), the execution behavior eb in the control node N″ is set as the control rule cr of the node.

[0023] Furthermore, the execution order relationship of the directed acyclic graph in different dimensions includes a breadth time series relationship and a depth time series relationship;

[0024] The breadth-time relationship between the subgraphs is represented by the subgraphs in the graph set G cn The order in which the control conditions in the control condition set CS are related to G cn The subgraph in corresponds to;

[0025] The ignition rule is configured such that if the ignition variables iv of the predecessor nodes are all true, the ignition variable iv of the current node is set to true, the processing function of the current node is activated, and the data of the current node is processed; if the ignition variables iv of the predecessor nodes are not all true, the ignition variable iv of the current node is set to false, the processing function of the current node is not activated, and the data of the current node cannot be processed.

[0026] Preferably, the script structure is represented by a quintuple and satisfies the relationship:

[0027] Script=<sn,SI,EB,VAR,G> ;

[0028] Among them, Script represents the script object, sn represents the script name, SI represents the script interpretation and execution status identification set, EB represents the script execution set before and after execution, VAR represents the set of all variables with the script scope, and G represents all graphs of the graph model after the control script conversion;

[0029] The script interpretation execution state identification set SI is represented by a four-tuple and satisfies the relationship:

[0030] SI=<st,df,ce,db> ;

[0031] Among them, st indicates the script status, df indicates whether the script is executed by default when the execution engine is started, ce indicates single execution or loop execution, and db indicates whether the script is in debugging state;

[0032] The script is executed as a set EB before and after execution, which is represented by a four-tuple and satisfies the relationship:

[0033] EB=<init,res′,br,ar> ;

[0034] Among them, init means initializing the configuration, graph, variables and other factors of the script, res′ means resetting the configuration, graph, variables and other factors of the script to the default, br means the behavior before execution, and ar means the behavior after execution.

[0035] Furthermore, a basic queue Q and a buffer queue BQ are set, wherein the basic queue Q is used to store all script objects to be scheduled, and the buffer queue BQ is used to record all script objects that need to be scheduled in the next cycle;

[0036] The scheduling of script objects according to the FIFO algorithm includes:

[0037] Step A: insert the script object whose script status st is READY to the end of the basic queue Q, and take the script object from the head of the basic queue Q as the current script object;

[0038] Step B: If the script state st of the current script object is READY, then the preset pre-execution behavior br is executed; otherwise, the preset pre-execution behavior br is abandoned;

[0039] Step C: interpret and execute the script object, and execute the preset post-execution behavior ar;

[0040] Step D: If the ce value of the script object is loop execution, the script state st of the current script object becomes READY, and the current script object is inserted into the buffer queue BQ; if the ce value of the script object is single execution, the next script object is used as the current script object;

[0041] Loop through steps AD. If there is no script object in the basic queue Q, stop looping through steps AD and swap the basic queue Q with the buffer queue BQ. If the total time consumed to schedule the script object is greater than the preset execution cycle, directly proceed to the script object scheduling for the next cycle. Otherwise, enter a dormant state. When the total time consumed plus the dormant time equals the preset execution cycle, proceed to the script object scheduling for the next cycle.

[0042] Further, a stack S′ is set, and the execution sequence of traversing the directed acyclic graph to obtain a graph in each level of the directed acyclic graph includes:

[0043] Get the first level graph in the directed acyclic graph as the current level graph g′;

[0044] Step K: Get the graph node n with in-degree 0 in the current level graph g′ start , and insert it into the stack S′;

[0045] Step L: Loop out the graph node at the top of the stack S′ and traverse all the direct successor nodes n of the graph node in reverse order according to the breadth-time relationship btih , insert n into the top of stack S′ h , until the stack S′ is empty;

[0046] Step M: Obtain the next level graph in the directed acyclic graph as the current level graph g′;

[0047] Step KM is repeated until all graph nodes in the directed acyclic graph are traversed to obtain the execution sequence of the graph in each level of the directed acyclic graph.

[0048] Preferably, a stack S is set, and a main graph of the directed acyclic graph is stored in the stack S;

[0049] The interpreting and executing the script object according to the ignition rules and the graph nodes in each execution sequence includes:

[0050] Step E: Set the top element of the stack S as the to-be-executed graph cg, and obtain the corresponding graph node n in the execution sequence of the to-be-executed graph cg in sequence according to the execution pointer ptr;

[0051] Step F: Determine whether the graph node n is executed by the ignition rule. When the graph node n needs to be executed and is a control node, after executing the execution behavior eb of the graph node n, insert the subgraph of the graph node n into the stack S to execute the execution behavior eb of the subgraph;

[0052] Step G: If the execution pointer ptr is empty, the execution graph cg is executed, the execution pointer ptr is reset and the top element of the stack S is popped out;

[0053] Repeat steps E, F, and G until stack S is empty.

[0054] Furthermore, the top element of the current stack S is used as the head of the queue and the target graph node of the jump is used as the tail of the queue, and a plurality of graph nodes and a plurality of levels of graphs are arranged in an interval manner as a jump path queue PQ;

[0055] The execution behavior eb includes the jump of graph node n, including:

[0056] Step X: Take element A′ from the head of the jump path queue PQ;

[0057] Step Y: If element A′ is a graph node, point the execution pointer ptr to element A′, and when element A′ is a control node, execute the reset behavior res of element A′, and then read element B′ from the head of jump path queue PQ. If element A′ is a control node connected to element B′, take element B′ out of jump path queue PQ and insert it into the top of stack S.

[0058] If element A′ is the to-be-executed graph cg in the stack S, read element C′ from the head of the jump path queue PQ. If element C′ is a control node connected to element A′, execute the reset behavior res of element A′ and jump the to-be-executed graph cg in the stack S to the upper level.

[0059] Repeat steps X and Y until all elements of the jump path queue PQ are taken out.

[0060] Preferably, the instruction tree tn is set to satisfy the relationship: tn=<id,t,Data,TN> ;

[0061] Wherein, id represents the unique identifier of the node, t is used to determine the instruction type, Data represents the execution data according to the individual design of each instruction, and TN is used to store all direct child nodes tn of the node in the instruction tree;

[0062] Converting script data into a directed acyclic graph according to the graph model structure includes:

[0063] Store the script data in the root node tn of the instruction tree tn root In the example, the root node tn root Insert into instruction tree node stack S tn In the example above, create the main graph of the directed acyclic graph and insert it into the graph stack S g Among them, S tn and S g The elements in the table correspond to each other;

[0064] Get S tn The top element of the stack tn 1 and S g The top element of the stack is g 1 , for tn 1 All child nodes of tn cur Execute step HI:

[0065] Step H: According to tn 1 Each child node tn cur The information creates the corresponding graph node n new , n new Join g 1 middle;

[0066] Step I: Build g 1 The second to last graph node in the new The connecting edges between

[0067] Step J: If graph node n new For While type, graph node n new Convert to a control node and create a new subgraph g 2 Insert into the graph set G, if the graph node nnew If type, the graph node n new Transform into a control node, create a new subgraph for all its child nodes and insert it into the graph set G;

[0068] When S tn When it is empty, the conversion is completed, and the graph set G is the converted directed acyclic graph.

[0069] Preferably, when interpreting and executing the script object, a script debugger is also included to debug the script object:

[0070] When the script's debug flag is true, the script debugger gets the script object;

[0071] Script debugger steps through graph nodes in a directed acyclic graph;

[0072] When the debugging flag of the script is false, the script object is restored to be interpreted and executed, and the script debugger stops executing the graph nodes in the directed acyclic graph.

[0073] One of the above technical solutions has the following advantages or beneficial effects:

[0074] The present invention determines the existing form of the script after conversion by setting the script structure, graph model structure and graph node structure, and provides the basic implementation of scripts, graphs and graph nodes; by performing grammatical semantic checks on the script data to be executed, ensuring that the input script conforms to the lexical and grammatical properties of the script language, and converting the script data into a directed acyclic graph, the dependency relationship and execution order in the script can be clearly expressed, making the processing of complex control logic intuitive and easy to understand, and can support the programming languages ​​of multiple device controllers, adapt to multiple control script types, improve the compatibility and scalability of the platform, traverse the directed acyclic graph to obtain the execution sequence of each level, and can conveniently execute the script in the order of execution, thereby improving the execution efficiency; the FIFO scheduling algorithm can ensure that the script objects are processed in the order of first-come-first-executed, avoiding resource competition and conflicts caused by concurrent execution; by using the ignition rule in the scheduling process, the graph nodes in each execution sequence are interpreted and executed, which can effectively improve the execution efficiency. When executing the script, it can ensure that all dependent nodes have been executed before being called, avoiding errors caused by missing dependencies, and the ignition rule can ensure that the execution of the node is triggered only when the conditions are met, thereby optimizing the use of resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0075] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0076] Figure 1 is a flow chart of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0077] Figure 2 is a first example diagram of the breadth-time relationship of the multi-script execution method of the virtual controller provided by an embodiment of the present invention;

[0078] Figure 3 It is a schematic diagram of a time-sequential multi-level directed acyclic graph structure of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0079] Figure 4 is a second example diagram of the breadth-time relationship of the multi-script execution method of the virtual controller provided by an embodiment of the present invention;

[0080] Figure 5 is an example diagram of the deep timing relationship of the multi-script execution method of the virtual controller provided by an embodiment of the present invention;

[0081] Figure 6 1 is an example diagram of timing relationship conflicts in different dimensions of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0082] Figure 7 It is a flow chart of data flow ignition judgment of a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0083] Figure 8 It is a script scheduling process of a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0084] Fig. 9 It is a first example diagram of a time-series-based depth-first topological sorting algorithm of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0085] Fig.10 It is a second example diagram of a time-series-based depth-first topological sorting algorithm of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0086] Fig.11 It is a schematic diagram of connection edge elements of a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0087] Fig.12 It is a flowchart of script interpretation and execution of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0088] Fig.13 It is a script data structure hierarchical relationship diagram of a multi-script execution method for a virtual controller provided by an embodiment of the present invention;

[0089] Fig.14 It is a jump mechanism flow chart of a directed acyclic graph of a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0090] Fig.15 It is a pseudo code schematic diagram of a jump path search algorithm based on multi-tree post-order traversal of a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0091] Fig.16 It is a flow chart of constructing PDAG based on instruction tree of a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0092] Fig.17 It is a flow chart of converting a robot script to PDAG in a multi-script execution method of a virtual controller provided by an embodiment of the present invention;

[0093] Fig.18 It is a schematic diagram of the listener mode of the multi-script execution method of the virtual controller provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0094] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.

[0095] In the description of the present invention, it is to be understood that the terms “center”, “longitudinal”, “lateral”, “length”, “width”, “thickness”, “up”, “down”, “left”, “right”, “vertical”, “horizontal”, “top”, “bottom”, “inside”, “outside”, “axial”, “radial”, “circumferential”, etc., indicating orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present invention.

[0096] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "plurality" means two or more.

[0097] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a direct connection, or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0098] Control scripts can be written in two ways: text and graphical. The programming languages ​​used are diverse, including general high-level languages ​​such as Java, C++, and C#, as well as languages ​​dedicated to physical device controllers and custom languages ​​for simulation platforms. Language diversity brings two challenges: first, users need to master different programming languages, which increases learning costs; second, the selected language must meet the specific requirements of the model because different languages ​​differ in function and applicability.

[0099] For production line simulation platforms, it is particularly important to speed up the process of building virtual production lines while simulating real production lines as much as possible. This is especially important for companies that frequently change production lines. However, there are multiple controllers in real production lines that need to execute different control programs. If the simulation platform also needs to support multiple virtual controllers, it will inevitably increase the development workload and is not conducive to the unified management of scripts.

[0100] The present invention provides a multi-script execution method for a virtual controller, the multi-script execution method comprising the steps of:

[0101] S1: Set the script structure, graph model structure and graph node structure, wherein the graph model structure includes a main graph and several levels of subgraphs, the main graph and the subgraphs include multiple graph nodes, each graph node structure includes the data and behavior required for storing the corresponding script instructions when interpreting and executing, and the ignition rules for judging whether the graph node can be executed, and the script structure includes graph model structure information;

[0102] S2: Performing a syntax and semantic check on the script data to be executed, converting the script data into a script object according to the script structure, converting the script data into a directed acyclic graph according to the graph model structure, and traversing the directed acyclic graph to obtain an execution sequence of the graph in each level of the directed acyclic graph;

[0103] S3: Schedule the script objects according to the FIFO algorithm. During scheduling, the directed acyclic graph is traversed to obtain the graph nodes in each execution sequence. The script objects are interpreted and executed according to the ignition rules and the graph nodes in each execution sequence.

[0104] Among them, the virtual controller is generally a system composed of multiple modules. The virtual controller system is both a script execution engine that supports script parsing and execution and a device controller that can interact with the digital twin model. In addition, it also needs to support the writing of control scripts. In the production line of an actual factory, it is often necessary to use multiple languages ​​to write equipment control programs. The simulation platform should also be able to support the writing and execution of multiple control scripts. In order to achieve this goal, the virtual controller needs to be able to parse and execute multiple scripts. The multi-script execution method of a virtual controller proposed in the present invention can solve the above problems.

[0105] Specifically, in step S1, the script structure includes basic grammatical elements, such as data types (such as integers and strings), control flows (such as conditional statements and loops), function calls, etc. The script structure is set to provide a standardized format so that all scripts follow the same rules, which helps to reduce errors caused by inconsistent formats during writing and execution. The definition of the graph model structure and the graph node structure makes the organization of scripts and data clearer. The graph model structure visualizes complex execution logic in the form of a graph (especially a directed acyclic graph, DAG), making different execution paths and logical relationships clearer, which helps to quickly find and manage subsequent operations. The graph model structure can It can clearly show the dependency between nodes. Based on the set graph structure, the scheduling algorithm (such as FIFO or priority scheduling) can more effectively manage the execution of the script and ensure that resources are reasonably allocated. The graph node is the basic unit in the execution process, which includes the specific implementation of the instruction, data storage and execution conditions. Each node not only stores the script instruction, but also contains the rules for judging whether the instruction can be executed. The ignition rules are usually some logical conditions or status checks, such as whether the variables are initialized, whether the preconditions are met, etc. This enables the execution process to be flexibly controlled to avoid erroneous execution. The relationship between the script structure, graph model structure and graph node structure designed in step S1 is shown in the figure. Fig.13 shown.

[0106] It is worth noting that when the script to be executed is input into the virtual controller, the script editor is used to limit user input to ensure that the script conforms to the lexical and partial syntax of the script language. However, for some syntax and semantics, the script data still needs to be checked as a whole to be judged. Therefore, in step S2, the script data to be executed needs to be checked for syntax and semantics. The syntax check ensures that the script conforms to the predetermined syntax rules. For example, if undefined variables or syntax errors appear in the script (such as missing semicolons, mismatched brackets, etc.), the parser will prompt an error and prevent further execution. The semantic check ensures the logical rationality of the script, including type checking (ensuring that the use of variables conforms to their types), scope checking (ensuring that variables are available in the appropriate scope), etc. The script data to be executed is converted into a script object according to the script structure set in step S1, that is, the script structure and the script data are in a one-to-one relationship. The script structure set in step S1 manages all the graphs formed after the script conversion and also manages the state of the script. Converting the script logic into a directed acyclic graph (PDAG) helps to represent the dependency relationship between execution nodes. Each node represents an execution unit, and the edge represents the execution order and dependency relationship, so as to adapt to the representation of data flow and control flow scripts at the same time. The converted directed acyclic graph (PDAG) is as follows: Figure 3 shown.

[0107] The FIFO (First In First Out) algorithm is a simple and efficient scheduling strategy. Script objects are placed in a queue in the order in which they arrive and are executed in sequence. The FIFO algorithm helps ensure the fairness of tasks and is simple and easy to implement. When a script is requested to be executed, the corresponding script object will be placed in a FIFO queue. The scheduler takes out the script objects in the queue in order for processing, ensuring that all script objects are scheduled in the order in which they are requested. The traversal starts from the starting node of the directed acyclic graph and tracks all reachable nodes in the graph. The depth-first search (DFS) or breadth-first search (BFS) algorithm can be used to traverse the directed acyclic graph to obtain all graph nodes. During the traversal process, the execution order of the nodes is recorded. Based on the dependency relationship of each graph node, a legal execution sequence is constructed to ensure that each node is executed only after all the nodes it depends on have been executed. The script objects are executed according to the execution sequence. When executing the graph nodes, if the ignition rule of the graph nodes is met, it means that the graph nodes are allowed to execute. Until all graph nodes are executed, it means that the script object has completed execution.

[0108] The present invention determines the existing form of the script after conversion by setting the script structure, graph model structure and graph node structure, and provides the basic implementation of scripts, graphs and graph nodes; by performing grammatical semantic checks on the script data to be executed, ensuring that the input script conforms to the lexical and grammatical properties of the script language, and converting the script data into a directed acyclic graph, the dependency relationship and execution order in the script can be clearly expressed, making the processing of complex control logic intuitive and easy to understand, and can support the programming languages ​​of multiple device controllers, adapt to multiple control script types, improve the compatibility and scalability of the platform, traverse the directed acyclic graph to obtain the execution sequence of each level, and can conveniently execute the script in the order of execution, thereby improving the execution efficiency; the FIFO scheduling algorithm can ensure that the script objects are processed in the order of first-come-first-executed, avoiding resource competition and conflicts caused by concurrent execution; by using the ignition rule in the scheduling process, the graph nodes in each execution sequence are interpreted and executed, which can effectively improve the execution efficiency. When executing the script, it can ensure that all dependent nodes have been executed before being called, avoiding errors caused by missing dependencies, and the ignition rule can ensure that the execution of the node is triggered only when the conditions are met, thereby optimizing the use of resources.

[0109] Preferably, the directed acyclic graph is stored in a cross linked list method, and the graphs at any level in the directed acyclic graph satisfy the relationship:

[0110] g=<id,N,E,ES,ptr> ;

[0111] Where g represents a graph of any level in a directed acyclic graph, id represents a graph identifier, N represents a graph node set, E represents a connection edge set, ES represents an execution sequence of the graph, and ptr represents an execution pointer;

[0112] A basic node B′ in the graph node set N satisfies the relationship:

[0113] N′= <id′,e fi ,e fo ,iv,ir,d,eb,init,res>;

[0114] Among them, id′ represents the graph node identifier, e fi represents the first incoming edge, e fo represents the first outgoing edge, iv represents the ignition variable, ir represents the ignition rule, d represents the execution data, eb represents the execution behavior, init represents the initialization behavior, res represents the reset behavior, and the first incoming edge e fi and the first outgoing edge e fo It is the way to define graph nodes in the cross-linked list method;

[0115] A connecting edge E′ in the connecting edge set E satisfies the relationship:

[0116] E′= <n t ,n h ,e nt ,e nh ,bti>;

[0117] Among them, n t Represents the tail graph node connected by the edge, n h The graph node representing the head to which the edge connects, e nt Indicates the next connecting edge with the same tail node, e nh Indicates the next connecting edge with the same head node, bti indicates breadth timing information;

[0118] The graph node set N also includes control nodes N″;

[0119] The control node N″ is extended from the basic node N′ and includes:

[0120] The execution data d in the control node N″ is composed of the control condition set CS and the graph set G cn (G cn ∈G), the execution behavior eb in the control node N″ is set as the control rule cr of the node.

[0121] Specifically, the cross linked list method is a way to store graphs, which uses two pointer sets to maintain the connections of incoming and outgoing edges respectively to support fast traversal. For any level of a directed acyclic graph, it can be described as a graph. The id is used to distinguish graphs of different levels to ensure that operations between different graphs are not confused; N represents the set of all nodes in the graph of this level, each node represents a state or operation, and the set of nodes is the core component of the graph, responsible for storing all data and logical structures of the graph. The connection edge set E defines the connection relationship between nodes, determines the data flow and operation order, and each edge connects two nodes, indicating that a node can pass information to another node or perform an operation; the execution sequence ES of the graph can ensure that the nodes are activated and processed in a specific order. What is important is that it can control the logical flow of task execution; the introduction of the execution pointer ptr allows the execution process of the graph to be efficient and sequential, and the movement of the pointer can guide the state change of the graph during execution.

[0122] In addition, the first incoming edge in the graph node points to the predecessor node of the node, and the first outgoing edge points to the successor node of the node. The ignition variable iv is a Boolean value. When it is true, it means that the node is ready to be executed. The ignition rule ir can be a conditional expression that controls when the node is triggered in the execution flow to ensure that the node will be processed only when specific conditions are met. The execution data d stores the core data that the graph node needs to process, which can be input parameters, status information or intermediate results, to ensure that the node has enough information to process during execution; the execution behavior eb describes the operation or logic that the graph node needs to perform when it is activated, which can include specific tasks such as calculation, data transmission, graph node jump or status update, and is a direct reflection of the node function.

[0123] The graph node n at the end connected by the edge E′ t It is the starting point of information transmission, indicating which node the data starts from. The head graph node connected by the connecting edge E′ is the node that receives the information and determines the final destination of the data. nt Points to the next edge with the same tail node as the current edge, which is used to implement traversal. In this way, all edges connected to the same tail node in the graph can be easily traversed; e nh Points to the next edge with the same head node as the current edge, supports traversal from the head node, and uses e nt and e nh , which can fully traverse all edges in the graph; bti records the time sequence information about the execution of nodes. The breadth timing information can help determine the execution dependencies between nodes to ensure that the graph follows the correct order when it is executed. The schematic diagram of the elements of the connecting edge is as follows Fig.11 shown.

[0124] The control node N″ is expanded and transformed from the basic node N′, where the execution data d is composed of the control condition set GS and the graph set G cn (G cn ∈G), the control condition set CS contains multiple condition sets that trigger execution behaviors, which are used to control the activation of nodes and ensure that the execution behaviors of nodes can be triggered under specific circumstances. cn It can be a graph of any level of a directed acyclic graph, through the graph set G cn The control and information flow across the graph can be realized; the execution behavior eb is set as the control rule cr of the node, which describes the rules that control how the node handles the execution flow according to the input conditions. The control rule determines the action that the node will take when it receives a specific input to enhance the decision-making ability and flexibility of the node.

[0125] The execution order relationship of the directed acyclic graph in different dimensions includes a breadth time sequence relationship and a depth time sequence relationship;

[0126] The breadth-time relationship between the subgraphs is represented by the subgraphs in the graph set G cn The order in which the control conditions in the control condition set CS are related to G cn The subgraph in corresponds to;

[0127] The ignition rule is configured such that if the ignition variables iv of the predecessor nodes are all true, the ignition variable iv of the current node is set to true, the processing function of the current node is activated, and the data of the current node is processed; if the ignition variables iv of the predecessor nodes are not all true, the ignition variable iv of the current node is set to false, the processing function of the current node is not activated, and the data of the current node cannot be processed.

[0128] Specifically, in a complex graph structure, a subgraph (or component) can represent a logical set of specific functions or tasks. cn is a graph set, containing multiple subgraphs. cn The control conditions in the control condition set CS correspond to these subgraphs, which can effectively manage and control the execution flow of the overall graph. Figure 3 It is a PDAG structure diagram with four layers of three-level subgraphs. In the diagram, the subgraphs of the next layer are linked by control nodes to form multiple layers, and then the depth time sequence relationship of the previous and next nodes is formed with the help of the node connection edges, and the breadth time sequence relationship is formed between all the outgoing edges of the nodes. In addition, the directed acyclic graph converted according to the graph model structure follows the following specifications: 1. Whether it is the main graph or the subgraph, there can only be one graph node with zero in-degree, that is, the script represented by the graph can only have one starting point, which is called the starting node n. start Among them, the in-degree refers to the number of in-edges of the graph node. If there is no in-edge, the in-degree is zero, such as Figure 3 A in the graph; 2. Whether it is the main graph or the subgraph, there can be multiple graph nodes with zero out-degree, that is, the script represented by the graph can have multiple endpoints, such as Figure 3 I and J nodes in the end ; 3. The breadth-time relationship represents the execution order relationship between the direct successor nodes of a node, such as Figure 2 As shown in , nodes B, C, and D are all direct successor nodes of node A, so there is a breadth-time relationship between the three. Since the ranking of node B is 1, node B is executed first among the three when interpreting and executing, and so on. Figure 4 The figure shows another situation. Node E has three direct predecessor nodes, so node E participates in three breadth timing relationships at the same time. 4. The depth timing relationship represents the execution order relationship between a node and its direct predecessor and successor nodes, such as Figure 5As shown in , node B is the successor node of node A, so node B should be executed after node A, and so on; 5. When the timing relationships of different dimensions conflict, the depth timing relationship shall prevail, such as Figure 6 As shown, there are both breadth and depth timing relationships between node C and node B. If node C is ranked higher in the breadth timing relationship, it will conflict with the depth timing relationship. At this time, the depth timing relationship shall prevail. It can be known that node C should be executed after nodes A and B. 6. The multi-level PDAG is realized by controlling the node to link subgraphs. If the control node links multiple subgraphs at the same time, there will also be a breadth timing relationship between the subgraphs. Different from the breadth timing relationship between ordinary nodes, the breadth timing relationship between subgraphs is only a reference. The execution order of the subgraphs and whether they are executed are determined by the control conditions and control rules of the control node. 7. PDAG is compatible with control flow based on data flow. Therefore, the execution process of graph nodes has the ignition link commonly seen in data flow. As shown in Figure 7 The figure shows the common data flow ignition process, where node B contains a processing function for processing data. The processing function will only work when the activation condition is met, and the activation condition needs to be comprehensively judged in combination with the data passed in by the predecessor nodes A and C. Since the activation condition directly determines whether the processing function is executed, the activation condition is also called the ignition rule ir. For the sake of universality, it is decided to set the Boolean ignition variable iv in the graph node. When iv is True, the ignition success node is executed. At the same time, the data transmitted between nodes is also set to iv, so what the ignition rule needs to do is to judge its own iv value based on the iv passed in by the predecessor node. The ignition rule ensures that the ignition variable of the current node will be set to true only when the ignition variables of all predecessor nodes are true, which means that the processing logic of the current node depends on the completion status of all its predecessor nodes, thereby establishing a strict dependency relationship. Once the ignition variable of the current node is set to true, the corresponding processing function will be called. If the ignition variable of any predecessor node is false, the ignition variable of the current node will be set to false, and the processing function of the node will not be activated, ensuring that the node is only processed under appropriate conditions, thereby maintaining the correctness and consistency of data processing.

[0129] The script structure is represented by a five-tuple and satisfies the relationship:

[0130] Script=<sn,SI,EB,VAR,G> ;

[0131] Among them, Script represents the script object, sn represents the script name, SI represents the script interpretation and execution status identification set, EB represents the script execution set before and after execution, VAR represents the set of all variables with the script scope, and G represents all graphs of the graph model after the control script conversion;

[0132] The script interpretation execution state identification set SI is represented by a four-tuple and satisfies the relationship:

[0133] SI=<st,df,ce,db> ;

[0134] Among them, st indicates the script status, df indicates whether the script is executed by default when the execution engine is started, ce indicates single execution or loop execution, and db indicates whether the script is in debugging state;

[0135] The script is executed as a set EB before and after execution, which is represented by a four-tuple and satisfies the relationship:

[0136] EB=<init,res′,br,ar> ;

[0137] Among them, init means initializing the configuration, graph, variables and other factors of the script, res′ means resetting the configuration, graph, variables and other factors of the script to the default, br means the behavior before execution, and ar means the behavior after execution.

[0138] Specifically, the script state st in the script interpretation execution state identification set SI can include states such as READY and Running, which can determine whether to implement the pre-execution behavior br and the post-execution behavior ar. ce can be a Boolean value, which determines whether the script is executed only once or cyclically. The cyclic execution is suitable for processing continuous tasks, such as real-time data monitoring; db can also be a Boolean value, indicating whether the script is running in debug mode, so that developers can track errors and check the execution process. Among them, the script is executed before and after the execution as a set EB, including initialization behavior init for factors such as the script configuration, graph and variables. It is executed before the script is executed and is responsible for configuring the environment, initializing variables and preparing the required resources. For example, reading configuration files, setting database connections, etc.; res′ is used to reset the script state and variables after the script is executed to ensure that the next execution will not be affected by the previous state; br represents specific operations that need to be performed before the script is executed, such as logging, allocating resources, etc., which are helpful for monitoring and managing the operation of the script; ar represents operations that need to be performed after the script is executed, such as releasing resources, updating status, recording results, etc., to ensure the stability and consistency of the system.

[0139] Set a basic queue Q and a buffer queue BQ, wherein the basic queue Q is used to store all script objects to be scheduled, and the buffer queue BQ is used to record all script objects that need to be scheduled in the next cycle;

[0140] The scheduling of script objects according to the FIFO algorithm includes:

[0141] Step A: insert the script object whose script status st is READY to the end of the basic queue Q, and take the script object from the head of the basic queue Q as the current script object;

[0142] Step B: If the script state st of the current script object is READY, then the preset pre-execution behavior br is executed; otherwise, the preset pre-execution behavior br is abandoned;

[0143] Step C: interpret and execute the script object, and execute the preset post-execution behavior ar;

[0144] Step D: If the ce value of the script object is loop execution, the script state st of the current script object becomes READY, and the current script object is inserted into the buffer queue BQ; if the ce value of the script object is single execution, the next script object is used as the current script object;

[0145] Loop through steps AD. If there is no script object in the basic queue Q, stop looping through steps AD and swap the basic queue Q with the buffer queue BQ. If the total time consumed to schedule the script object is greater than the preset execution cycle, directly proceed to the script object scheduling for the next cycle. Otherwise, enter a dormant state. When the total time consumed plus the dormant time equals the preset execution cycle, proceed to the script object scheduling for the next cycle.

[0146] Specifically, if Figure 8 As shown in the figure, the script scheduling process is performed. The buffer queue BQ is set based on the need for periodic execution. At the beginning of the scheduling process, all scripts in the READY state are inserted into the tail of the Q queue according to the script state st, and then the script objects Script are taken from the head of the queue for processing. Before processing, it is still necessary to judge st, st CSis the st of the current script. The Script in the READY state is the first execution, which means that the script is scheduled for the first time. Therefore, the preset pre-execution behavior (br) needs to be executed to ensure that each script can complete the necessary initialization operations when it is first executed. The Script in the RUNNING state is the resume execution, which means that the script has been executed in the previous cycle. The pre-execution behavior can be skipped directly to improve the execution efficiency. Then the common thing is the interpretation and execution of the Script. After the execution is completed, the preset post-execution behavior ar needs to be executed and the loop execution identifier ce needs to be used to determine whether the Script continues to execute or sleep. When there is no element in Q, it means that the round of execution is over. By setting a fixed execution cycle (such as 20ms), the script is managed. The scheduling and execution of the thread, taking the execution cycle of 20ms as the benchmark, calculates the difference between the total execution time and the thread sleep time. If the total execution time exceeds 20ms, it does not need to sleep and directly enters the next round of execution. It should be added that during the scheduling process, a dormant script may be activated. At this time, the script should be inserted into the end of the Q queue and st should be modified to READY. By calculating the total execution time and comparing it with the preset cycle, it is decided whether it needs to sleep and optimize the use of system resources. During the scheduling process, a dormant script may be activated by an external event. In this case, it is allowed to be inserted into the end of the queue and its status is updated to READY, which increases the flexibility of the system and enables the virtual controller to adapt to a dynamically changing environment.

[0147] Preferably, a stack st′ is set, and the execution sequence of traversing the directed acyclic graph to obtain a graph in each level of the directed acyclic graph includes:

[0148] Get the first level graph in the directed acyclic graph as the current level graph g′;

[0149] Step K: Get the graph node n with in-degree 0 in the current level graph g′ start , and insert it into the stack S′;

[0150] Step L: Loop out the graph node at the top of the stack S′ and traverse all the direct successor nodes n of the graph node in reverse order according to the breadth-time relationship bti h , insert n to the top of stack S′ h , until the stack S′ is empty;

[0151] Step M: Obtain the next level graph in the directed acyclic graph as the current level graph g′;

[0152] Step KM is repeated until all graph nodes in the directed acyclic graph are traversed to obtain the execution sequence of the graph in each level of the directed acyclic graph.

[0153] Specifically, in order to completely obtain the execution sequence of the graph in each level of the directed acyclic graph, the present invention uses a time-based depth-first topological sorting algorithm. First, the levels of the directed acyclic graph need to be traversed and the execution sequence of the graph of each layer is generated. Specifically, all dependencies between nodes at the same level of the execution sequence have been satisfied, and the nodes can be executed in parallel. The dependencies between the levels are ordered, that is, the nodes of the upper layer are executed first, and then the nodes of the lower layer are executed. First, we obtain the first level of the directed acyclic graph. The nodes in the first level are all graph nodes n with an in-degree of 0. start , an in-degree of 0 means that these nodes do not have any predecessor dependencies and can start execution directly. In step K, in the current level graph g′, find all nodes with an in-degree of 0. These nodes do not have any predecessor tasks and are the first nodes to be executed, so put them into the stack S′. In step L, the stack S′ is a last-in-first-out data structure, which means that the node at the top of the stack is the last node to be visited. Each time a graph node is popped from the top of the stack and its successor node is processed, so when it is necessary to traverse the successor node in reverse order, the execution of the successor node depends on the completion of the current node. Therefore, the direct successor node of the top node of the stack can only be processed after the graph node at the top of S′ is processed. The purpose of traversing the successor node in reverse order is to ensure that the successor node n h The execution order conforms to the topological order and satisfies the dependency relationship. Whenever we traverse a graph node, we will record it into the execution sequence and continue to push its successor nodes (in reverse order) into the stack one by one to ensure that they will be processed in the correct timing. Then, in step M, we continue to obtain the graph of the next level as the current level graph g′. By repeating step KM until all levels of nodes are processed, it is ensured that each layer of nodes in the graph is executed in topological order. In this algorithm, the topological order guarantees the dependency relationship. All predecessor nodes of each node (the nodes that depend on it) will be executed first before its successor nodes can be processed. The stack S′ ensures that the node we process each time is the current top-level node, and all its dependencies (predecessor nodes) have been processed. The execution sequence obtained according to this idea is correct. Therefore, the executed step KM is a depth-first topological sorting algorithm based on timing, and its implementation process is as follows: Fig. 9 and Fig.10 As shown, the stack structure and reverse order traversal mechanism are used to realize hierarchical traversal of the directed acyclic graph, and the execution sequence of each level can be output. It follows the basic principle of topological sorting to ensure that the execution order of tasks is consistent with the dependency relationship. The algorithm can be applied to actual scenarios such as task scheduling and course arrangement to ensure that each task is executed in a reasonable order.

[0154] Preferably, a stack S is set, and a main graph of the directed acyclic graph is stored in the stack S;

[0155] The interpreting and executing the script object according to the ignition rules and the graph nodes in each execution sequence includes:

[0156] Step E: Set the top element of the stack S as the to-be-executed graph cg, and obtain the corresponding graph node n in the execution sequence of the to-be-executed graph cg in sequence according to the execution pointer ptr;

[0157] Step F: Determine whether the graph node n is executed by the ignition rule. When the graph node n needs to be executed and is a control node, after executing the execution behavior eb of the graph node n, insert the subgraph of the graph node n into the stack S to execute the execution behavior eb of the subgraph;

[0158] Step G: If the execution pointer ptr is empty, the execution graph cg is executed, the execution pointer ptr is reset and the top element of the stack S is popped out;

[0159] Repeat steps E, F, and G until stack S is empty.

[0160] Specifically, if Fig.13 As shown, first create a stack S, store the main graph of the directed acyclic graph into the stack S, pop the top element from the stack S, and regard it as the graph cg to be executed, that is, the graph cg to be executed for the first time is the main graph of the directed acyclic graph. The execution sequence of the directed acyclic graph has been obtained in the previous step. The execution pointer ptr of the graph cg to be executed points to the first node in the graph to be executed. The execution pointer ptr obtains the graph nodes n of the execution sequence corresponding to the graph cg to be executed in turn, first executes the ignition rule ir of n, and then determines whether n is executed according to the ignition variable iv. When the graph node n needs to be executed, the execution behavior eb of the graph node n is implemented. At the same time, when the graph node n is a control node, the subgraph of the graph node n is inserted into the stack S to execute the execution behavior eb of the subgraph. After the current graph node n is executed, the execution pointer ptr is moved to the top of the stack S, and the executed graph is popped out. Repeat steps E, F, and G until the stack is empty, combined with Figure 8 It can be seen that the interpretation and execution of the script object is performed during the script scheduling to ensure the accuracy of the script execution.

[0161] Preferably, the top element of the current stack S is used as the head of the queue and the target graph node of the jump is used as the tail of the queue, and a plurality of graph nodes and a plurality of levels of graphs are arranged in an interval manner as the jump path queue PQ;

[0162] The execution behavior eb includes the jump of graph node n, including:

[0163] Step X: Take element A′ from the head of the jump path queue PQ;

[0164] Step Y: If element A′ is a graph node, point the execution pointer ptr to element A′, and when element A′ is a control node, execute the reset behavior res of element A′, and then read element B′ from the head of jump path queue PQ. If element A′ is a control node connected to element B′, take element B′ out of jump path queue PQ and insert it into the top of stack S.

[0165] If element A′ is the to-be-executed graph cg in the stack S, read element C′ from the head of the jump path queue PQ. If element C′ is a control node connected to element A′, execute the reset behavior res of element A′ and jump the to-be-executed graph cg in the stack S to the upper level.

[0166] Repeat steps X and Y until all elements of the jump path queue PQ are taken out.

[0167] During the execution of a graph node, the execution behavior eb may include a jump of the graph node. An example of a jump is Fig.14 As shown, specifically, in step X, element A' is taken out from the head of the jump path queue PQ. Extracting A' can obtain the currently executed graph node or control node for subsequent processing, ensuring that the elements in the queue are accessed and operated in a predetermined order. Determine whether A is a graph node or the graph cg at the top of the S stack. If A is a graph node, point the pointer ptr to A. If A is still a control node cn, its reset behavior function res needs to be called to eliminate the impact of cn not being called back. At the same time, read element B when the PQ element is not zero. At this time, if A is cn linked to B, it means that it is necessary to jump to the subgraph of cn. If A is the current graph cg, take element C from PQ. At this time, if C is cn linked to A, it means that it is necessary to jump to the upper level graph of graph cg. When the PQ element is zero, it means that the jump is completed and the script can continue to execute according to S.

[0168] In addition, the present invention also designs a jump path search algorithm based on multi-tree post-order traversal to obtain PQ, such as Fig.15 As shown, Fig.15The pseudo code diagram for the recursive implementation of the algorithm is shown in Figure 1. The input of the algorithm is the current node cur, the starting node start, the end node end, and the result queue RQ which is a global variable. The output, i.e. the return value, is the queue TQ. The queues AQ and BQ are defined as temporary variables. According to the idea of ​​post-order traversal, the algorithm will first classify and process all the child nodes under the cur node, and then process the cur node according to the situation that AQ and BQ are not empty. When AQ and BQ are not empty, it means that the path is found. In addition, the custom function forN is used to traverse the graph node set N. In the process, recur(n,start,end) is called recursively, and then The non-empty return value is assigned to the empty AQ or BQ; the equal function is used to determine whether cur is equal to start or end. If so, a queue is created and cur is inserted, and then the queue is returned; the forG function is similar to the forN function, but it traverses the graph set G; the merge function is used to merge AQ and BQ, and the elements of the queue that does not contain start are taken from the end of the queue and inserted into another queue in sequence. If there is no cur in the original queue, it needs to be inserted first; the insert function is used to determine whether AQ or BQ is not empty. If both are empty, nill is returned. If so, it is determined whether it contains cur. If not, cur is inserted, and then the queue TQ is returned.

[0169] Preferably, the instruction tree tn is set to satisfy the relationship: tn=<id,t,Data,TN> ;

[0170] Wherein, id represents the unique identifier of the node, t is used to determine the instruction type, Data represents the execution data according to the individual design of each instruction, and TN is used to store all direct child nodes tn of the node in the instruction tree;

[0171] Converting script data into a directed acyclic graph according to the graph model structure includes:

[0172] Store the script data in the root node tn of the instruction tree tn root In the example, the root node tn root Insert into instruction tree node stack S tn In the example above, create the main graph of the directed acyclic graph and insert it into the graph stack S g Among them, S tn and S g The elements in the table correspond to each other;

[0173] Get S tn The top element of the stack tn 1 and S g The top element of the stack is g 1 , for tn 1 All child nodes of tn cur Execute step HI:

[0174] Step H: According to tn1 Each child node tn cur Create the corresponding graph node n new , n new Join g 1 middle;

[0175] Step I: Build g 1 The second to last graph node in the new The connecting edges between

[0176] Step J: If graph node n new For While type, graph node n new Convert to a control node and create a new subgraph g 2 Insert into the graph set G, if the graph node n new If type, the graph node n new Transform into a control node, create a new subgraph for all its child nodes and insert it into the graph set G;

[0177] When S tn When it is empty, the conversion is completed, and the graph set G is the converted directed acyclic graph.

[0178] Specifically, taking the robot as an example, the program data of the robot script is obtained through the root node tn of the instruction tree. root Storage, script data conversion to PDAG requires processing of the instruction tree tn. The strategy for converting the instruction tree tn to PDAG is to perform a breadth traversal of the instruction tree tn, placing the sibling nodes in the same graph and the child nodes in the subgraph. The specific conversion process is as follows Fig.16 As shown, at the beginning of the process, tn root Insert into instruction tree node stack S tn , and create the main graph g of PDAG and insert it into the graph stack S g , where S tn and S g The elements in are corresponding, and then get S tn and S g The top element of the stack tn 1 and g 1 , for tn 1 All child nodes under tn are traversed. cur For example, at the beginning of the process, the corresponding graph node n is created according to its information new And join the graph g at the level where the node is located 1 , then establish g 1 The second to last graph node recorded with n new The connection edge between them, and then by judging the current instruction tree node element tn cur The type of classification process is to determine the insertion S tnand S g If the element is of While type, the graph node is first converted into a control node, and a new subgraph g is created. 2 Add to the graph collection, and finally when S tn When the element is empty, it means the conversion is finished and the graph set G representing PDAG is returned.

[0179] by Fig.17 For example, when S tn Popup root For tn 1 When TN 1 5, enter the process, connect PTP1 and WaitSignal in Figure g, tn cur If it is sequential execution, the processing ends directly, and if is tn cur When , connect if and PTP1 in Figure g, for tn cur The judgment is made as If type, the if node is converted into a control node, and the child nodes Then and Else of if are traversed. Each creates a new subgraph and adds it to the graph set G and the control condition of the control node. Then and Else are inserted into S tn At the top of the stack, the new subgraph is inserted into the graph stack S g , the processing is finished, continue to traverse the child nodes under the root node, and take Delay2 as tn cur When , connect Delay2 and if in graph g, judge the type as other processing ends, continue to traverse the child nodes under the root node, and take SetSignal as tn cur When , connect SetSignal and Delay2 in Figure g, and judge the type as other processing ends;

[0180] From S tn Pop up Else and assign it to tn 1 , for tn 1 Traverse the child nodes of Else, connect SetTool and PTP2 according to the graph level above, and when While is tn cur When connecting While and SetTool, judge tn cur The type is While type, convert the current graph node into a control node, create a new subgraph, add it to the graph set G and the control condition of the control node, and insert While into S tn At the top of the stack, the new subgraph is inserted into the graph stack S g .

[0181] From S tn Pop up While and assign it to tn 1 , for tn 1 The child nodes are traversed, and the child nodes judge tn curWhen the type is Other, connect Assign to Setbase to PTP3 at the While level.

[0182] From S tn Pop up Then and assign it to tn 1 , for tn 1 The child nodes are traversed, and the child nodes judge tn cur If the type is Other, connect Delay1 to LIN at the Then level, S tn The transformation ends when the element is empty, and the graph set G representing the PDAG is returned.

[0183] Preferably, when interpreting and executing the script object, a script debugger is also included to debug the script object:

[0184] When the script's debug flag is true, the script debugger gets the script object;

[0185] Script debugger steps through graph nodes in a directed acyclic graph;

[0186] When the debugging flag of the script is false, the script object is restored to be interpreted and executed, and the script debugger stops executing the graph nodes in the directed acyclic graph.

[0187] Specifically, the script debugging function allows the script writer to clearly understand the script execution process and effect, so as to optimize and modify the script content. The script debugger is a specific carrier that provides debugging functions, and its core is the script debugging mechanism. Since this article uses PDAG diagrams to represent scripts, it is relatively easy to implement script debugging. In the debugging mechanism, when the scheduling execution thread determines that the script's debugging flag db is true, it will pass the script to the script debugger. The script debugger will only execute the script step by step after receiving the execution instruction. Among them, the core of single-step execution is to execute the graph node n according to the stack S. When db is false, the debugger will return the script to the execution thread to continue to execute the subsequent content. At the same time, the interpreted execution of the script object can be regarded as an event source. For this purpose, the listener pattern is designed to be divided into three parts: event source, event, and event listener. When the event source changes, one or more types of events will be generated, and the event listener registers to listen to a certain type of specific event of the event source and responds to it. After the monitoring mechanism is established, the external program can monitor and respond to the status through the event listener. Specifically, Fig.18 shown.

[0188] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0189] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.

Claims

1. A multi-script execution method for a virtual controller, characterized in that: The multi-script execution method comprises: Set the script structure, graph model structure and graph node structure, where the graph model structure includes a main graph and several levels of sub-graphs, the main graph and sub-graphs include multiple graph nodes, each graph node structure includes information required for storing the corresponding script instruction interpretation and execution and the ignition rule for determining whether the graph node can be executed, and the script structure includes graph model structure information; Performing a syntax and semantic check on the script data to be executed, converting the script data into a script object according to the script structure, converting the script data into a directed acyclic graph according to the graph model structure, and traversing the directed acyclic graph to obtain an execution sequence of the graph at each level of the directed acyclic graph; The script objects are scheduled according to the FIFO algorithm. During scheduling, the directed acyclic graph is traversed to obtain the graph nodes in each execution sequence. The script objects are interpreted and executed according to the ignition rules and the graph nodes in each execution sequence.

2. The multi-script execution method according to claim 1, characterized in that: The directed acyclic graph is stored in a cross-linked list method, and the graphs at any level in the directed acyclic graph satisfy the relationship: g=<id,N,E,ES,ptr>; Where g represents a graph of any level in a directed acyclic graph, id represents a graph identifier, N represents a graph node set, E represents a connection edge set, ES represents an execution sequence of the graph, and ptr represents an execution pointer; A basic node N' in the graph node set N satisfies the relationship: N′=#id′,e fi ,and fo ,iv,ir,d,eb,init,res>; Among them, id′ represents the graph node identifier, e fi represents the first incoming edge, e fo represents the first outgoing edge, iv represents the ignition variable, ir represents the ignition rule, d represents the execution data, eb represents the execution behavior, init represents the initialization behavior, res represents the reset behavior, and the first incoming edge e fi and the first outgoing edge e fo It is the way to define graph nodes in the cross-linked list method; A connecting edge E′ in the connecting edge set E satisfies the relationship: E′=<n t ,n h ,e nt ,e nh ,bti>; Among them, n t Represents the tail graph node connected by the edge, n h The graph node representing the head to which the edge connects, e nt Indicates the next connecting edge with the same tail node, e nh Indicates the next connecting edge with the same head node, bti indicates breadth timing information; The graph node set N also includes control nodes N"; The control node N″ is extended from the basic node N′ and includes: The execution data d in the control node N″ is composed of the control condition set CS and the graph set G cn (G cn ∈G), the execution behavior in the control node N″ is set as the control rule cr of the node.

3. The multi-script execution method according to claim 2, characterized in that: The execution order relationship of the directed acyclic graph in different dimensions includes a breadth time sequence relationship and a depth time sequence relationship; The breadth-time relationship between the subgraphs is represented by the subgraphs in the graph set G cn The order in which the control conditions in the control condition set CS are related to G cn The subgraph in corresponds to; The ignition rule is configured such that if the ignition variables iv of the predecessor nodes are all true, the ignition variable iv of the current node is set to true, the processing function of the current node is activated, and the data of the current node is processed; if the ignition variables iv of the predecessor nodes are not all true, the ignition variable iv of the current node is set to false, the processing function of the current node is not activated, and the data of the current node cannot be processed.

4. The multi-script execution method according to claim 2, characterized in that: The script structure is represented by a five-tuple and satisfies the relationship: Script=<sn,SI,EB,VAR,G>; Among them, Script represents the script object, sn represents the script name, SI represents the script interpretation and execution status identification set, EB represents the script execution set before and after execution, VAR represents the set of all variables with the script scope, and G represents all graphs of the graph model after the control script conversion; The script interpretation execution state identification set SI is represented by a four-tuple and satisfies the relationship: SI = <st, df, ce, db>; Among them, st indicates the script status, df indicates whether the script is executed by default when the execution engine is started, ce indicates single execution or loop execution, and db indicates whether the script is in debugging state; The script is executed as a set EB before and after execution, which is represented by a four-tuple and satisfies the relationship: EB=<init, res′, br, ar>; Among them, init means initializing the configuration, graph, variables and other factors of the script, res′ means resetting the configuration, graph, variables and other factors of the script to the default, br means the behavior before execution, and ar means the behavior after execution.

5. The multi-script execution method according to claim 4, characterized in that: Set a basic queue Q and a buffer queue BQ, wherein the basic queue Q is used to store all script objects to be scheduled, and the buffer queue BQ is used to record all script objects that need to be scheduled in the next cycle; The scheduling of script objects according to the FIFO algorithm includes: Step A: insert the script object whose script status st is READY to the end of the basic queue Q, and take the script object from the head of the basic queue Q as the current script object; Step B: If the script state st of the current script object is READY, then the preset pre-execution behavior br is executed, otherwise the preset pre-execution behavior br is abandoned; Step C: interpret and execute the script object, and execute the preset post-execution behavior ar; Step D: If the ce value of the script object is loop execution, the script state st of the current script object becomes READY, and the current script object is inserted into the buffer queue BQ; if the ce value of the script object is single execution, the next script object is used as the current script object; Loop through steps AD. If there is no script object in the basic queue Q, stop looping through steps AD and swap the basic queue Q with the buffer queue BQ. If the total time consumed to schedule the script object is greater than the preset execution cycle, directly proceed to the script object scheduling for the next cycle. Otherwise, enter a dormant state. When the total time consumed plus the dormant time equals the preset execution cycle, proceed to the script object scheduling for the next cycle.

6. The multi-script execution method according to claim 5, characterized in that: A stack S′ is set, and the execution sequence of traversing the directed acyclic graph to obtain a graph in each level of the directed acyclic graph includes: Get the first level graph in the directed acyclic graph as the current level graph g′; Step K: Get the graph node n with in-degree 0 in the current level graph g′ start , and insert it into the stack S′; Step L: Loop out the graph node at the top of the stack S′ and traverse all the direct successor nodes n of the graph node in reverse order according to the breadth-time relationship bti h , insert n into the top of stack S′ h , until the stack S′ is empty; Step M: Obtain the next level graph in the directed acyclic graph as the current level graph g′; Step KM is repeated until all graph nodes in the directed acyclic graph are traversed to obtain the execution sequence of the graph in each level of the directed acyclic graph.

7. The multi-script execution method according to claim 6, characterized in that: Set a stack S, and store the main graph of the directed acyclic graph into the stack S; The interpreting and executing of the script object according to the ignition rules and the graph nodes in each execution sequence includes: Step E: Set the top element of the stack S as the to-be-executed graph cg, and obtain the corresponding graph node n in the execution sequence of the to-be-executed graph cg in sequence according to the execution pointer ptr; Step F: Determine whether the graph node n is executed by the ignition rule. When the graph node n needs to be executed and is a control node, insert the subgraph of the graph node n into the stack S after executing the execution behavior of the graph node n to execute the execution behavior eb of the subgraph; Step G: If the execution pointer ptr is empty, the execution graph cg is executed, the execution pointer ptr is reset and the top element of the stack S is popped out; Repeat steps E, F, and G until stack S is empty.

8. The multi-script execution method according to claim 7, characterized in that: The top element of the current stack S is used as the head of the queue and the target graph node of the jump is used as the tail of the queue. Several graph nodes and several levels of graphs are arranged in intervals as the jump path queue PQ. The execution behavior includes the jump of graph node n, including: Step X: Take element A′ from the head of the jump path queue PQ; Step Y: If element A′ is a graph node, point the execution pointer ptr to element A′, and when element A′ is a control node, execute the reset behavior res of element A′, and then read element B′ from the head of jump path queue PQ. If element A′ is a control node connected to element B′, take element B′ out of jump path queue PQ and insert it into the top of stack S. If element A′ is the to-be-executed graph cg in the stack S, read element C′ from the head of the jump path queue PQ. If element C′ is a control node connected to element A′, execute the reset behavior res of element A′ and jump the to-be-executed graph cg in the stack S to the upper level. Repeat steps X and Y until all elements of the jump path queue PQ are taken out.

9. The multi-script execution method according to claim 1, characterized in that: Set the instruction tree tn to satisfy the relationship: tn =<id,t,Data,TN> ; Wherein, id represents the unique identifier of the node, t is used to determine the instruction type, Data represents the execution data according to the individual design of each instruction, and TN is used to store all direct child nodes tn of the node in the instruction tree; Converting script data into a directed acyclic graph according to the graph model structure includes: Store the script data in the root node tn of the instruction tree tn root In the example, the root node tn root Insert into instruction tree node stack S tn In the example above, create the main graph of the directed acyclic graph and insert it into the graph stack S g Among them, S tn and S g The elements in the table correspond to each other; Get S tn The top elements of the stack tn1 and S g The top element g1 of the stack, for all child nodes tn1 cur Execute step HI: Step H: According to each child node tn of t, cur The information creates the corresponding graph node n new , n ew Add to g1; Step I: Establish the penultimate graph node in g1 and n new The connecting edges between Step J: If graph node n new For While type, graph node n new Convert to a control node, create a new subgraph g2 and insert it into the graph set G. If the graph node n new If type, the graph node n new Transform into a control node, create a new subgraph for all its child nodes and insert it into the graph set G; When S tn When it is empty, the conversion is completed, and the graph set G is the converted directed acyclic graph.

10. The multi-script execution method according to claim 1, characterized in that: When interpreting and executing a script object, the script debugger is also used to debug the script object: When the script's debug flag is true, the script debugger gets the script object; Script debugger steps through graph nodes in a directed acyclic graph; When the debugging flag of the script is false, the script object is restored to be interpreted and executed, and the script debugger stops executing the graph nodes in the directed acyclic graph.

Citation Information

Patent Citations

  • Script generation method and device, equipment and storage medium

    CN118519630A

  • Script conversion program for model inspection, model inspection program, script conversion device for model inspection and model inspection device

    JP2020030490A

  • System and method for modifying execution of scripts for a job scheduler using deontic logic

    US20100211815A1

Cited By

  • Intelligent robot control algorithm scheduling method and system based on dynamic directed acyclic graph

    CN120697030A

  • Interpreted script pre-execution verification method and device, medium and program product

    CN121501634A

  • An interpretive script pre-execution verification method, device, medium and program product

    CN121501634B

  • Script access object white list verification method and device, medium and program product

    CN121501635A

  • A script access object whitelist checking method, device, medium and program product

    CN121501635B