Method and system for configuring motion control code based on intelligent analysis
By automatically generating motion control code through intelligent analysis methods and large language models, the problems of long processing time and difficulty in code reuse in existing technologies are solved, and an efficient and safe code configuration process is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 上海砺群科技有限公司
- Filing Date
- 2026-05-09
- Publication Date
- 2026-07-31
AI Technical Summary
The existing motion control code configuration process relies on the engineer's experience, is time-consuming and makes it difficult to guarantee optimal global performance. Furthermore, the API differences between different hardware platforms make code reuse difficult and migration costs high.
An intelligent analysis-based approach is adopted to decompose the motion task through a large language model, generate standardized code, and automatically search for optimal control parameters using a preset optimization model. Combined with code generation technology, automatic generation and verification are achieved.
It achieves efficient and intelligent parameter tuning, improves configuration efficiency, reduces reliance on expert experience, ensures code security and performance, and reduces logical errors and omissions of boundary conditions.
Smart Images

Figure CN122489119A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of automation technology, and in particular to a method and system for configuring motion control codes based on intelligent analysis. Background Technology
[0002] Motion control systems are core technologies in modern industrial automation, robotics, CNC machine tools, aerospace, and other fields. Their task is to convert planned motion trajectories into precise commands for driving motors, achieving closed-loop control of position, speed, and torque. A typical motion control code configuration process includes multiple stages such as requirements analysis, hardware selection, control algorithm selection, parameter tuning, code writing, simulation verification, and on-site debugging. Among these, the tuning of control parameters and the writing of code are key to achieving high-performance motion control, directly determining the system's response speed, tracking accuracy, stability, and robustness.
[0003] In existing motion control code configuration processes, the configuration of motion control code highly relies on the experience of engineers and manual operation. The code writing process is usually carried out by control engineers writing line by line according to the functional specifications. The parameter setting process is mainly based on setting initial values for the model first, and then manually fine-tuning through repeated step response tests. Among these, the code writing process requires high professional skills from programmers and is prone to introducing logical errors, missing boundary conditions, or safety hazards. At the same time, the APIs of different hardware platforms are very different, making code reuse difficult and migration costs high. Although there are related technologies based on AI to generate code, the parameter setting and optimization process still requires manual setting based on experience and testing processes. Since there is strong coupling between the parameters, manual tuning not only takes several days or even weeks, but also makes it difficult to guarantee globally optimal performance. Therefore, how to achieve efficient and intelligent parameter tuning in the motion control code configuration process is the fundamental problem that this invention aims to solve. Summary of the Invention
[0004] To achieve efficient and intelligent parameter tuning during motion control code configuration, this application provides a motion control code configuration method and system based on intelligent analysis.
[0005] Firstly, this application provides a motion control code configuration method based on intelligent analysis, employing the following technical solution: The motion control code configuration method based on intelligent analysis includes: S1. Decompose the motion task based on the large language model and generate standardized motion control code; S2. Set the initial parameters for the motion task, define the optimization objective and parameter search space, and automatically search for the optimal control parameters based on the preset tuning model; S3. Configure the code based on the optimal control parameters and motion control code.
[0006] Optionally, step S2 includes the following process: S21. Define the parameter space, objective function, and evaluation budget; set initial parameters according to the dimensions of the parameter space and construct the initial dataset; S22. In each iteration, a probabilistic proxy model is fitted based on the dataset, and the predicted mean and predicted variance of each point are output. S23. Calculate the current optimal value, calculate the expected improvement function based on the current optimal value, the predicted mean and the predicted variance, maximize the expected improvement function in the parameter space, and select the global optimal candidate point as the parameter point to be evaluated next time. S24. Apply the parameter points that need to be evaluated next to the test module, obtain new objective function observations, and expand the parameter points and corresponding objective function observations into the dataset; S25. After each iteration, determine whether the convergence condition is met. If the convergence condition is met, terminate the iteration; otherwise, return to step S22. S26. Extract the optimal parameters from the dataset and perform verification tests on them. Once the verification tests are passed, use them as the optimal control parameters.
[0007] Optionally, the initial parameter setting process includes: Set the number of initial parameters to , d is the dimension of the parameter space; For each dimension, divide [0, 1] into equal parts. Given several non-overlapping intervals, randomly shuffle the order of the intervals in each dimension to obtain a... Matrix; Within each selected interval, a point is randomly and uniformly selected and mapped back to the original parameter space to obtain the initial parameters; The initial dataset construction process includes: Each initial parameter is applied to the test module to obtain the corresponding objective function observations. An initial dataset is then constructed based on the initial parameters and the objective function observations.
[0008] Optionally, the process of fitting the probabilistic surrogate model includes: Map the range of parameters to the interval [0, 1], and subtract the mean from the observed values of the objective function and divide by the standard deviation; The similarity between parameters is defined using kernel functions; The unknown parameters in the kernel function are learned by maximizing the log marginal likelihood, and the optimal hyperparameters are solved using gradient descent. The predicted mean and predicted variance are obtained based on the optimal hyperparameters.
[0009] Optionally, step S23 includes the following steps: The minimum value of the objective function observed in the dataset is taken as the current optimal value. ; Calculate the standardization improvement based on the current best value, the predicted mean, and the predicted variance. The standardized improvement amount is substituted into the probability density function PDF and the cumulative distribution function CDF of the normal distribution, respectively, and the corresponding results are obtained. Based on the difference between the current optimal value and the predicted mean and the prediction variance, the improvement expectation function is obtained by weighted summation of the corresponding results of the probability density function PDF and the cumulative distribution function CDF.
[0010] Optionally, step S23 may further include: Generate by random sampling within the parameter space One candidate point; For each candidate point, calculate the value of the improved expectation function, and select the Q points with the largest improved expectation function values as initial points; for each initial point, use the gradient ascent method in the parameter space to maximize the improved expectation function, and stop the iteration process when the termination condition is met; Compare the values of the improved expectation function of all local optima and boundary points, and select the point corresponding to the maximum value as the global optimum candidate point.
[0011] Optionally, the convergence condition includes: Any stopping condition is met, including: The number of iterations is greater than or equal to the preset number; The maximum value of the improved expectation function is less than the corresponding expectation threshold; The observed value of the objective function is less than the corresponding observation threshold after a preset number of iterations; The parameter variation is less than the preset value.
[0012] Optionally, the process of step S26 includes: The test code is configured according to the optimal parameters and motion control code, and the test process is carried out according to the configured test code. The test process includes several scenarios, and each scenario is tested several times. There are several test indicators. Assign weights to each scenario and each metric, ensuring that the sum of the weights for all scenarios is 1 and the sum of the weights for all metrics is 1. Calculate the basic exceedance ratio for each indicator in each scenario; Based on the different indicators exceeding the limit, collaborative penalties are applied to obtain collaborative penalty items; The basic penalty items are obtained based on the basic over-limit ratio of indicators for each scenario. The reliability of the parameter test results is judged based on the sum of the basic penalty items and the collaborative penalty items for all scenarios.
[0013] Secondly, this application provides a motion control code configuration system based on intelligent analysis, which adopts the following technical solution: A motion control code configuration system based on intelligent analysis, wherein the system employs any one of the above-described motion control code configuration methods based on intelligent analysis.
[0014] In summary, this application includes at least one of the following beneficial technical effects: This invention finds near-global optimal parameters with a small number of evaluations through efficient and intelligent parameter tuning, and combines it with code generation technology driven by a large language model to achieve automatic generation and verification of structured motion control programs from natural language requirements. It can significantly improve configuration efficiency, reduce reliance on expert experience, ensure code security and performance, and overcome the shortcomings of existing technologies. Attached Figure Description
[0015] Figure 1 This is a flowchart of the steps involved in configuring motion control code based on intelligent analysis.
[0016] Figure 2 This is a flowchart of the process of obtaining the optimal control parameters in step S2. Detailed Implementation
[0017] The embodiments of this application are described in detail below, and examples of the embodiments are shown in the accompanying drawings.
[0018] In the description of this specification, the references to "certain embodiments," "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples" refer to specific features, structures, materials, or characteristics described in connection with the described embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0019] This application discloses a motion control code configuration method based on intelligent analysis, referring to... Figure 1The method includes: S1, decomposing the motion task based on a large language model to generate standardized motion control code; S2, setting initial parameters for the motion task, defining optimization objectives and parameter search space, and automatically searching for optimal control parameters based on a preset tuning model; S3, configuring the code according to the optimal control parameters and motion control code. This embodiment finds near-global optimal parameters with a small number of evaluations through efficient and intelligent parameter tuning, and combines large language model-driven code generation technology to achieve automatic generation and verification from natural language requirements to structured motion control programs. It can significantly improve configuration efficiency, reduce reliance on expert experience, ensure code security and performance, and overcome the shortcomings of existing technologies.
[0020] In this embodiment, step S1 is implemented using the AI-assisted tool MCCoder. The large language model decomposes the motion task into a series of simple, executable subtasks based on the description of the motion task. This decomposition process defines the API call order and also serves as a standard for evaluating the correctness of the final code. Simultaneously, during the generation process, MCCoder retrieves the "most similar code example" and the "most relevant API documentation" from the private and mature WMX3 motion library and provides them to the LLM as a contextual reference for generating the code, ensuring that the generated code is based on facts. After the initial code is generated, MCCoder's verifier automatically executes and checks the code, forming a closed loop of "generation-verification-correction". Finally, the verification process is used to generate standardized motion control code.
[0021] In one embodiment, refer to Figure 2 The process of obtaining optimal control parameters in step S2 includes: S21, setting the parameter space, objective function, and evaluation budget; setting initial parameters according to the dimensions of the parameter space and constructing an initial dataset; wherein, the parameter space is... d is the dimension of the parameter space. These are the minimum and maximum limits of the first parameter, respectively; the objective function. There is no specific expression; it is obtained based on each real experiment or simulation and is used to evaluate the performance cost. The smaller the value, the better the control effect. The evaluation budget represents the limit on the number of real experiments or simulations. In this embodiment, the evaluation budget is 50 times.
[0022] In addition, the process of setting the initial parameters includes: setting the number of initial parameters to... , Taking the most common PID parameters in motion control as an example, there are three parameters, so the parameter space has a dimension of 3; for each dimension, [0, 1] is divided into equal parts. Non-overlapping intervals Randomly shuffle the interval order of each dimension to obtain a The matrix, in which a point is uniformly and randomly selected within each selected interval. And map it back to the original parameter space. This represents the position of the i-th sample in the j-th dimension, and the initial parameters are obtained. Through the above process, the selection of initial parameters can ensure that the combination of intervals of all dimensions constitutes a Latin hypercube, thereby covering the entire space more uniformly.
[0023] In addition, the initial dataset construction process includes: applying each initial parameter to the test module to obtain the corresponding objective function observations. , To observe the noise, during simulation, In real experiments, Based on empirical data, an initial dataset is constructed using the initial parameters and observed values of the objective function. .
[0024] In step S22, for each iteration, a probabilistic surrogate model is fitted based on the dataset, outputting the predicted mean and predicted variance for each point. The fitting process of the probabilistic surrogate model includes: first, mapping the range of parameters to the interval [0, 1] to standardize the input and improve the stability of the kernel function; then, subtracting the mean from the observed values of the objective function and dividing by the standard deviation to make the data have zero mean and unit variance, thus achieving output standardization; then, defining the similarity between parameters through the kernel function. In this embodiment, the kernel function used is Matérn5 / 2, and the learned hyperparameter vector is the length dimension l and the signal variance. and noise variance The hyperparameter vector is initialized, and then the unknown parameters in the kernel function are learned by maximizing the log marginal likelihood. First, a dataset is given. Assuming a zero-mean prior, the observed values... ,in, K is a symmetric positive definite matrix with the following elements: , Let I be the kernel function, and I be the identity matrix, where all elements on the main diagonal are 1 and all other elements are 0; the log-marginal likelihood is: Then, gradient descent is used to solve for the optimal hyperparameters. In this embodiment, the L-BFGS optimizer is used to calculate the partial derivative of the log-marginal likelihood with respect to each hyperparameter, thereby obtaining the optimal hyperparameters. Based on the optimal hyperparameters, the following steps are taken: and K, nt represents the current iteration number, from which the predicted mean is obtained. and prediction variance ,in, , .
[0025] In step S23, the current optimal value is first calculated. The minimum value of the objective function observed in the dataset is taken as the current optimal value. ,Right now Then, the standardized improvement amount is calculated based on the current optimal value, the predicted mean, and the predicted variance. Substituting the standardized improvement amount into the probability density function PDF and the cumulative distribution function CDF of the normal distribution, respectively, yields the following results: and Based on the difference between the current optimal value and the predicted mean and prediction variance The improved expectation function is obtained by weighted summing the results corresponding to the probability density function (PDF) and the cumulative distribution function (CDF). Therefore, the improved expectation function is: Then, the improved expectation function is maximized in the parameter space, and the globally optimal candidate point is selected as the parameter point to be evaluated next; this process first generates the parameter point through random sampling in the parameter space. One candidate point; Based on empirical data, the value of the improved expectation function is calculated for each candidate point. It should be noted that during the calculation process, when the prediction variance is very small, EI may be unstable due to numerical issues. Therefore, when the prediction variance is less than 10^(-12), EI is set to 0.
[0026] Then, Q points with the largest improved expected function values are selected as initial points. The empirical range of Q is 10~20, and 15 is selected in this embodiment. These points serve as the starting points for local optimization, and some random points can be added to increase diversity. For each initial point, since... about Since it is differentiable, the gradient ascent method is used to maximize the improved expectation function in the parameter space. The iteration process stops when the termination condition is met. The termination condition is that the gradient norm is less than 10^(-6), the maximum number of iterations is reached, and the step size change is less than a preset value. The preset value is set according to experience. The values of the improved expectation function of all local optima and boundary points are compared, and the point corresponding to the maximum value is selected as the global optimal candidate point.
[0027] In step S24, the parameter points to be evaluated next are first applied to the test module to obtain new objective function observations, and the parameter points and corresponding objective function observations are expanded into the dataset. In step S25, after each iteration, it is determined whether the convergence condition is met. The convergence condition includes: meeting any stopping condition, which includes: the number of iterations being greater than or equal to a preset number, which is the evaluation budget; and the maximum value of the improved expected function being less than the corresponding expected threshold, which in this embodiment is the corresponding expected threshold. The objective function observation value is less than the corresponding observation threshold after a preset number of iterations. In this embodiment, the preset number of iterations is set to 5, and the corresponding observation threshold is... The change in parameters is less than the preset value. For the normalized parameters, the preset value ranges from 0.01 to 0.05, and in this embodiment it is set to 0.04. If the convergence condition is met, the iteration is terminated; otherwise, return to step S22. Through the above iterative process, an approximate global optimal solution can be found within a small number of evaluations.
[0028] Finally, step S26 is performed to extract the optimal parameters from the dataset and conduct verification tests. Once the verification test is passed, these parameters are used as the optimal control parameters. This includes: first, configuring test code based on the optimal parameters and motion control code; then, conducting the test process according to the configured test code. The test process includes several scenarios, with each scenario repeated several times, and several test indicators; finally, assigning weights to each scenario and each indicator, ensuring that the sum of the weights for all scenarios is 1. The sum of the weights of all indicators is 1; that is... There are M test scenarios, G performance metrics, and each scenario is tested V times. As the weight of the scene, The weights of the indicators for different scenarios are given; there are four performance indicators in this embodiment, including overshoot, settling time, integral absolute error and peak tracking error.
[0029] Firstly, through Calculate the basic out-of-limit ratio for each indicator in each scenario. ,in, Let be the mean of the q-th indicator in the s-th scenario. Let q be the threshold value for the q-th indicator. .
[0030] Then, collaborative penalties are applied based on the different out-of-limit states of the indicators to obtain collaborative penalty terms. The process of obtaining collaborative penalty terms first involves forming a vector from the out-of-limit portions of all indicators under scenario s, i.e. The coupling penalty term is defined as a quadratic form: ;in, Let be the index coupling matrix for the s-th test scenario. Symmetrical with a diagonal of 0, its setting depends on different scenario states; therefore, through... The magnitude of the term can measure the collaborative penalty between different indicators exceeding the limit. If two indicators exceed the limit at the same time, the coupling term will contribute additional penalty.
[0031] Then, based on the basic over-limit ratio of the indicators for each scenario, the basic penalty item is obtained. , Then, obtain the sum of all basic penalty terms and collaborative penalty terms for all scenarios. Define risk index The risk index R is compared with the risk threshold. In this embodiment, the risk threshold is set to 0.3. Therefore, when the risk index does not exceed the risk threshold, the parameter passes the verification. Through the above process, the reliability of the parameter test results can be judged.
[0032] This application also discloses a motion control code configuration system based on intelligent analysis, which adopts the above-described motion control code configuration method based on intelligent analysis.
[0033] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A motion control code configuration method based on intelligent analysis, characterized in that, include: S1. Decompose the motion task based on the large language model and generate standardized motion control code; S2. Set the initial parameters for the motion task, define the optimization objective and parameter search space, and automatically search for the optimal control parameters based on the preset tuning model; S3. Configure the code based on the optimal control parameters and motion control code.
2. The motion control code configuration method based on intelligent analysis according to claim 1, characterized in that, Step S2 includes the following process: S21. Define the parameter space, objective function, and evaluation budget; set initial parameters according to the dimensions of the parameter space and construct the initial dataset; S22. In each iteration, a probabilistic proxy model is fitted based on the dataset, and the predicted mean and predicted variance of each point are output. S23. Calculate the current optimal value, calculate the expected improvement function based on the current optimal value, the predicted mean and the predicted variance, maximize the expected improvement function in the parameter space, and select the global optimal candidate point as the parameter point to be evaluated next time. S24. Apply the parameter points that need to be evaluated next to the test module, obtain new objective function observations, and expand the parameter points and corresponding objective function observations into the dataset; S25. After each iteration, determine whether the convergence condition is met. If the convergence condition is met, terminate the iteration; otherwise, return to step S22. S26. Extract the optimal parameters from the dataset and perform verification tests on them. Once the verification tests are passed, use them as the optimal control parameters.
3. The motion control code configuration method based on intelligent analysis according to claim 2, characterized in that, The process of setting initial parameters includes: Set the number of initial parameters to , d is the dimension of the parameter space; For each dimension, divide [0, 1] into equal parts. Given several non-overlapping intervals, randomly shuffle the order of the intervals in each dimension to obtain a... Matrix; Within each selected interval, a point is randomly and uniformly selected and mapped back to the original parameter space to obtain the initial parameters; The initial dataset construction process includes: Each initial parameter is applied to the test module to obtain the corresponding objective function observations. An initial dataset is then constructed based on the initial parameters and the objective function observations.
4. The motion control code configuration method based on intelligent analysis according to claim 2, characterized in that, The process of fitting the probabilistic proxy model includes: Map the range of parameters to the interval [0, 1], and subtract the mean from the observed values of the objective function and divide by the standard deviation; The similarity between parameters is defined using kernel functions; The unknown parameters in the kernel function are learned by maximizing the log marginal likelihood, and the optimal hyperparameters are solved using gradient descent. The predicted mean and predicted variance are obtained based on the optimal hyperparameters.
5. The motion control code configuration method based on intelligent analysis according to claim 2, characterized in that, Step S23 includes the following process: The minimum value of the objective function observed in the dataset is taken as the current optimal value. ; Calculate the standardization improvement based on the current best value, the predicted mean, and the predicted variance. The standardized improvement amount is substituted into the probability density function PDF and the cumulative distribution function CDF of the normal distribution, respectively, and the corresponding results are obtained. Based on the difference between the current optimal value and the predicted mean and the prediction variance, the improvement expectation function is obtained by weighted summation of the corresponding results of the probability density function PDF and the cumulative distribution function CDF.
6. The motion control code configuration method based on intelligent analysis according to claim 5, characterized in that, Step S23 also includes: Generate by random sampling within the parameter space One candidate point; For each candidate point, calculate the value of the improved expectation function, and select the Q points with the largest improved expectation function values as initial points; for each initial point, use the gradient ascent method in the parameter space to maximize the improved expectation function, and stop the iteration process when the termination condition is met; Compare the values of the improved expectation function of all local optima and boundary points, and select the point corresponding to the maximum value as the global optimum candidate point.
7. The motion control code configuration method based on intelligent analysis according to claim 2, characterized in that, The convergence conditions include: Any stopping condition is met, including: The number of iterations is greater than or equal to the preset number; The maximum value of the improved expectation function is less than the corresponding expectation threshold; The observed value of the objective function is less than the corresponding observation threshold after a preset number of iterations; The parameter variation is less than the preset value.
8. The motion control code configuration method based on intelligent analysis according to claim 2, characterized in that, Step S26 includes the following process: The test code is configured according to the optimal parameters and motion control code, and the test process is carried out according to the configured test code. The test process includes several scenarios, and each scenario is tested several times. There are several test indicators. Assign weights to each scenario and each metric, ensuring that the sum of the weights for all scenarios is 1 and the sum of the weights for all metrics is 1. Calculate the basic exceedance ratio for each indicator in each scenario; Based on the different indicators exceeding the limit, collaborative penalties are applied to obtain collaborative penalty items; The basic penalty items are obtained based on the basic over-limit ratio of indicators for each scenario. The reliability of the parameter test results is judged based on the sum of the basic penalty items and the collaborative penalty items for all scenarios.
9. A motion control code configuration system based on intelligent analysis, characterized in that, The system employs the motion control code configuration method based on intelligent analysis as described in any one of claims 1-8.