Robot control method, device and robot
By training the residual prediction model in the inverse dynamics model, predicting and compensating the torque residual, the problem of inaccurate prediction of the inverse dynamics model in complex environments is solved, and the control accuracy and operating efficiency of the robot are improved.
Patent Information
- Application Number
- CN202410887952.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-07-04
AI Technical Summary
When existing inverse dynamics models deal with complex variables and uncertain factors in the actual environment, their predictions are inaccurate, which affects the control performance of the robot.
By training the residual prediction model based on the predicted torque and actual torque residual of the inverse dynamics model, the torque residual at the next moment is predicted and compensated into the predicted torque to obtain more accurate torque control.
The control accuracy and operating efficiency of the robot are improved, and precise control of the robot is achieved.
Smart Images

Figure CN118404592B
Abstract
Description
Technical Field
[0001] The present application relates to the field of robotics technology, and in particular to a robot control method, device and robot. Background Art
[0002] With the rapid development of robotics, robots have become an indispensable part of various fields. They are able to perform various tasks according to specific programs or instructions, including but not limited to assembly on production lines, cleaning work, and medical operations. By effectively controlling the behavior of robots, their work efficiency can be significantly improved, and the application scope of robots in various fields can be further expanded. This precise control can not only increase productivity, but also improve safety and precision, thus creating more convenience and possibilities for humans.
[0003] The inverse dynamics model of the robot plays a key role in improving the control accuracy and operation efficiency of the robot. By predicting and calculating the force and torque required for the robot to perform a specific task, the inverse dynamics model enables the robot to perform complex tasks more accurately and efficiently. The application of inverse dynamics models is particularly important in fields such as high-performance manufacturing, automated assembly, and fine manipulation. However, existing inverse dynamics models still face challenges in dealing with complex variables and uncertain factors in actual environments. For example, uncertain factors such as environmental noise, joint friction, dynamic load changes, flexibility of the robotic arm, and joint clearance may lead to inaccurate predictions of the inverse dynamics model, which in turn affects the control performance of the robot. Therefore, there is an urgent need for a method to enhance the control accuracy and operation efficiency of the robot. Summary of the invention
[0004] In view of this, the present application provides a robot control method, device and robot to improve the compensation accuracy of the inverse dynamics model and enhance the control accuracy and operating efficiency of the robot.
[0005] Specifically, the present application is implemented through the following technical solutions:
[0006] A first aspect of the present application provides a robot control method, the method comprising:
[0007] For each joint of the robot, based on the inverse dynamics model, according to the dynamic parameters of the joint at N consecutive historical moments before the current moment, the torque required to drive the joint at the next moment is calculated to obtain the predicted torque of the joint at the next moment;
[0008] For each of the M consecutive historical moments before the current moment, according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment, the torque residual of the joint at the historical moment is obtained;
[0009] Based on the pre-trained residual prediction model, according to the M torque residuals of the joint at the M historical moments, predict the torque residual of the joint at the next moment;
[0010] The torque residual of the joint at the next moment is compensated to the predicted torque to obtain the control torque required to drive the joint at the next moment, and the joint is controlled according to the control torque.
[0011] A second aspect of the present application provides a robot control device, the device comprising a prediction module, an acquisition module and a control module; wherein:
[0012] The prediction module is used to calculate the torque required to drive the joint at the next moment for each joint of the robot based on the inverse dynamics model and the dynamic parameters of the joint at N consecutive historical moments before the current moment, so as to obtain the predicted torque of the joint at the next moment;
[0013] The acquisition module is used to obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment for each of the M consecutive historical moments before the current moment;
[0014] The prediction module is further used to predict the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments based on a pre-trained residual prediction model;
[0015] The control module is used to compensate the torque residual of the joint at the next moment into the predicted torque, obtain the control torque required to drive the joint at the next moment, and control the joint according to the control torque.
[0016] The third aspect of the present application provides a robot, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the methods provided in the first aspect of the present application are implemented.
[0017] The fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any one of the methods provided in the first aspect of the present application.
[0018] The robot control method, device and robot provided in the present application train a residual prediction model in advance. In this way, for each joint of the robot, based on the inverse dynamics model, according to the dynamic parameters of the joint at N consecutive historical moments before the current moment, after the predicted torque of the joint at the next moment is calculated, it is possible to further obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment for each of the M consecutive historical moments before the current moment, and then based on the residual prediction model, predict the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments. In this way, after predicting the torque residual of the joint at the next moment, the torque residual of the joint at the next moment can be compensated to the predicted torque, so as to obtain the control torque required to drive the joint at the next moment, and control the joint according to the control torque. In this way, through the pre-trained residual prediction model, the torque residual of the joint at the next moment can be predicted, and then the torque residual can be used to compensate the predicted torque, so that the final control torque is more accurate, which can improve the compensation accuracy, enhance the control accuracy and operation efficiency of the robot, and achieve precise control of the robot. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 A flowchart of a first embodiment of a robot control method provided in this application;
[0020] Figure 2 A schematic diagram of a residual prediction model shown as an exemplary embodiment of the present application;
[0021] Figure 3 A flowchart of a second embodiment of the robot control method provided in this application;
[0022] Figure 4 A loss function curve diagram when training a residual prediction model for joint 1 data shown in an exemplary embodiment of the present application;
[0023] Figure 5 A loss function curve diagram when training a residual prediction model for joint 2 data shown in an exemplary embodiment of the present application;
[0024] Figure 6 A loss function curve diagram when training a residual prediction model for joint 3 data according to an exemplary embodiment of the present application;
[0025] Figure 7 A loss function curve diagram when training a residual prediction model for joint 4 data according to an exemplary embodiment of the present application;
[0026] Figure 8A loss function curve diagram when training a residual prediction model for joint 5 data according to an exemplary embodiment of the present application;
[0027] Fig. 9 A loss function curve diagram when training a residual prediction model for data of joint 6 shown in an exemplary embodiment of the present application;
[0028] Fig.10 A loss function curve diagram when training a residual prediction model for data of joint 7 shown in an exemplary embodiment of the present application;
[0029] Fig.11 A schematic diagram of the predicted torque and the actual torque of the joint 1 in the test data set shown in an exemplary embodiment of the present application;
[0030] Fig.12 A schematic diagram of the predicted torque and the actual torque of the joint 2 in the test data set shown in an exemplary embodiment of the present application;
[0031] Fig.13 A schematic diagram of the predicted torque and the actual torque of the joint 3 in the test data set shown in an exemplary embodiment of the present application;
[0032] Fig.14 A schematic diagram of the predicted torque and the actual torque of the joint 4 in the test data set shown in an exemplary embodiment of the present application;
[0033] Fig.15 A schematic diagram of the predicted torque and the actual torque of the joint 5 in the test data set shown in an exemplary embodiment of the present application;
[0034] Fig.16 A schematic diagram of the predicted torque and the actual torque of the joint 6 in the test data set shown in an exemplary embodiment of the present application;
[0035] Fig.17 A schematic diagram of the predicted torque and the actual torque of the joint 7 in the test data set shown in an exemplary embodiment of the present application;
[0036] Fig.18 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 1 according to an exemplary embodiment of the present application;
[0037] Fig.19 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 2 according to an exemplary embodiment of the present application;
[0038] Fig. 20 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 3 according to an exemplary embodiment of the present application;
[0039] Fig.21 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 4 according to an exemplary embodiment of the present application;
[0040] Fig. 22 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 5 according to an exemplary embodiment of the present application;
[0041] Fig.23 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 6 according to an exemplary embodiment of the present application;
[0042] Fig.24 A schematic diagram showing a comparison between an actual torque residual and a predicted torque residual of a robot joint 7 according to an exemplary embodiment of the present application;
[0043] Fig.25 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 1 shown in an exemplary embodiment of the present application;
[0044] Fig.26 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 2 shown in an exemplary embodiment of the present application;
[0045] Fig. 27 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 3 shown in an exemplary embodiment of the present application;
[0046] Fig.28 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 4 shown in an exemplary embodiment of the present application;
[0047] Fig.29 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 5 shown in an exemplary embodiment of the present application;
[0048] Fig.30 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 6 shown in an exemplary embodiment of the present application;
[0049] Fig.31 A comparison diagram of the torque error before compensation and the torque error after compensation of the robot joint 7 shown in an exemplary embodiment of the present application;
[0050] Fig.32 A comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 1 shown in an exemplary embodiment of the present application;
[0051] Fig.33This is a comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 2 shown in an exemplary embodiment of the present application;
[0052] Fig.34 This is a comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 3 shown in an exemplary embodiment of the present application;
[0053] Fig.35 A comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 4 shown in an exemplary embodiment of the present application;
[0054] Fig.36 A comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 5 shown in an exemplary embodiment of the present application;
[0055] Fig.37 A comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 6 shown in an exemplary embodiment of the present application;
[0056] Fig.38 A comparison diagram of the controlled torque and the actual torque after compensation of the robot joint 7 shown in an exemplary embodiment of the present application;
[0057] Fig.39 This is a schematic structural diagram of the first embodiment of the robot control device provided in this application. DETAILED DESCRIPTION
[0058] Here, exemplary embodiments are described in detail, and examples thereof are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application.
[0059] The terms used in this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in this article refers to and includes any or all possible combinations of one or more associated listed items.
[0060] It should be understood that although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0061] Specific embodiments are given below to introduce the technical solution of the present application in detail.
[0062] Figure 1 This is a flow chart of the first embodiment of the robot control method provided by this application. Please refer to Figure 1 , the method provided in this embodiment may include:
[0063] S101. For each joint of the robot, based on the inverse dynamics model, according to the dynamic parameters of the joint at N consecutive historical moments before the current moment, calculate the torque required to drive the joint at the next moment, and obtain the predicted torque of the joint at the next moment.
[0064] It should be noted that the robot control method and device provided in the present application are applied to a robot, which is an articulated robot including multiple joints. For example, in a possible implementation, the robot includes 7 joints.
[0065] Specifically, the inverse dynamics model is selected according to actual needs, and this embodiment is not limited to this. For example, in one embodiment, the inverse dynamics model is an inverse dynamics model constructed based on the Newton-Euler algorithm and the Coulomb friction algorithm.
[0066] It can be understood that the Newton-Euler algorithm includes the principles of Newtonian mechanics and Euler angle dynamics, which are used to derive the robot's position, velocity, acceleration, and the forces and torques acting on each joint in space. The Coulomb friction algorithm is used to describe the friction between two objects, which is proportional to the normal pressure between them and is related to the product of the friction coefficient.
[0067] It can be understood that, for each joint, the inverse dynamics model can predict the torque required to drive the joint at the next moment based on the dynamic parameters of the joint at N historical moments.
[0068] The specific value of N is set according to actual needs, and in this embodiment, the specific value of N is not limited. For example, in one embodiment, N is 5. Further, the dynamic parameters of the joint may include angular velocity, angular displacement and angular acceleration.
[0069] In specific implementation, for each joint of the robot, the dynamic parameters of the joint at N consecutive historical moments before the current moment are input into the inverse dynamics model, and the inverse dynamics model outputs the predicted torque of the joint at the next moment.
[0070] For example, in one embodiment, N is 5, and when the current moment is t, in this step, for a certain joint, the dynamic parameters of the joint at t-4, t-3, t-2, t-1 and t are input into a pre-trained inverse dynamics model, and the inverse dynamics model outputs the predicted torque T1 of the joint at t+1.
[0071] S102. For each of the M consecutive historical moments before the current moment, obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment.
[0072] Specifically, M is set according to actual needs, and in this embodiment, the specific value of M is not limited. For example, in one embodiment, M is 3. It should be noted that M and N can be the same or different, and in this embodiment, they are not limited.
[0073] It is understandable that, for a certain joint, for each of the M consecutive historical moments before the current moment, the predicted torque of the joint at the historical moment can be obtained based on the method in step S101. Further, for a certain joint, for each of the M consecutive historical moments before the current moment, the actual torque of the joint at the historical moment can be obtained based on the mechanical sensor (wherein, the torque of the joint at the historical moment measured by the mechanical sensor is the actual torque).
[0074] Furthermore, for a certain joint, its torque residual at a certain historical moment is equal to the difference between the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment.
[0075] For example, in combination with the above example, when M is 3 and the current moment is t, in this step, for a certain joint, the torque residuals of the joint at moments t-2, t-1 and t are obtained. In specific implementation, for moment t-2, the actual torque at moment t-2 is subtracted from the predicted torque at moment t-2 to obtain the torque residual at moment t-2. Among them, the actual torque at moment t-2 can be directly read according to the mechanical sensor, and the predicted torque at moment t-2 can be obtained by the method in step S101, that is, the dynamic parameters at moments t-7, t-6, t-5, t-4 and t-3 are input into the pre-trained inverse dynamics model, and the inverse dynamics model outputs the predicted torque at moment t-2.
[0076] S103 . Based on a pre-trained residual prediction model, predict the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments.
[0077] Specifically, for a certain joint, the pre-trained residual prediction model can predict the torque residual of the joint at the next moment based on the M torque residuals of the joint at M historical moments. For example, in one embodiment, the residual prediction model can be an LSTM network, which can output a torque residual based on the M torque residuals, that is, for a certain joint, it can predict the torque residual of the joint at the next moment based on the M torque residuals of the joint at M historical moments.
[0078] Specifically, the LSTM (Long Short-Term Memory) model is a special recurrent neural network that selects to retain or forget historical information based on various gated weight matrices. At each time step, the LSTM model updates the current memory cell state and output through mechanisms such as the input gate, forget gate, and output gate based on the current input, the output of the previous moment, and the memory cell state. Among them, the input gate determines which parts of the current input information need to be recorded by the memory cell, the forget gate determines which information of the memory cell state at the previous moment needs to be retained, and the output gate converts the updated memory cell state into the output at the current moment.
[0079] Specifically, the LSTM model is used to predict the torque residual at the next moment based on the input M torque residuals. The specific formula of the gated weight matrix of the LSTM model is as follows:
[0080] Forget Gate: ,
[0081] Among them, the is the activation value of the forget gate; is the weight matrix of the forget gate; is the bias vector of the forget gate; is the sigmoid activation function; is the hidden state of the previous moment; The input at the current moment.
[0082] Input Gate: ,
[0083] Among them, the is the activation value of the input gate; is the sigmoid activation function; is the weight matrix of the input gate; is the hidden state of the previous moment; is the input at the current moment; is the bias vector of the input gate.
[0084] Cell Alternative Update Vector: ,
[0085] Among them, the is the candidate memory cell state; is the weight matrix of the memory unit state; is the hidden state of the previous moment; is the input at the current moment; is the bias vector of the memory cell state.
[0086] Cell status update: ,
[0087] Among them, the is the memory unit state at the current moment; is the activation value of the forget gate; is the memory unit state at the previous moment; is the activation value of the input gate; is the candidate memory cell state.
[0088] Output Gate: ,
[0089] Among them, the is the activation value of the output gate; is the sigmoid activation function; is the weight matrix of the output gate; is the hidden state of the previous moment; is the input at the current moment; is the bias vector of the output gate.
[0090] Cell status output: ,
[0091] Among them, the is the hidden state at the current moment; is the activation value of the output gate; is the memory unit state at the current moment.
[0092] Torque residual prediction value (i.e. predicted torque residual): ,
[0093] Among them, the is the torque residual prediction value; is the hidden state at the current moment; is the torque residual.
[0094] Specifically, Figure 2 This is a schematic diagram of a residual prediction model shown in an exemplary embodiment of the present application. Figure 2Optionally, in a possible implementation, the residual prediction model includes a cascaded first model and a second model; wherein the first model includes n LSTM models in parallel; and the second model is a model composed of three fully connected layers.
[0095] Please continue to refer to Figure 2 , when the specific structure of the residual prediction model is Figure 2 When shown, the specific implementation process of this step may include:
[0096] (1) For each LSTM model, the M torque residuals are input into the LSTM model, so that the LSTM model predicts the torque residual of the joint at the next moment according to the M torque residuals, and outputs the torque residual prediction value corresponding to the LSTM model; wherein the n LSTM models are trained based on the Bagging algorithm, and the training sample sets of the n LSTM models are different.
[0097] In specific implementation, for a certain joint, when it is necessary to predict the torque residual of the joint at the next moment, the M torque residuals of the joint at M historical moments are respectively input into each LSTM model. For a certain LSTM model, referring to the previous description, it can predict the torque residual of the joint at the next moment based on the M torque residuals. For the convenience of explanation, the torque residual output by the i-th LSTM model is recorded as Yi, where i is equal to 1 to n.
[0098] (2) The n torque residual prediction values corresponding to the n LSTM models are simultaneously input into the second model, so that the second model integrates the n torque residual prediction values, and outputs the integrated torque residual prediction values as the torque residual of the joint at the next moment.
[0099] As described above, each LSTM model can predict the torque residual of the joint at the next moment based on the M torque residuals of the joint at M historical moments, that is, n LSTM models can output n torque residual prediction values.
[0100] Furthermore, in this step, the n torque residual prediction values are simultaneously input into the second model. Referring to the previous description, the second model includes an input layer, a hidden layer and an output layer. It can be understood that the dimension of the input layer of the second model is , the n torque residual prediction values output by the first model can be expressed as ,Furthermore, the weight matrix of the input layer is expressed as , the weight matrix of the hidden layer is expressed as ; The processing process of the second model can be expressed as:
[0101] ,
[0102] Among them, the is the fitting result of the fully connected layer; is the dimension of the input layer of the second model; is the weight matrix of the input layer of the second model; is the weight matrix of the hidden layer of the second model; It is the torque residual prediction value output by the first model.
[0103] It can be understood that after the input layer and the hidden layer are processed, n values can be obtained. Furthermore, in the output layer, the second model uses the bagging calculation framework to take the average value of these n values to obtain the integrated torque residual prediction value, and outputs the torque residual prediction value as the torque residual of the joint at the next moment. The processing process of the output layer can be expressed as:
[0104] ,
[0105] Where n is the number of LSTM models included in the first model.
[0106] The method provided by the present application, when setting the residual prediction model, can obtain n torque residual prediction values by setting n different LSTM models, and adjust and average the n torque residual prediction values based on the second model to obtain the final torque residual prediction value. The torque residual prediction value obtained by this method is more accurate, which can further improve the prediction accuracy of the residual prediction model, improve the compensation accuracy of the inverse dynamics model, and enhance the control accuracy and operation efficiency of the robot.
[0107] S104, compensating the torque residual of the joint at the next moment into the predicted torque to obtain the control torque required to drive the joint at the next moment, and controlling the joint according to the control torque.
[0108] Specifically, the control torque required to drive the joint at the next moment is equal to the sum of the predicted torque of the joint at the next moment and the torque residual of the joint at the next moment.
[0109] For example, combining the above example, the current time is t, the predicted torque of the joint at time t+1 is T1, and the torque residual of the joint at time t+1 is T2, then the control torque required to drive the joint at the next moment can be obtained as T1+T2, and the joint is controlled according to the control torque.
[0110] The robot control method provided in this embodiment trains a residual prediction model in advance, so that for each joint of the robot, after obtaining the predicted torque of the joint at the next moment based on the inverse dynamics model and the dynamic parameters of the joint at N consecutive historical moments before the current moment, it is possible to further obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment for each of the M consecutive historical moments before the current moment, and then predict the torque residual of the joint at the next moment based on the residual prediction model and the M torque residuals of the joint at the M historical moments. In this way, after predicting the torque residual of the joint at the next moment, the torque residual of the joint at the next moment can be compensated to the predicted torque to obtain the control torque required to drive the joint at the next moment, and control the joint according to the control torque. In this way, through the pre-trained residual prediction model, the torque residual of the joint at the next moment can be predicted, and then the torque residual can be used to compensate the predicted torque, so that the final control torque is more accurate, which can improve the compensation accuracy, enhance the control accuracy and operation efficiency of the robot, and achieve precise control of the robot.
[0111] Figure 3 This is a flow chart of the second embodiment of the robot control method provided by this application. Please refer to Figure 3 The method provided in this embodiment, based on the above embodiment, the training process of the residual prediction model includes:
[0112] S301. Construct an original data set; wherein, the original data set includes the actual torque, predicted torque and actual torque residual of each joint of the robot at each moment within a preset time period; wherein, the predicted torque of each joint of the robot at each moment within the preset time period is obtained based on the prediction of the inverse dynamics model.
[0113] Specifically, the preset time period is set according to actual needs, and is not limited in this embodiment. For example, in one embodiment, the preset time period is from 8 am to 8 pm. The original data set includes the actual torque, predicted torque, and actual torque residual of each joint of the robot at each moment in the preset time period.
[0114] It should be noted that the predicted torque of a joint at a certain moment within a preset time period refers to the predicted torque obtained based on the inverse dynamics model, the actual torque of the joint at this moment refers to the torque measured by the mechanical sensor, and the actual torque residual of the joint at this moment refers to the difference between the predicted torque and the actual torque of the joint at this moment.
[0115] Optionally, in a possible implementation manner, the process of obtaining the original data set includes:
[0116] (1) Obtaining the dynamic parameters and actual torque of each joint of the robot at each moment within the preset time period.
[0117] Specifically, referring to the above description, the dynamic parameters include angular velocity, angular displacement and angular acceleration. In specific implementation, for a certain joint, the angular velocity, angular displacement and angular acceleration of the joint at each moment in a preset time period can be obtained to obtain the dynamic parameters of the joint at that moment.
[0118] Furthermore, the dynamic parameters and actual torque of each joint of the robot at each moment within a preset time period can be directly read by the sensor.
[0119] (2) For each joint, based on the inverse dynamics model, calculate the predicted torque of the joint at each moment within the preset time period.
[0120] Specifically, referring to the above description, based on the inverse dynamics model, the method in step S101 can be used to predict the predicted torque of each joint of the robot at each moment within a preset time period.
[0121] (3) For each moment in the preset time period, the actual torque residual of the joint at that moment is obtained according to the predicted torque of the joint at that moment and the actual torque of the joint at that moment.
[0122] In a specific implementation, for a certain joint, the actual torque of the joint at a certain moment is subtracted from the predicted torque of the joint at that moment to obtain the actual torque residual of the joint at that moment.
[0123] (4) constructing an original data set using the actual torque, predicted torque, and actual torque residual of each joint of the robot at each moment within the preset time period.
[0124] Finally, the actual torque, predicted torque and actual torque residual of each joint of the robot at each moment within the preset time period are saved as a set of data. All the data are saved in the same way to construct the original data set.
[0125] For example, in one embodiment, for a certain joint, the constructed original data set includes 20,000 sets of data for the joint. It can be understood that these 20,000 sets of data are time series data, that is, they are data at 20,000 moments within a preset time period, and these 20,000 moments are arranged in chronological order.
[0126] S302: Divide the original data set into a test set and a validation set.
[0127] Specifically, the test set is used to train the residual prediction model, and the validation set is used to adjust the parameters of the residual prediction model and evaluate the performance of the residual prediction model.
[0128] In specific implementation, the original data set can be divided into a test set and a validation set according to a certain ratio. For example, in one embodiment, the first 80% of the original data set is divided into a test set, and the remaining 20% of the original data set is divided into a validation set according to the chronological order. In combination with the above example, for a certain joint, when the original data set includes 20,000 groups of data of the joint, the first 16,000 groups of data are used as a test set, and the last 4,000 groups of data are used as a validation set. The data division principles for other joints are similar and will not be repeated here.
[0129] S303: Based on the sampling method indicated by the bagging algorithm, sampling with replacement is performed on the test set to obtain n sample data sets.
[0130] Specifically, the sampling method indicated by the Bagging algorithm refers to randomly selecting a sample from the test set and putting it back into the test set to ensure that each sample is still likely to be selected in the next sampling.
[0131] It should be noted that n is equal to the number of LSTM models included in the first model. In this step, n sampling data sets are obtained, and one sampling data set is used to train one LSTM model.
[0132] Furthermore, the sampling method indicated by the Bagging algorithm can be expressed as follows:
[0133] ,
[0134] in, Indicates the selected sample; Represents the probability of the sample being selected.
[0135] The method provided in the present application performs sampling based on the sampling method indicated by the Bagging algorithm. Such a sampling method with replacement can be used to generate multiple sampling data sets for training multiple models, which can alleviate the problem of overfitting and improve the generalization ability of the model.
[0136] S304. Freeze the parameters of the second model, and for each of the n LSTM models, use a sampling data set as a training sample set of the LSTM model to train the LSTM model, so as to train the n LSTM models and obtain an intermediate residual prediction model.
[0137] Specifically, the number of sampled data sets is the same as the number of LSTM models, which is n, to ensure that each sampled data set is used to train one LSTM model.
[0138] In the specific implementation, any sampling data set is randomly selected from the n sampling data sets to train LSTM model 1. In the same way, any sampling data set is randomly selected from the remaining n-1 sampling data sets to train LSTM model 2 until LSTM model n is trained.
[0139] It should be noted that during the training process, the parameters of the second model need to be kept unchanged, that is, the requires_grad attribute in the parameters of the second model can be set to False, so that the parameters of the second model will be frozen.
[0140] Furthermore, when the n LSTM models are trained, the intermediate residual prediction model can be obtained. Specifically, in the intermediate residual prediction model, the n LSTM models have been preliminarily trained, and the second model has not been trained.
[0141] S305. Based on the verification set and the intermediate residual prediction model, obtain the predicted torque residuals at multiple moments in the verification set.
[0142] In a specific implementation, the verification set is input into the intermediate residual prediction model, and the intermediate residual prediction model outputs the predicted torque residuals at multiple moments in the verification set.
[0143] Combined with the previous introduction, for example, for a certain joint, the validation set contains 4000 sets of data, and these 4000 sets of data are recorded as X1~X4000, corresponding to the time t1~t4000 respectively. Further, referring to the previous description, for an LSTM model, it can predict the torque residual at the next moment based on the torque residuals at M historical moments. For example, M is 3, that is, it can predict the torque residual at time t+1 based on the torque residuals at time t, time t-1, and time t-2. Therefore, for an LSTM model, after X1~X4000 is input into it, it can output the predicted torque residual at time t4~t4000.
[0144] S306. Using the predicted torque residuals and actual torque residuals at multiple moments in the validation set as input to train the second model.
[0145] Referring to the previous description, through step S305, the predicted torque residuals at multiple moments in the verification set can be obtained. Furthermore, for each of the multiple moments, the actual torque residual at that moment can be directly read from the verification set, and then the predicted torque residual and the actual torque residual at that moment are used as a set of data to train the second model.
[0146] Referring to the previous description, after obtaining the predicted torque residual at time t4-t4000 through step S305, for example, for t4, its actual torque residual can be obtained. In this way, the actual torque residual and the predicted torque residual are taken as a set of data to obtain 3997 sets of data, and then the second model is trained using these 3997 sets of data.
[0147] It should be noted that the training process of the second model is mainly to make the predicted torque residual as close to the actual torque residual as possible by learning the difference between the predicted torque residual and the actual torque residual, so as to obtain the weight matrix of the input layer and the hidden layer.
[0148] Optionally, in a possible implementation process, during the training of the second model, the learning rate of the first model is maintained at 0.01 to fine-tune the parameters of the first model.
[0149] The method provided in this embodiment provides a method for training a residual prediction model. In the first aspect, during training, each of the n LSTM models is trained based on the Bagging algorithm, which can avoid model overfitting and improve the generalization ability of the model. Furthermore, training the second model based on the validation set can better learn the difference between the predicted torque residual and the actual torque residual, so that the predicted torque residual is as close to the actual torque residual as possible, thereby improving the prediction accuracy of the residual prediction model.
[0150] Furthermore, the present application also provides an embodiment to verify the method provided by the present application.
[0151] Specifically, in order to verify the effectiveness and accuracy of the residual prediction model proposed in this application, a verification test is carried out to verify it:
[0152] Specifically, during verification, the operating conditions of the residual prediction model are: CPU Intel i7-13700H, 16G memory, NVIDIA RTX4060 graphics card 8G video memory, operating system is Windows 11, and the environment configuration is Anaconda python3.9, Pytorch-cuda11.8, Pytorch 2.1.0.
[0153] Furthermore, the input of the residual prediction model is M torque residuals of a single joint (see the previous introduction, the torque residual refers to the difference between the actual torque of a single joint and the predicted torque), and the output of the residual prediction model is a single channel, and the output is specifically the predicted value of the torque residual of a single joint, that is, the torque residual of the joint at the next moment mentioned above.
[0154] It should be noted that when training the residual prediction model, it is necessary to train the residual prediction model based on the data of 7 joints. Figures 4 to 10 The loss function curve diagram of the residual prediction model when training the residual prediction model based on the data of seven joints shown in an exemplary embodiment of the present application. Table 1 is a data statistics table of the residual prediction model when training the residual prediction model based on the data of seven joints shown in an exemplary embodiment of the present application. Please refer to Figures 4 to 10 As shown in Table 1, the value of the loss function decreases with the increase of the number of iterations. After 800 iterations of training, most of them converge within 130 times. Therefore, in this embodiment, the value of epoch is adjusted to 130.
[0155] Table 1 Data statistics of residual prediction model trained based on data of seven joints
[0156]
[0157] It can be seen from Table 1 that in the training process of the residual prediction model, when the decrease rate of the loss function is between 94.4% and 96.4%, the training result of the residual prediction model is good, and the model can fit the data points well.
[0158] Next, the parameter setting of the residual prediction model is introduced. Table 2 is a parameter setting table of the residual prediction model shown in an exemplary embodiment of the present application:
[0159] Table 2 Parameter setting table of residual prediction model
[0160]
[0161] It should be noted that when training the model, the data set can be obtained based on sampling or calculation. For example, through sampling, the angular displacement and angular velocity of the seven joints at each moment can be obtained, and then the angular acceleration of the joint can be calculated based on the derivative of the angular displacement and angular velocity. Furthermore, the actual torque of the joint at a certain moment can be obtained through sampling, and the predicted torque of the joint at a certain moment can be predicted based on the inverse dynamics model. Figures 11 to 17 This is a schematic diagram of the predicted torque and actual torque of 7 joints in a test data set shown as an exemplary embodiment of the present application. The predicted torque is obtained based on the inverse dynamics model, and the actual torque is the actual torque value collected.
[0162] Furthermore, in order to verify the effectiveness and improvement effect of the residual prediction model proposed in this application, 290 verification points were randomly selected from the 25,000 data sets for training set verification.
[0163] After the residual prediction model is trained, in this embodiment, four indicators, namely, mean squared error (MSE), root mean squared error (RMSE), mean absolute error (MAE), and R2 Score, are used to analyze the test set. The definitions and descriptions of these indicators are given below:
[0164] ,
[0165] in, Represents the true value of the data set; Represents the predicted value of the data set; It represents the number of data sets; MSE represents mean square error; RMSE represents root mean square error; MAE represents mean absolute error.
[0166] It should be noted that the R-square value represents the coefficient of determination of the residual prediction model, and its best value is 1.0, indicating that the residual prediction model perfectly predicts the true value. The R-square value may also be negative, that is, there is no mapping fit relationship between the predicted data and the true data.
[0167] Table 3 shows the MSE, RMSE, MAR and R-square values corresponding to the residual prediction model shown in an exemplary embodiment of the present application:
[0168]
[0169] Please refer to Table 3, from which it can be seen that the MSE, RMSE and MAE of the torque residual prediction values of the 7 joints of the robot are all close to 0. It can be seen that the residual prediction model constructed in this application has good adaptability to the prediction of torque residual.
[0170] Furthermore, Figures 18 to 24 This is a schematic diagram showing the comparison between the actual torque residuals and the predicted torque residuals of the seven joints of the robot according to an exemplary embodiment of the present application. Figures 25 to 31 FIG. 1 is a comparison diagram of torque errors of seven joints of a robot before and after compensation, shown in an exemplary embodiment of the present application. Figure 32 to Figure 38 This is a comparison diagram of the control torque and actual torque of the robot's seven joints after compensation, showing an exemplary embodiment of the present application.
[0171] It should be noted that Figures 18 to 24In the formula, the actual torque residual refers to the difference between the actual torque actually acquired and the predicted torque predicted by the inverse dynamics model, and the predicted torque residual refers to the torque residual predicted by the residual prediction model. Figures 25 to 31 The torque error before compensation refers to the error between the predicted torque and the actual torque before compensation, which represents the difference between the torque predicted by the inverse dynamics model and the actual torque. The torque error after compensation refers to the difference between the torque obtained by compensating the predicted torque with the predicted torque residual and the actual torque. Figure 32 to Figure 38 The control torque in refers to the torque obtained by compensating the predicted torque with the predicted torque residual, and the actual torque refers to the actually acquired torque.
[0172] Please refer to Figures 18 to 24 and Figures 25 to 31 It can be seen that before compensation, the absolute value of the torque error of joint 1 is basically evenly distributed in [4.0374, 0.0006]; the absolute value of the torque error of joint 2 is distributed in [5.4627, 0.0121]; the absolute value of the torque error of joint 3 is distributed in [4.3725, 0.0066]; the absolute value of the torque error of joint 4 is distributed in [2.9014, 0.0109]; the absolute value of the torque error of joint 5 is distributed in [0.7850, 0.0039]; the absolute value of the torque error of joint 6 is distributed in [0.6646, 0.0014]; the absolute value of the torque error of joint 7 is basically evenly distributed in [0.4305, 0.0088]. After compensation, the absolute values of the torque errors of the seven joints of the robot are basically distributed around 0, at about Fluctuates left and right, and the fluctuation range is very small. Please continue to refer to Figure 32 to Figure 38 , see the previous introduction and Figure 32 to Figure 38 It can be seen that the torque of each joint after compensation is not much different from the actual torque, and the compensation accuracy is high, which can improve the accuracy of robot operation.
[0173] Corresponding to the aforementioned embodiment of a robot control method, the present application also provides an embodiment of a robot control device.
[0174] Fig.39 This is a schematic diagram of the structure of the first embodiment of the robot control device provided in this application. Fig.39 The device provided in this embodiment includes: a prediction module 1010, an acquisition module 1020 and a control module 1030; wherein,
[0175] The prediction module 1010 is used to predict the torque required to drive each joint of the robot at the next moment based on the inverse dynamics model and the dynamic parameters of the joint at N consecutive historical moments before the current moment, so as to obtain the predicted torque of the joint at the next moment;
[0176] The acquisition module 1020 is used to obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment for each of the M consecutive historical moments before the current moment;
[0177] The prediction module 1010 is further used to predict the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments based on the pre-trained residual prediction model;
[0178] The control module 1030 is used to compensate the torque residual of the joint at the next moment into the predicted torque, obtain the control torque required to drive the joint at the next moment, and control the joint according to the control torque.
[0179] The robot control device provided in this embodiment uses an advance residual prediction model. In this way, for each joint of the robot, based on the inverse dynamics model, according to the dynamic parameters of the joint at N consecutive historical moments before the current moment, after obtaining the predicted torque of the joint at the next moment, it can further obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment for each of the M consecutive historical moments before the current moment. Then, based on the residual prediction model, according to the M torque residuals of the joint at the M historical moments, the torque residual of the joint at the next moment is predicted. In this way, after predicting the torque residual of the joint at the next moment, the torque residual of the joint at the next moment can be compensated to the predicted torque to obtain the control torque required to drive the joint at the next moment, and the joint is controlled according to the control torque. In this way, through the pre-trained residual prediction model, the torque residual of the joint at the next moment can be predicted, and then the torque residual can be used to compensate the predicted torque, making the actual torque more accurate, which can improve the compensation accuracy, enhance the control accuracy and operation efficiency of the robot, and achieve precise control of the robot.
[0180] The device of this embodiment can be used to perform Figure 1 The steps, specific implementation principles and implementation processes of the method embodiment shown are similar and will not be repeated here.
[0181] Please continue to refer to Figure 2 The present application also provides a robot, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any one of the methods provided in the first aspect of the present application are implemented.
[0182] The present application also provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the steps of any one of the methods provided in the present application are implemented.
[0183] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0184] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0185] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A robot control method, characterized in that: The method comprises: For each joint of the robot, based on the inverse dynamics model, according to the dynamic parameters of the joint at N consecutive historical moments before the current moment, the torque required to drive the joint at the next moment is calculated to obtain the predicted torque of the joint at the next moment; For each of the M consecutive historical moments before the current moment, according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment, the torque residual of the joint at the historical moment is obtained; Based on the pre-trained residual prediction model, according to the M torque residuals of the joint at the M historical moments, predict the torque residual of the joint at the next moment; Compensating the torque residual of the joint at the next moment into the predicted torque to obtain the control torque required to drive the joint at the next moment, and controlling the joint according to the control torque; The residual prediction model includes a cascaded first model and a second model; wherein the first model includes n LSTM models in parallel; the residual prediction model based on the pre-trained method predicts the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments, including: For each LSTM model, the M torque residuals are input into the LSTM model, so that the LSTM model predicts the torque residual of the joint at the next moment according to the M torque residuals, and outputs the torque residual prediction value corresponding to the LSTM model; wherein the n LSTM models are trained based on the Bagging algorithm, and the training sample sets of the n LSTM models are different; The n torque residual prediction values corresponding to the n LSTM models are simultaneously input into the second model, so that the n torque residual prediction values are integrated by the second model, and the integrated torque residual prediction values are output as the torque residual of the joint at the next moment.
2. The method according to claim 1, characterized in that The training process of the residual prediction model includes: Constructing an original data set; wherein the original data set includes the actual torque, predicted torque and actual torque residual of each joint of the robot at each moment within a preset time period; wherein the predicted torque of each joint of the robot at each moment within the preset time period is obtained based on the prediction of the inverse dynamics model; Dividing the original data set into a test set and a validation set; Based on the sampling method indicated by the bagging algorithm, sampling with replacement is performed on the test set to obtain n sample data sets; Freeze the parameters of the second model, and for each of the n LSTM models, use a sample data set as a training sample set of the LSTM model to train the LSTM model, so as to train the n LSTM models and obtain an intermediate residual prediction model; Based on the verification set and the intermediate residual prediction model, obtaining predicted torque residuals at multiple moments in the verification set; The second model is trained by taking the predicted torque residuals and the actual torque residuals at multiple moments in the validation set as input.
3. The method according to claim 2, characterized in that The constructing of the original data set includes: Obtaining the dynamic parameters and actual torque of each joint of the robot at each moment within the preset time period; For each joint, based on the inverse dynamics model, calculate the predicted torque of the joint at each moment within the preset time period; For each moment in the preset time period, according to the predicted torque of the joint at the moment and the actual torque of the joint at the moment, obtain the actual torque residual of the joint at the moment; The original data set is constructed by using the actual torque, predicted torque and actual torque residual of each joint of the robot at each moment within the preset time period.
4. The method according to claim 2, characterized in that: During the training of the second model, the learning rate of the first model is maintained at 0.01 to fine-tune the parameters of the first model.
5. The method according to claim 1 or 2, characterized in that: The second model is a model consisting of three fully connected layers.
6. According to the method of claim 1, the inverse dynamics model is an inverse dynamics model constructed based on Newton-Euler algorithm and Coulomb friction algorithm.
7. A robot control device, characterized in that: The device comprises a prediction module, an acquisition module and a control module; wherein, The prediction module is used to calculate the torque required to drive each joint of the robot at the next moment based on the inverse dynamics model and the dynamic parameters of the joint at N consecutive historical moments before the current moment, so as to obtain the predicted torque of the joint at the next moment; The acquisition module is used to obtain the torque residual of the joint at the historical moment according to the actual torque of the joint at the historical moment and the predicted torque of the joint at the historical moment for each of the M consecutive historical moments before the current moment; The prediction module is further used to predict the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments based on a pre-trained residual prediction model; The control module is used to compensate the torque residual of the joint at the next moment into the predicted torque, obtain the control torque required to drive the joint at the next moment, and control the joint according to the control torque; The residual prediction model includes a cascaded first model and a second model; wherein the first model includes n LSTM models in parallel; the residual prediction model based on the pre-trained method predicts the torque residual of the joint at the next moment according to the M torque residuals of the joint at the M historical moments, including: For each LSTM model, the M torque residuals are input into the LSTM model, so that the LSTM model predicts the torque residual of the joint at the next moment according to the M torque residuals, and outputs the torque residual prediction value corresponding to the LSTM model; wherein the n LSTM models are trained based on the Bagging algorithm, and the training sample sets of the n LSTM models are different; The n torque residual prediction values corresponding to the n LSTM models are simultaneously input into the second model, so that the n torque residual prediction values are integrated by the second model, and the integrated torque residual prediction values are output as the torque residual of the joint at the next moment.
8. A robot comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
