An execution method and system of an axle control script program, a terminal, and a storage medium
By compiling the axis control script program into a layered executable structure and introducing an execution flow management mechanism, the problem of high coupling in the execution structure of the axis control script program is solved, enabling effective handling of complex control logic and improved execution reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN HANS ROBOT CO LTD
- Filing Date
- 2026-04-14
- Publication Date
- 2026-07-21
AI Technical Summary
The existing axis control script program execution structure has a high degree of coupling and cannot effectively handle complex control logic, resulting in poor execution reliability.
The compiler-execution separation architecture is adopted, which compiles the axis control script program into a layered executable structure of real-time script buffer unit and script line unit, and introduces a controllable execution flow management mechanism to schedule and manage the status information of the buffer unit through preset control cycle.
It improves the execution reliability of axis control script programs, effectively handles complex control logic, reduces system coupling, and ensures the balanced progress of multiple script tasks in the time dimension.
Smart Images

Figure CN122431822A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial automation control technology, and in particular to a method, system, terminal, and storage medium for executing axis control script programs. Background Technology
[0002] Axis control systems typically require coordinated control of multiple motion axes based on user-programmed control logic to achieve functions such as complex trajectory planning, logical judgment, and real-time response. However, in practical applications, the control logic faced by axis control systems is becoming increasingly complex, and traditional program execution methods are gradually revealing their shortcomings in terms of real-time performance, determinism, and maintainability, making it difficult to meet the stringent requirements of multi-axis linkage, high-speed interpolation, and complex logical judgment in high-frequency control scenarios.
[0003] Currently, various axis control program execution schemes have been developed, mainly including control methods based on fixed-function instruction sets, interpreted execution methods based on scripts or high-level languages, and periodic scanning execution methods based on programmable logic controllers (PLCs). However, these existing schemes still have significant drawbacks in practical applications. For example, the fixed-instruction-set method lacks flexibility and is difficult to adapt to changing control requirements; the interpreted execution method parses instructions line by line during runtime, limiting execution efficiency and easily causing control delays or execution jitter; the periodic scanning method, due to the high coupling between the compilation and execution processes, lacks a unified and clear intermediate representation or execution structure, leading to difficulties in program debugging and insufficient scalability. More importantly, existing technologies generally lack the ability to fine-grained manage user control logic, failing to effectively track instruction execution status, execution order, and execution results, making it difficult to achieve flexible flow control and exception handling mechanisms. Therefore, the existing axis control script program execution structure has high coupling and cannot effectively handle complex control logic, resulting in poor reliability of axis control script program execution. Summary of the Invention
[0004] This invention proposes a method, system, terminal, and storage medium for executing axis control script programs. It addresses the problem of poor execution reliability caused by the high coupling and inability to effectively handle complex control logic in existing axis control script program execution structures. This invention simplifies the execution structure by employing a compiler-execution separation architecture and introduces a controllable execution flow management mechanism to monitor and manage the axis control script program execution process. This enables the axis control program to effectively handle complex control logic during execution, thereby improving the reliability of axis control script program execution.
[0005] To achieve the above objectives, embodiments of the present invention provide a method for executing an axis control script program, comprising: compiling a pre-acquired axis control script program into a plurality of executable script units, wherein each executable script unit consists of a plurality of real-time script buffer units and a plurality of script line units; within any preset control period, using the real-time script buffer units as scheduling objects, traversing each real-time script buffer unit in an enabled state to obtain the enabled real-time script buffer unit corresponding to each preset control period; based on the enabled real-time script buffer unit, obtaining the current execution state information of the enabled real-time script buffer unit, and selecting a plurality of corresponding script line units according to the current execution state information; sequentially executing the instructions corresponding to the script line units, and updating the current execution state information of the enabled real-time script buffer unit each time the instruction is executed, until the plurality of script line units corresponding to the enabled real-time script buffer unit are executed, thereby completing the axis control script program execution process.
[0006] This invention proposes a method for executing axis control script programs. The method compiles the axis control script program into a layered executable structure containing real-time script buffer units and script line units, thereby separating the compilation and execution processes and reducing system coupling. Furthermore, it iterates and schedules each enabled buffer unit in a preset control cycle, ensuring that each enabled buffer unit has an execution opportunity in each cycle. This avoids a single script occupying execution resources for an extended period, guaranteeing balanced progress of multiple script tasks over time. Thus, this method simplifies the execution structure by adopting a compilation-execution separation architecture and introduces a controllable execution flow management mechanism to monitor and manage the axis control script program execution process. This enables the axis control program to effectively handle complex control logic during execution, thereby improving the reliability of axis control script program execution.
[0007] Furthermore, the pre-acquired axis control script program is compiled into several executable script units, each of which consists of several real-time script buffer units and several script line units. The process includes: receiving the axis control script program input by the user; obtaining structured text code statements and corresponding buffer identifiers; performing string segmentation on the structured text code statements, matching multi-character symbols and extracting identifier fragments to obtain a string array; converting each string in the string array into a token sequence and identifying the corresponding variable declaration format; encapsulating the token sequence that has completed variable declaration format identification into a command unit and associating it with the buffer identifier to generate the real-time script buffer unit; generating the script line unit based on the real-time script buffer unit and a preset logical order combination, and associating one or more script line units with the corresponding real-time script buffer unit, integrating the real-time script buffer unit and the script line unit to obtain an executable script unit.
[0008] In the above scheme, buffer identifiers are introduced to mark code segments. Combined with string splitting, token sequence conversion, and variable declaration format recognition, the structured text code statements input by the user are gradually transformed into structured command units, ultimately forming a hierarchically clear executable script unit. This not only preserves the logical order and variable scope information of the original code but also associates each command unit with its respective buffer identifier, facilitating the differentiation and independent scheduling of code in different buffers during subsequent execution. Simultaneously, by processing variable declaration statements separately and registering them in a variable table, variable declarations are prevented from entering the expression evaluation process, improving compilation efficiency and code execution security, and providing a reliable data structure foundation for subsequent execution.
[0009] Furthermore, in the step of converting each string in the string array into a token sequence and identifying the corresponding variable declaration format, the identification of the corresponding variable declaration format includes: if a variable declaration statement is identified, registering the variable corresponding to the variable declaration statement into the variable table corresponding to the buffer identifier; if an identifier is identified and the next token sequence of the identifier is a left parenthesis, determining the identifier as a function name and obtaining the function address from the preset function manager; if an identifier is identified and the next token sequence of the identifier is not a left parenthesis, determining the identifier as a variable name and obtaining the variable address from the preset variable manager.
[0010] In the above scheme, a context rule based on whether the next token sequence of the identifier is a left bracket is used to distinguish function names and variable names. This avoids the ambiguity and limitations of simply relying on name string matching, enabling the axis control system to flexibly support user-defined function and variable naming without maintaining a large keyword whitelist, thus reducing the maintenance cost of the axis control system. Separate identification and registration of variable declaration statements ensures that variables complete memory allocation and address binding during the compilation phase, reducing runtime parsing overhead. For the identification of function and variable names, function and variable addresses are pre-obtained through the function manager and variable manager, providing an efficient routing mechanism for subsequent function calls. This supports parsing complex variable expressions into structured addressing information, improving the efficiency of accessing complex data structures.
[0011] Furthermore, before the step of compiling the pre-acquired axis control script program into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units, the process further includes: creating a project directory in response to a new project operation; reading user code files in the current project directory in response to a pre-compilation operation, and performing syntax and integrity checks on the user code files; if the checks pass, generating the axis control script program; if the checks fail, recording error information and preventing the project from entering the running state.
[0012] The above scheme introduces project management and pre-compilation verification mechanisms to provide a security barrier for the execution of axis control script programs. Unified management of the project directory facilitates independent storage, rapid switching, and state maintenance of multiple axis control projects, enabling isolation and reuse between different control tasks. Syntax and integrity checks during pre-compilation can detect syntax errors, incomplete variable declarations, incorrect function call formats, and mismatched project configuration parameters in user code in advance, preventing unqualified control logic from entering the runtime phase and thus preventing runtime errors from damaging the axis control equipment. Error messages recorded when verification fails provide clear debugging guidance for users, improving the efficiency of code development and maintenance, and contributing to increased reliability of axis control script program execution.
[0013] Furthermore, based on the enabled real-time script buffer unit, the current execution status information of the enabled real-time script buffer unit is obtained, and several corresponding script line units are selected according to the current execution status information, including: reading the current execution status information of the enabled real-time script buffer unit and using the current execution status information as the line pointer of the enabled real-time script buffer unit; and selecting several script line units associated with the enabled real-time script buffer unit based on the line pointer.
[0014] In the above scheme, an independent line pointer is maintained for each real-time script buffer unit, enabling accurate tracking of the execution progress of multiple script segments. The line pointer, as a lightweight execution status information, records the current script line position of each buffer unit with minimal storage overhead, allowing the axis control system to seamlessly connect execution flows between multiple control cycles. When the axis control system switches between different real-time script buffer units, it only needs to read the line pointer of the corresponding real-time script buffer unit to quickly locate the script line unit to be executed, without having to traverse the entire script code. This not only improves the efficiency of execution scheduling but also allows the axis control system to save and restore the execution progress of each buffer unit during project switching or abnormal recovery, contributing to improved reliability of axis control script execution.
[0015] Furthermore, the instructions corresponding to the script line units are executed sequentially. Each time an instruction is executed, the current execution status information of the enabled real-time script buffer unit is updated until the script line units corresponding to the enabled real-time script buffer unit are executed, thus completing the axis control script program execution process. This includes: executing the instructions corresponding to the script line units in a preset order; if all instructions of the current script line unit are executed, updating the current execution status information of the enabled real-time script buffer unit and incrementing the line pointer so that the line pointer points to the next script line unit to be executed; if the line pointer points to a null value, the enabled real-time script buffer unit is executed; when all enabled real-time script buffer units are executed, the axis control script program execution process is completed.
[0016] In the above scheme, a sequential execution mechanism at the instruction level and an automatic incrementing mechanism for the row pointer are used to automate the script execution process. Within each control cycle, the axis control system executes all instructions within the current script line unit in a preset order, ensuring the atomicity of logical operations within a single line and preventing inconsistencies caused by incomplete instruction execution within the same line due to cycle interruptions. After execution, the system automatically transitions to the next script line by incrementing the row pointer. When the row pointer points to a null value, the axis control system can accurately determine that the real-time script buffer unit has been completed, thus removing it from the scheduling queue of subsequent cycles and avoiding unnecessary scheduling that occupies execution resources. Therefore, the axis control system can automatically manage the lifecycle of multiple real-time script buffer units, achieving fully automated management from the start of execution to completion, which helps improve the reliability of axis control script program execution.
[0017] Furthermore, the step of executing the corresponding instructions in the script line unit according to a preset order also includes: associating several function identifiers with corresponding executable functions based on a pre-built function registry; during the execution of the instructions corresponding to the script line unit, when a function call is parsed, searching for the corresponding executable function in the function registry according to the parsed function identifier; and executing the executable function through a preset calling interface.
[0018] In the above scheme, a function registry mechanism is introduced to decouple function identifiers from executable functions, enabling modular management and dynamic expansion of script functions. All script functions are executed through a unified calling interface. The execution flow does not need to concern itself with the implementation details of specific function types. When adding or modifying script functions, only the corresponding function unit needs to be added or updated in the registry, without modifying the main framework code of the execution system. This improves the system's scalability and function reuse efficiency. During function calls, the axis control system can also perform quantity and type validation on the actual parameters based on the input parameter information configured during registration. This separates parameter validity checks from function business logic, filtering out invalid function calls before invocation, reducing the probability of runtime errors, and improving the stability and reliability of the axis control system.
[0019] This invention also provides an execution system for an axis control script program, including a program compilation module, a real-time script buffer unit traversal module, a script line unit selection module, and an instruction execution module; wherein: the program compilation module is used to compile a pre-acquired axis control script program into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units; the real-time script buffer unit traversal module is used to traverse each real-time script buffer unit in the enabled state within any preset control cycle, taking the real-time script buffer unit as the scheduling object, to obtain the enabled real-time script buffer unit corresponding to each preset control cycle; the script line unit selection module is used to obtain the current execution status information of the enabled real-time script buffer unit based on the enabled real-time script buffer unit, and select several corresponding script line units according to the current execution status information; the instruction execution module is used to execute the corresponding instructions in the script line units sequentially, and update the current execution status information of the enabled real-time script buffer unit each time the instruction execution is completed, until the several script line units corresponding to the enabled real-time script buffer unit are executed, thus completing the axis control script program execution process.
[0020] This invention proposes an execution system for axis control script programs. The axis control script program is compiled into a layered executable structure containing real-time script buffer units and script line units, thereby separating the compilation and execution processes and reducing system coupling. Furthermore, each enabled buffer unit is traversed and scheduled in a preset control cycle to ensure that each enabled buffer unit has an execution opportunity in each cycle. This avoids a single script occupying execution resources for an extended period and ensures balanced progress of multiple script tasks over time. Thus, the compilation-execution separation architecture simplifies the execution structure, and a controllable execution flow management mechanism is introduced to monitor and manage the axis control script program execution process, enabling the program to effectively handle complex control logic and improve its execution reliability.
[0021] An execution terminal for an axis control script program, the terminal comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the aforementioned method for executing an axis control script program when executing the computer program.
[0022] An execution storage medium for an axis control script program, the storage medium comprising a stored computer program, wherein, when the computer program is running, the device where the storage medium is located executes the aforementioned method for executing the axis control script program. Attached Figure Description
[0023] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0024] Figure 1 A flowchart illustrating the steps of an axis control script program execution method according to a certain embodiment of the present invention; Figure 2 A schematic diagram of the executable script unit architecture of an axis control script program execution method provided in a certain embodiment of the present invention; Figure 3 This is a schematic diagram of the module structure of an axis control script program execution system provided in a certain embodiment of the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0026] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.
[0027] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.
[0028] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0029] In the description of the embodiments in this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.
[0030] In the description of the embodiments of this application, the term "multiple" refers to two or more (including two), similarly, "multiple sets" refers to two or more (including two sets), and "multiple pieces" refers to two or more (including two pieces).
[0031] In the description of the embodiments of this application, unless otherwise expressly specified and limited, technical terms such as "installation," "connection," "joining," and "fixing" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components. For those skilled in the art, the specific meaning of the above terms in the embodiments of this application can be understood according to the specific circumstances.
[0032] To address the issue of poor reliability in existing axis control script execution due to high coupling in the script execution structure and its inability to effectively handle complex control logic, see [reference needed]. Figure 1 , Figure 1 This is a flowchart illustrating the steps of an axis control script program execution method according to a certain embodiment of the present invention; as shown below. Figure 1 As shown, this embodiment of the invention proposes a method for executing an axis control script program, including steps 101 to 104, each step of which is as follows: Step 101: Compile the pre-acquired axis control script program into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units; Step 102: Within any preset control period, using the real-time script buffer unit as the scheduling object, traverse each of the real-time script buffer units that are in the enabled state to obtain the enabled real-time script buffer units corresponding to each preset control period. Step 103: Based on the enabled real-time script buffer unit, obtain the current execution status information of the enabled real-time script buffer unit, and select several corresponding script line units according to the current execution status information. Step 104: Execute the corresponding instructions in the script line unit in sequence. Each time the instruction is executed, update the current execution status information of the enabled real-time script buffer unit until the script line units corresponding to the enabled real-time script buffer unit are executed, thus completing the axis control script program execution process.
[0033] One possible implementation is to execute the axis control script program execution method proposed in this embodiment of the invention using a real-time script system. The real-time script system includes a code editing system, a project management system, and a compilation and execution system. The code editing system provides users with an environment for writing axis control programs, and its main functions include the creation, editing, and basic syntax constraints of axis control programs. The project management system is used to uniformly manage and verify the user code generated by the code editing system, and its main functions include project organization and management, code legality verification, and pre-execution preparation. The compilation and execution system is used to compile and execute the code verified by the project management system in real time, and its main functions include code compilation, instruction organization, and execution scheduling.
[0034] For example, this embodiment proposes a method for executing axis control script programs. First, the input axis control script program is compiled, converting it into executable script units with a hierarchical structure. Each executable script unit consists of multiple real-time script buffer units and multiple script line units. Specifically, see... Figure 2 , Figure 2 A schematic diagram of the executable script unit architecture for an axis control script program execution method provided in a certain embodiment of the present invention; as shown. Figure 2 As shown, a complete project corresponds to a project-level unit. Each project-level unit includes multiple real-time script buffer units, each real-time script buffer unit includes multiple script line units, and each script line unit includes multiple instruction-level units. The project-level unit is represented as "project," the real-time script buffer unit as "buffer," the script line unit as "line," and the instruction-level unit as "cmd." Figure 2The numbers 1, 2, and 3 are used to distinguish different units and have no special meaning.
[0035] After compilation, the controller begins the scheduling process based on a preset control period, which in this embodiment can be 1 millisecond. At the beginning of each control period, a list of all enabled but not yet completed real-time script buffer units in the current project is obtained. Then, each real-time script buffer unit in the list is traversed sequentially. For the currently traversed real-time script buffer unit, its internally maintained current execution status information is read. This current execution status information is represented by a line pointer pointing to the script line unit to be executed. Based on this line pointer, the corresponding script line unit is selected from the current real-time script buffer unit. Then, all instruction layer units contained in the script line unit are executed sequentially. Each instruction layer unit corresponds to a specific axis control operation or logic processing. When all instruction layer units in the script line unit have been executed, the current execution status information of the current real-time script buffer unit is updated, and the line pointer is incremented to point to the next script line unit. In the next control period, the same operation is performed on the real-time script buffer unit, and this process is repeated until the line pointer points to a null value, indicating that all script line units corresponding to the real-time script buffer unit have been executed. Once all enabled real-time script buffer units have finished executing, the entire axis control script program execution process is complete.
[0036] This invention proposes a method for executing axis control script programs. The method compiles the axis control script program into a layered executable structure containing real-time script buffer units and script line units, thereby separating the compilation and execution processes and reducing system coupling. Furthermore, it iterates and schedules each enabled buffer unit in a preset control cycle, ensuring that each enabled buffer unit has an execution opportunity in each cycle. This avoids a single script occupying execution resources for an extended period, guaranteeing balanced progress of multiple script tasks over time. Thus, this method simplifies the execution structure by adopting a compilation-execution separation architecture and introduces a controllable execution flow management mechanism to monitor and manage the axis control script program execution process. This enables the axis control program to effectively handle complex control logic during execution, thereby improving the reliability of axis control script program execution.
[0037] In a preferred embodiment, a pre-acquired axis control script program is compiled into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units, including: receiving the axis control script program input by the user; obtaining structured text code statements and buffer identifiers corresponding to the structured text code statements; performing string segmentation on the structured text code statements, matching multi-character symbols and extracting identifier fragments to obtain a string array; converting each string in the string array into a token sequence and identifying the corresponding variable declaration format; encapsulating the token sequence that has completed variable declaration format identification into a command unit and associating it with the buffer identifier to generate the real-time script buffer unit; generating the script line unit based on the real-time script buffer unit and a preset logical order combination, and associating one or more script line units with the corresponding real-time script buffer units, integrating the real-time script buffer units and the script line units to obtain an executable script unit.
[0038] For example, the system first receives the ST language code statement input by the user and the buffer identifier to which the statement belongs. In this embodiment, the ST language code statement is represented as a structured text code statement, denoted as sCmd. The buffer identifier is used to mark the program segment or command buffer where the current code is located, so as to facilitate subsequent variable scope judgment and structured storage, and is denoted as PushBuffID. Then, the string splitting function SplitString(sCmd, v_sCmd) is used to split the ST language code statement sCmd into strings. The splitting rule is to traverse the string in character order, automatically skip white characters, prioritize matching multi-character symbols, and if the current position is not a symbol, continuously extract complete identifier fragments composed of letters, numbers, underscores, member access characters ".", and array subscript characters "[ ]". The obtained fragments are stored in the string array in order, and white characters and end characters are deleted to form the string sequence used for subsequent parsing.
[0039] Then, each string in the string sequence is converted into a Token sequence. During the conversion, multiple recognition actions are performed in sequence, including determining whether it is a logical control statement keyword such as IF, THEN, ELSIF, ELSE, END_IF, WHILE, FOR, CASE, RETURN, etc.; determining whether it is a TRUE / FALSE Boolean literal; determining whether it conforms to the variable declaration format of "variable name: type name"; and determining whether it is an assignment operator, separator, operator, or delimiter. For strings that do not match the above recognition rules, they are temporarily identified as identifiers to be further processed. When a string is successfully recognized, the corresponding Token object is constructed and written into the Token sequence.
[0040] The system then identifies the variable declaration format of the token sequence. If the system recognizes a variable declaration statement, such as "A :INT;", it identifies the variable name and variable type from the token sequence, calls the variable manager to register the variable in the variable table corresponding to the current buffer identifier, and marks the statement as a variable declaration statement, preventing it from entering the ordinary expression calculation process. For tokens temporarily identified as identifiers, the system further determines the type based on the context. If the token following the identifier is a left parenthesis, it is determined to be a function name, the function manager is called to obtain the function address, and the token type is rewritten as the function type. If it is not followed by a left parenthesis, it is determined to be a variable name, and the token type is rewritten as the variable type. After completing the variable name recognition, the system further parses complex variable expressions, including ordinary variables, structure members, array elements, and composite structure arrays. Specifically, through steps such as member accessor segmentation, array subscript extraction, and hierarchical calls to the structure manager to parse member types, structured addressing information of "base address + array offset + structure level offset" is generated.
[0041] Finally, the token sequence after tokenization and resolution of variables, functions and / or offsets is encapsulated into a command unit, and the current buffer identifier is added to generate a real-time script buffer unit. Then, the units are combined according to a preset logical order to generate script line units, and finally integrated to obtain an executable script unit.
[0042] In the above scheme, buffer identifiers are introduced to mark code segments. Combined with string splitting, token sequence conversion, and variable declaration format recognition, the structured text code statements input by the user are gradually transformed into structured command units, ultimately forming a hierarchically clear executable script unit. This not only preserves the logical order and variable scope information of the original code but also associates each command unit with its respective buffer identifier, facilitating the differentiation and independent scheduling of code in different buffers during subsequent execution. Simultaneously, by processing variable declaration statements separately and registering them in a variable table, variable declarations are prevented from entering the expression evaluation process, improving compilation efficiency and code execution security, and providing a reliable data structure foundation for subsequent execution.
[0043] In a preferred embodiment, in the step of converting each string in the string array into a token sequence and identifying the corresponding variable declaration format, the identification of the corresponding variable declaration format includes: if a variable declaration statement is identified, registering the variable corresponding to the variable declaration statement into the variable table corresponding to the buffer identifier; if an identifier is identified and the next token sequence of the identifier is a left parenthesis, determining the identifier as a function name and obtaining the function address from a preset function manager; if an identifier is identified and the next token sequence of the identifier is not a left parenthesis, determining the identifier as a variable name and obtaining the variable address from a preset variable manager.
[0044] For example, during the process of converting each string in the string array into a token sequence, differentiated processing flows are executed for different types of input. When an input statement is identified as conforming to the variable declaration format, the following actions are performed: the variable name "A" and variable type "INT" are identified from the string segmentation result; the variable type resolution function is called to obtain the variable type number; then, the variable manager's add variable interface is called to register the variable into the variable table corresponding to the current buffer identifier; at the same time, the statement is marked as a variable declaration statement, and the variable declaration result is returned directly without proceeding to the subsequent ordinary expression calculation process.
[0045] When an identifier is detected, a context-based determination rule is used to distinguish whether the identifier is a function name or a variable name. Specifically, it checks whether the next token sequence of the identifier is a left parenthesis. If the next token is a left parenthesis, it means that the identifier is a function name. The function manager's function address retrieval interface is called to find and retrieve the corresponding function address based on the function name. Then, the type of the token is changed from the preprocessed identifier type to the function type. If the next token is not a left parenthesis, the identifier is determined to be a variable name. The system changes the type of the token to the variable type and can retrieve the variable address from the variable manager.
[0046] In the above scheme, a context rule based on whether the next token sequence of the identifier is a left bracket is used to distinguish function names and variable names. This avoids the ambiguity and limitations of simply relying on name string matching, enabling the axis control system to flexibly support user-defined function and variable naming without maintaining a large keyword whitelist, thus reducing the maintenance cost of the axis control system. Separate identification and registration of variable declaration statements ensures that variables complete memory allocation and address binding during the compilation phase, reducing runtime parsing overhead. For the identification of function and variable names, function and variable addresses are pre-obtained through the function manager and variable manager, providing an efficient routing mechanism for subsequent function calls. This supports parsing complex variable expressions into structured addressing information, improving the efficiency of accessing complex data structures.
[0047] In a preferred embodiment, before executing the step of compiling the pre-acquired axis control script program into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units, the method further includes: creating a project directory in response to a new project operation; reading user code files in the current project directory in response to a pre-compilation operation, and performing syntax and integrity checks on the user code files; if the checks pass, generating the axis control script program; if the checks fail, recording error information and preventing the project from entering the running state.
[0048] For example, before performing the compilation step, a project management operation is proposed, which maintains an independent project directory for each axis control project. This project directory includes at least a project configuration file, a user code file, a buffer information file, a pre-compiled result file, and a project index file. The project configuration file records the project name, project path, axis configuration parameters, and runtime parameters; the user code file stores the ST code written by the user; the buffer information file records the number, name, associated code segment, and status information of each buffer; the pre-compiled result file stores the verified structured code or intermediate representation; and the project index file records the code modules, function blocks, and variable table information contained in the current project.
[0049] When a new project is created, the system first creates the corresponding project directory and generates default project configuration files, code files, and buffer information files within that directory. Simultaneously, the default buffer is initialized, and project index information is established. When a project is deleted, the system locates the corresponding project directory based on the target project identifier, deletes all related files in that directory, and completes the project deletion. Notably, the system also supports importing and exporting projects, facilitating project backup, migration, and sharing.
[0050] When responding to a pre-compilation operation, the user code file in the current project directory is read and submitted to the syntax verification module for preliminary verification. The preliminary verification process includes at least: whether the syntax keywords are valid, whether the variable declarations are complete, whether the expression format is correct, whether the function call format is correct, whether the association between the buffer and the code segment is consistent, and whether the project configuration parameters match the objects referenced in the code. In one implementation, syntax analysis of the user code is performed using syntax rules built based on ANTLR4 to obtain a syntax tree or intermediate structure. When the verification passes, the verified code or intermediate representation is generated and written to the pre-compiled result file, which is the axis control script program to be processed in the compilation step. When the verification fails, the system records the error location, error type, and error message, and prevents the project from entering the running state, thereby avoiding the execution of non-compliant control logic.
[0051] The above scheme introduces project management and pre-compilation verification mechanisms to provide a security barrier for the execution of axis control script programs. Unified management of the project directory facilitates independent storage, rapid switching, and state maintenance of multiple axis control projects, enabling isolation and reuse between different control tasks. Syntax and integrity checks during pre-compilation can detect syntax errors, incomplete variable declarations, incorrect function call formats, and mismatched project configuration parameters in user code in advance, preventing unqualified control logic from entering the runtime phase and thus preventing runtime errors from damaging the axis control equipment. Error messages recorded when verification fails provide clear debugging guidance for users, improving the efficiency of code development and maintenance, and contributing to increased reliability of axis control script program execution.
[0052] In a preferred embodiment, based on the enabled real-time script buffer unit, the current execution status information of the enabled real-time script buffer unit is obtained, and several corresponding script line units are selected according to the current execution status information, including: reading the current execution status information of the enabled real-time script buffer unit and using the current execution status information as the line pointer of the enabled real-time script buffer unit; and selecting several script line units associated with the enabled real-time script buffer unit based on the line pointer.
[0053] For example, during the execution scheduling process, an independent current execution status information is maintained for each real-time script buffer unit. This status information is specifically represented by a line pointer, which is an index value pointing to the position of the script line sequence inside the buffer unit, recording which line of script the real-time script buffer unit has currently executed.
[0054] When traversing enabled real-time script buffer units at the start of a new control cycle, for the currently traversed enabled real-time script buffer unit, the line pointer value stored internally in that buffer unit is first read. For example, suppose a buffer unit named "MainTask" contains 10 lines of script, and its current line pointer value is 5, indicating that the first 4 lines of script have been executed, and the next line to be executed is the 5th line. This line pointer value is used as the basis for selecting the script line unit, and the corresponding script line unit is directly located and selected from the script line sequence associated with that buffer unit based on the line pointer value.
[0055] In the above scheme, an independent line pointer is maintained for each real-time script buffer unit, enabling accurate tracking of the execution progress of multiple script segments. The line pointer, as a lightweight execution status information, records the current script line position of each buffer unit with minimal storage overhead, allowing the axis control system to seamlessly connect execution flows between multiple control cycles. When the axis control system switches between different real-time script buffer units, it only needs to read the line pointer of the corresponding real-time script buffer unit to quickly locate the script line unit to be executed, without having to traverse the entire script code. This not only improves the efficiency of execution scheduling but also allows the axis control system to save and restore the execution progress of each buffer unit during project switching or abnormal recovery, contributing to improved reliability of axis control script execution.
[0056] In a preferred embodiment, the instructions corresponding to the script line units are executed sequentially. Each time an instruction is executed, the current execution status information of the enabled real-time script buffer unit is updated until all script line units corresponding to the enabled real-time script buffer unit have been executed, thus completing the axis control script program execution process. This includes: executing the instructions corresponding to the script line units in a preset order; if all instructions in the current script line unit have been executed, updating the current execution status information of the enabled real-time script buffer unit and incrementing the line pointer so that the line pointer points to the next script line unit to be executed; if the line pointer points to a null value, the enabled real-time script buffer unit has been executed; and when all enabled real-time script buffer units have been executed, the axis control script program execution process is completed.
[0057] For example, after selecting the script line unit corresponding to the enabled real-time script buffer unit, all instructions contained in the script line unit are executed in a preset order. The preset order refers to the natural arrangement order of instructions in each line when the script is written. For example, it can be set to execute them in order from left to right.
[0058] During execution, instructions are executed one by one, and the axis control status and variable values are updated accordingly. When the last instruction in the current script line unit is completed, it is determined that all instructions in the current script line unit have been executed. At this point, an execution status update operation is performed. Specifically, the current execution status information of the enabled real-time script buffer unit is updated first, and then its line pointer is incremented by 1, making the line pointer point to the next script line unit to be executed in that enabled real-time script buffer unit. For example, if the current line pointer value is 5, after execution, the line pointer is updated to 6, indicating that the 6th line of script will be executed in the next control cycle.
[0059] After each update of the row pointer, check if the row pointer points to a null value. If the row pointer value exceeds the total number of script lines contained in the enabled real-time script buffer unit, it is determined that the row pointer points to a null value. At this time, the enabled real-time script buffer unit is marked as completed. Enabled real-time script buffer units marked as completed will be skipped in the traversal of subsequent control cycles and will no longer participate in scheduling. When all enabled real-time script buffer units are marked as completed, the execution process of the entire axis control script program is completed.
[0060] In the above scheme, a sequential execution mechanism at the instruction level and an automatic incrementing mechanism for the row pointer are used to automate the script execution process. Within each control cycle, the axis control system executes all instructions within the current script line unit in a preset order, ensuring the atomicity of logical operations within a single line and preventing inconsistencies caused by incomplete instruction execution within the same line due to cycle interruptions. After execution, the system automatically transitions to the next script line by incrementing the row pointer. When the row pointer points to a null value, the axis control system can accurately determine that the real-time script buffer unit has been completed, thus removing it from the scheduling queue of subsequent cycles and avoiding unnecessary scheduling that occupies execution resources. Therefore, the axis control system can automatically manage the lifecycle of multiple real-time script buffer units, achieving fully automated management from the start of execution to completion, which helps improve the reliability of axis control script program execution.
[0061] In a preferred embodiment, the step of executing the instructions corresponding to the script line unit in a preset order further includes: associating several function identifiers with corresponding executable functions based on a pre-built function registry; during the execution of the instructions corresponding to the script line unit, when a function call is parsed, searching for the corresponding executable function in the function registry based on the parsed function identifier; and executing the executable function through a preset calling interface.
[0062] For example, a function registration information table is pre-built during the startup phase. This table records the function identifier, input parameter information, and corresponding function execution unit for each script function. Each script function exists as an independent executable function and inherits from a unified function base class. Notably, the function base class defines a unified function call entry point to receive the parameter list passed in during the script parsing phase and to complete the necessary parameter binding and validity verification before calling the execution logic.
[0063] Specifically, during the function registration phase, the function identifier is associated with the corresponding executable function, and the input parameter information of the executable function is configured. This parameter information is stored in the function registry. When the script executes an instruction that requires a function call during runtime, such as when a function call statement is parsed, the corresponding executable function is searched for in the function registry based on the parsed function identifier. After finding the corresponding executable function, the pre-configured input parameter information of the executable function is obtained, and the number and type of the actually passed parameters are validated. The specific process is as follows: first, the number of actual parameters is validated; then, the type of each parameter is validated. If the validation passes, the executable function is called through a unified entry point to execute its internal business logic and return the calculation result. If the validation fails, the error message is recorded, and the executable function is prevented from entering the execution phase to avoid runtime errors caused by parameter mismatch.
[0064] In the above scheme, a function registry mechanism is introduced to decouple function identifiers from executable functions, enabling modular management and dynamic expansion of script functions. All script functions are executed through a unified calling interface. The execution flow does not need to concern itself with the implementation details of specific function types. When adding or modifying script functions, only the corresponding function unit needs to be added or updated in the registry, without modifying the main framework code of the execution system. This improves the system's scalability and function reuse efficiency. During function calls, the axis control system can also perform quantity and type validation on the actual parameters based on the input parameter information configured during registration. This separates parameter validity checks from function business logic, filtering out invalid function calls before invocation, reducing the probability of runtime errors, and improving the stability and reliability of the axis control system.
[0065] Based on the above method embodiments, corresponding apparatus embodiments are provided; see [link to apparatus embodiments]. Figure 3 , Figure 3 This is a schematic diagram of the module structure of an axis control script program execution system according to a certain embodiment of the present invention. Figure 3As shown, this embodiment of the invention also provides an execution system for an axis control script program, including a program compilation module 201, a real-time script buffer unit traversal module 202, a script line unit selection module 203, and an instruction execution module 204; wherein: the program compilation module 201 is used to compile a pre-acquired axis control script program into several executable script units, wherein each executable script unit is composed of several real-time script buffer units and several script line units; the real-time script buffer unit traversal module 202 is used to traverse each real-time script buffer unit in the enabled state within any preset control cycle, using the real-time script buffer unit as the scheduling object. The system executes the real-time script buffer unit to obtain the corresponding enabled real-time script buffer unit within each preset control cycle. The script line unit selection module 203 is used to obtain the current execution status information of the enabled real-time script buffer unit based on the enabled real-time script buffer unit, and select several corresponding script line units according to the current execution status information. The instruction execution module 204 is used to execute the corresponding instructions in the script line units in sequence. Whenever the instruction execution is completed, the current execution status information of the enabled real-time script buffer unit is updated until the several script line units corresponding to the enabled real-time script buffer unit are executed, thus completing the axis control script program execution process.
[0066] This invention proposes an execution system for axis control script programs. The axis control script program is compiled into a layered executable structure containing real-time script buffer units and script line units, thereby separating the compilation and execution processes and reducing system coupling. Furthermore, each enabled buffer unit is traversed and scheduled in a preset control cycle to ensure that each enabled buffer unit has an execution opportunity in each cycle. This avoids a single script occupying execution resources for an extended period and ensures balanced progress of multiple script tasks over time. Thus, the compilation-execution separation architecture simplifies the execution structure, and a controllable execution flow management mechanism is introduced to monitor and manage the axis control script program execution process, enabling the program to effectively handle complex control logic and improve its execution reliability.
[0067] It is understood that the above-described device embodiments correspond to the method embodiments of the present invention, and can implement the method for executing an axis control script program provided by any of the above-described method embodiments of the present invention.
[0068] It should be noted that the device embodiments described above are merely illustrative, and some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can specifically be implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.
[0069] Based on the above-described embodiment of the method for executing an axis control script program, another embodiment of the present invention provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the method for executing an axis control script program according to any embodiment of the present invention.
[0070] For example, in this embodiment, the computer program can be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the terminal device.
[0071] The terminal device may be a desktop computer, laptop, handheld computer, or cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0072] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the terminal device, connecting all parts of the terminal device via various interfaces and lines.
[0073] Based on the above-described method embodiments, another embodiment of the present invention provides a computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to execute a method for executing an axis control script program as described in any of the above-described method embodiments of the present invention.
[0074] The modules / units integrated in the device / terminal equipment, if implemented as software functional units and sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.
[0075] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A method for executing an axis control script program, characterized in that, include: The pre-acquired axis control script program is compiled into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units; Within any preset control period, the real-time script buffer unit is used as the scheduling object, and each real-time script buffer unit in the enabled state is traversed to obtain the enabled real-time script buffer unit corresponding to each preset control period. Based on the enabled real-time script buffer unit, the current execution status information of the enabled real-time script buffer unit is obtained, and several corresponding script line units are selected according to the current execution status information. The corresponding instructions in the script line unit are executed sequentially. Each time the instruction is executed, the current execution status information of the enabled real-time script buffer unit is updated until the several script line units corresponding to the enabled real-time script buffer unit are executed, thus completing the axis control script program execution process.
2. The method for executing a shaft control script program as described in claim 1, characterized in that, The pre-acquired axis control script program is compiled into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units, including: Receive the axis control script program input by the user, and obtain the structured text code statement and the buffer identifier corresponding to the structured text code statement; The structured text code statement is split into strings, multi-character symbols are matched and identifier fragments are extracted to obtain a string array; Each string in the string array is converted into a token sequence, and the corresponding variable declaration format is identified; The token sequence that has completed variable declaration format recognition is encapsulated into a command unit and associated with the buffer identifier to generate the real-time script buffer unit; Based on the real-time script buffer unit and the preset logical sequence combination, the script line unit is generated, and one or more script line units are associated with the corresponding real-time script buffer unit. The real-time script buffer unit and the script line unit are integrated to obtain an executable script unit.
3. The method for executing a shaft control script program as described in claim 2, characterized in that, In the step of converting each string in the string array into a token sequence and identifying the corresponding variable declaration format, the identification of the corresponding variable declaration format includes: If a variable declaration statement is detected, the variable corresponding to the variable declaration statement is registered in the variable table corresponding to the buffer identifier; If an identifier is identified and the next token sequence of the identifier is a left parenthesis, then the identifier is determined to be a function name, and the function address is obtained from the preset function manager; If an identifier is identified and the next token sequence of the identifier is not a left parenthesis, then the identifier is determined to be a variable name, and the variable address is obtained from the preset variable manager.
4. The method for executing a shaft control script program as described in claim 2, characterized in that, Before the step of compiling the pre-acquired axis control script program into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units, the method further includes: In response to the new project operation, create a project directory; In response to the pre-compilation operation, the user code files in the current project directory are read, and the user code files are subjected to syntax and integrity checks. If the verification passes, the axis control script program will be generated; If the verification fails, the error message will be logged and the project will be prevented from entering the running state.
5. The method for executing a shaft control script program as described in claim 2, characterized in that, Based on the enabled real-time script buffer unit, the current execution status information of the enabled real-time script buffer unit is obtained, and several corresponding script line units are selected according to the current execution status information, including: Read the current execution status information of the enabled real-time script buffer unit, and use the current execution status information as the row pointer of the enabled real-time script buffer unit; Based on the line pointer, select a number of script line units associated with the enabled real-time script buffer unit.
6. The method for executing a shaft control script program as described in claim 5, characterized in that, The instructions corresponding to the script line units are executed sequentially. Each time an instruction is completed, the current execution status information of the enabled real-time script buffer unit is updated until the script line units corresponding to the enabled real-time script buffer unit have been executed, thus completing the axis control script program execution process, including: The instructions in the script line unit are executed in a preset order; If all instructions in the current script line unit have been executed, the current execution status information of the enabled real-time script buffer unit is updated and the line pointer is incremented so that the line pointer points to the next script line unit to be executed. If the row pointer points to a null value, then the real-time script buffer unit is enabled to complete execution; Once all enabled real-time script buffer units have finished executing, the axis control script program execution process is complete.
7. The method for executing a shaft control script program as described in claim 6, characterized in that, The step of executing the corresponding instructions in the script line unit according to a preset order further includes: Based on a pre-built function registry, several function identifiers are associated with their corresponding executable functions. During the execution of the instructions corresponding to the script line unit, when a function call is parsed, the corresponding executable function is searched from the function registry based on the parsed function identifier; The executable function is then executed via a preset calling interface.
8. An execution system for a shaft control script program, characterized in that, It includes a program compilation module, a real-time script buffer unit traversal module, a script line unit selection module, and an instruction execution module; among which: The program compilation module is used to compile the pre-acquired axis control script program into several executable script units, wherein each executable script unit consists of several real-time script buffer units and several script line units; The real-time script buffer unit traversal module is used to traverse each real-time script buffer unit in the enabled state within any preset control period, taking the real-time script buffer unit as the scheduling object, to obtain the enabled real-time script buffer unit corresponding to each preset control period. The script line unit selection module is used to obtain the current execution status information of the enabled real-time script buffer unit based on the enabled real-time script buffer unit, and select several corresponding script line units according to the current execution status information. The instruction execution module is used to execute the corresponding instructions in the script line unit in sequence. Whenever the instruction execution is completed, the current execution status information of the enabled real-time script buffer unit is updated until the several script line units corresponding to the enabled real-time script buffer unit are executed, thus completing the axis control script program execution process.
9. An execution terminal for an axis control script program, characterized in that, The terminal includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements a method for executing an axis control script program as described in any one of claims 1 to 7.
10. An execution storage medium for an axis control script program, characterized in that, The storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device where the storage medium is located to execute a method for executing an axis control script program as described in any one of claims 1 to 7.