Calculation method and device for motor position control

By precalculating the ratio G of the electronic gear ratio in the calculation method of motor position control, and multiplication and rounding operations are performed in combination with real-time input pulse Xn, the problem of low efficiency of division and balance calculation in the prior art is solved, and efficient motor position control is achieved, taking into account both calculation accuracy and efficiency.

CN119853542APending Publication Date: 2025-04-18FUJIAN WEIKONG ELECTRONIC TECHNOLOGY CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202510347330.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-24
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

The existing calculation methods for motor position control have shortcomings in taking into account both calculation accuracy and calculation efficiency, especially the efficiency of division and balance calculation is poor, which affects the real-time nature of the system.

Method used

By precalculating the ratio G=A/B of the electronic gear ratio and multiplying it with the real-time input pulse Xn, the first output pulse Yf is obtained, and then rounding Yf is obtained to obtain the real-time output pulse Yn. At the same time, the real-time remainder Mn is calculated by Xn×A=Yn×B+Mn, and error correction is performed based on Mn and the last final remainder Mlast to obtain the final output pulse Y.

Benefits of technology

This method significantly improves the computing efficiency and improves the real-time performance of the embedded system. At the same time, it retains the error correction of the real-time output pulse Yn by the remainder M, ensuring the calculation accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119853542A_ABST
    Figure CN119853542A_ABST
Patent Text Reader

Abstract

The invention provides a calculation method and device for motor position control. The method comprises the steps that the ratio G = A / B of an electronic gear ratio is calculated in advance; multiplying the ratio G by the real-time input pulse Xn to obtain a first output pulse Yf; rounding the first output pulse Yf to obtain a real-time output pulse Yn; calculating to obtain a real-time remainder Mn through Xn * A = Yn * B + Mn, and calculating a current final remainder M according to the real-time remainder Mn and a last final remainder Mlast; and performing error correction on the real-time output pulse Yn according to the final remainder M to obtain a final output pulse Y for motor position control. The calculation precision and the calculation efficiency of motor position control are considered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automation data technology, and in particular to a calculation method and device for motor position control. Background Art

[0002] In automation applications, in order to enable the automation equipment to perform precise positioning, the upper device is usually used to send pulse commands or position commands to control the position of the motor. The input pulse command or position command is to set the load displacement, while the motor position command is the encoder unit. The units of the two are different, so the electronic gear ratio is required for proportional conversion. That is, the role of the electronic gear ratio is to multiply the input pulse number or position value by the electronic gear ratio as the position command for motor position control.

[0003] The electronic gear ratio includes the following two parameters: the electronic gear ratio numerator and the gear ratio denominator, which are expressed using integer variables. At this time, assuming that the electronic gear ratio numerator is A, the gear ratio denominator is B, the input pulse number is X, and the output pulse calculated by the electronic gear ratio is Y, the following calculation formula is used: X×A / B=Y. In position control, if there is a new X value, the electronic gear ratio calculation will be repeatedly called, and the formula is expanded to: ∑X×A / B=∑Y.

[0004] In the prior art, the calculation method for calculating the output pulse Y required for motor position control based on the electronic gear ratio includes: (1) The calculation of the output pulse Y follows the above calculation rule: X×A / B=Y remainder M, where the remainder M needs to be introduced because the calculation result of the output pulse Y may not be divisible evenly. The above X, Y, A, B, and M are all integer variables.

[0005] In this process, the calculation process involved includes 1 integer multiplication, 1 integer division, 1 remainder operation and 1 addition, and the above addition is the accumulation of the remainder M. The above calculation process must be calculated in real time in each cycle.

[0006] This method has the following disadvantages: The computational efficiency of division and remainder operations is poor, compared with multiplication and addition and subtraction. Especially when the MCU does not support the division instruction, it takes more time. And when the data width of the gear ratio denominator B is larger, the efficiency of division calculation will decrease significantly. When the embedded MCU software platform calculates, the poor computational efficiency will affect the real-time performance of the system.

[0007] (2) The electronic gear ratio calculation follows the above calculation rules: X×A / B=Y, where the input pulse X is an integer variable and the output pulse Y uses a floating-point variable. At this time, the gear ratio numerator A and the gear ratio B are converted into floating-point numbers for calculation. However, when the motor uses the output pulse Y for position control, it only takes its integer value.

[0008] This method has the following disadvantages: using floating-point numbers for the gear ratio numerator and denominator will lead to cumulative errors in the calculated output pulse Y. After many calculations, the output pulse Y will deviate from the theoretical value and gradually increase, resulting in poor calculation, which is unacceptable in position control.

[0009] Therefore, the existing calculation method for motor position control cannot take into account both calculation accuracy and calculation efficiency. Summary of the invention

[0010] In order to solve the above problems in the prior art, the present invention provides a method and device for calculating motor position control, which take into account both the calculation accuracy and calculation efficiency of the motor position control.

[0011] In order to achieve the above object, the technical solution adopted by the present invention is: In a first aspect, the present invention provides a calculation method for motor position control, comprising the steps of: S1. Pre-calculate the ratio of the electronic gear ratio G=A / B, where the gear ratio numerator A and the gear ratio denominator B are integer variables, and the ratio G is a floating-point variable; S2, the ratio G and the real-time input pulse X n Multiply them to get the first output pulse Y f , where the real-time input pulse X n is a shaping variable, the first output pulse Y f is a floating point variable; S3, the first output pulse Y f Round off to get the real-time output pulse Y n , wherein the real-time output pulse Y n is an integer variable; S4, through X n ×A=Y n ×B+M n To calculate the real-time remainder M n , according to the real-time remainder M n and the final remainder M of the previous last To calculate the current final remainder M, where the real-time remainder M n , the last final remainder M last and the current final remainder M are both integer variables; S5, according to the final remainder M, the real-time output pulse Y n Error correction is performed to obtain the final output pulse Y for motor position control.

[0012] The beneficial effects of the present invention are as follows: although the present invention adds integer operation, floating-point multiplication and addition and subtraction operations, it greatly improves the calculation efficiency compared with the integer division and remainder operation, so as to improve the real-time performance of the embedded system; at the same time, the remainder M is retained for the real-time output pulse Y n Error correction is performed to ensure the calculation accuracy of the final output pulse Y, thereby taking into account both the calculation accuracy and efficiency of the motor position control.

[0013] Optionally, the step S5 includes the following steps: If the final remainder M is greater than the gear ratio denominator B, the real-time output pulse Y n After adding 1, it is used as the final output pulse Y of the motor position control. Otherwise, the real-time output pulse Y is directly used. n As the final output pulse Y of motor position control.

[0014] Optionally, the step S5 further includes the following steps: If the final remainder M is greater than the gear ratio denominator B, the gear ratio denominator B is subtracted from the final remainder M to obtain the next final remainder M. last .

[0015] Optionally, in step S4, X n ×A=Y n ×B+M n To calculate the real-time remainder M n The following steps are involved: The real-time input pulse X n Multiplying the gear ratio numerator A by the first result value; The real-time output pulse Y n Multiplying the gear ratio denominator B by the gear ratio denominator B to obtain a second result value; Subtract the second result value from the first result value to obtain a real-time remainder M n .

[0016] Optionally, the step S1 is recalculated only when the gear ratio numerator A or the gear ratio denominator B changes.

[0017] In a second aspect, the present invention provides a computing device for motor position control, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program: S1. Pre-calculate the ratio of the electronic gear ratio G=A / B, where the gear ratio numerator A and the gear ratio denominator B are integer variables, and the ratio G is a floating-point variable; S2, the ratio G and the real-time input pulse X n Multiply them to get the first output pulse Y f , where the real-time input pulse X n is a shaping variable, the first output pulse Y f is a floating point variable; S3, the first output pulse Y f Round off to get the real-time output pulse Y n , wherein the real-time output pulse Y n is an integer variable; S4, through X n ×A=Y n ×B+M n To calculate the real-time remainder M n , according to the real-time remainder M n and the final remainder M of the previous last To calculate the current final remainder M, where the real-time remainder M n , the last final remainder M last and the current final remainder M are both integer variables; S5, according to the final remainder M, the real-time output pulse Y n Error correction is performed to obtain the final output pulse Y for motor position control.

[0018] Optionally, the step S5 includes the following steps: If the final remainder M is greater than the gear ratio denominator B, the real-time output pulse Y n After adding 1, it is used as the final output pulse Y of the motor position control. Otherwise, the real-time output pulse Y is directly used. n As the final output pulse Y of motor position control.

[0019] Optionally, the step S5 further includes the following steps: If the final remainder M is greater than the gear ratio denominator B, the gear ratio denominator B is subtracted from the final remainder M to obtain the next final remainder M. last .

[0020] Optionally, in step S4, X n ×A=Y n ×B+M n To calculate the real-time remainder M n The following steps are involved: The real-time input pulse X nMultiplying the gear ratio numerator A by the first result value; The real-time output pulse Y n Multiplying the gear ratio denominator B by the gear ratio denominator B to obtain a second result value; Subtract the second result value from the first result value to obtain a real-time remainder M n .

[0021] Optionally, the step S1 is recalculated only when the gear ratio numerator A or the gear ratio denominator B changes.

[0022] Among them, the technical effect corresponding to the calculation device for motor position control provided by the second aspect refers to the relevant description of the calculation method for motor position control provided by the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 A schematic diagram of the main flow of a calculation method for motor position control according to an embodiment of the present invention; Figure 2 A schematic diagram of the framework of a calculation device for motor position control according to an embodiment of the present invention.

[0024] Description of reference numerals: 1. A calculation device for motor position control; 2. Processor; 3. Memory. DETAILED DESCRIPTION

[0025] In order to better understand the above technical solution, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a clearer and more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.

[0026] Embodiment 1 Please refer to Figure 1 , a calculation method for motor position control, comprising the steps of: S1. Pre-calculate the electronic gear ratio G=A / B, where the gear ratio numerator A and the gear ratio denominator B are integer variables, and the ratio G is a floating-point variable.

[0027] The gear ratio numerator A or the gear ratio denominator B is a parameter set by the user, so step S1 is recalculated only when the gear ratio numerator A or the gear ratio denominator B changes. Therefore, the time of step S1 can be ignored when calculating the motor position control in the subsequent steps.

[0028] Among them, integer variables are generally represented by int or long, and floating-point variables are represented by float.

[0029] S2, compare the ratio G with the real-time input pulse X n Multiply them to get the first output pulse Y f , where the real-time input pulse X n is an integer variable, the first output pulse Y f A floating point variable.

[0030] Among them, the ratio G is a floating point variable, that is, it has a decimal point, so the first output pulse Y f Also for floating point variables.

[0031] S3, the first output pulse Y f Round off to get the real-time output pulse Y n , where real-time output pulse Y n is an integer variable.

[0032] In the computer system, the first output pulse Y f Forced to convert into an integer variable and assign it to the real-time output pulse Y n .

[0033] On this basis, the design principles of the subsequent steps of this embodiment are: According to X×A / B=Y, we get: X×A=Y×B. Since the gear ratio numerator A, the gear ratio denominator B, the input pulse X, and the output pulse Y are all integers, there may be a remainder in the calculation result, and the remainder is M, that is, the final formula is: X×A=Y×B+M.

[0034] S4, through X n ×A=Y n ×B+M n To calculate the real-time remainder M n , according to the real-time remainder M n and the final remainder M of the previous last To calculate the current final remainder M, where the real-time remainder M n , the last final remainder M last and the current final remainder M are both integer variables.

[0035] In this embodiment, in step S4, X n ×A=Y n ×B+M n To calculate the real-time remainder M n The following steps are involved: S41, the real-time input pulse X n Multiplying by the gear ratio numerator A yields the first result value.

[0036] Among them, the first result value Buf0=X n ×A.

[0037] S42, real-time output pulse Y n Multiply it by the gear ratio denominator B to get the second result value.

[0038] Among them, the second result value Buf1=Y n ×B.

[0039] S43, subtract the second result value from the first result value to obtain a real-time remainder M n .

[0040] Among them, the real-time remainder M n = Buf0 - Buf1.

[0041] S5, according to the final remainder M, the real-time output pulse Y n Error correction is performed to obtain the final output pulse Y for motor position control.

[0042] In this embodiment, step S5 includes the following steps: S51, if the final remainder M is greater than the gear ratio denominator B, the pulse Y will be output in real time n After adding 1, it is used as the final output pulse Y of the motor position control, otherwise the real-time output pulse Y is directly n As the final output pulse Y of motor position control.

[0043] S52. If the final remainder M is greater than the gear ratio denominator B, the gear ratio denominator B is subtracted from the final remainder M to obtain the next final remainder M. last .

[0044] Among them, if the final remainder M is greater than the gear ratio denominator B, the final output pulse Y+=1, and the final remainder M-=B.

[0045] Therefore, according to the above steps, the calculation process is exemplified as follows: (1) First calculation: X1×A=Y1×B+M; Buf0=X1×A; Buf1=Y1×B; M1=Buf0-Buf1; M+=M1; The initial value of M in the first calculation is 0.

[0046] (2) Second calculation: X2×A=Y2×B+M; Buf0=X2×A; Buf1=Y2×B; M2=Buf0-Buf1; M+=M2; Among them, M at the end of the first operation is M this time last , which is used to add to the real-time remainder M2 of this calculation, that is, M = M 2+ M last .

[0047] When the final remainder M is greater than the gear ratio denominator B, the real-time output pulse Y2 calculated for the second time needs to be added 1 to obtain the final output pulse Y=Y2+1, and the final remainder M needs to be subtracted from B.

[0048] The formula is as follows: X2×A=(Y2+1)×B+(MB).

[0049] (3) Third calculation: X3×A=Y3×B+M; Buf0=X3×A; Buf1=Y3×B; M3=Buf0-Buf1; M+=M3; Among them, M at the end of the second operation is M this time last , which is used to add to the real-time remainder M3 of this calculation, that is, M = M 3+ M last .

[0050] When the final remainder M is greater than the gear ratio denominator B, the real-time output pulse Y3 calculated for the third time needs to be added 1 to obtain the final output pulse Y=Y3+1, and the final remainder M needs to be subtracted from B.

[0051] This process continues recursively.

[0052] Therefore, because of the existence of the final remainder M, even if Y n There are small deviations, and the error will be made in each calculation so that it will never exceed 1, so there will be no loss of calculation accuracy.

[0053] Compared with the calculation method (1) in the prior art, the calculation method of this embodiment is: The calculation method (1) in the prior art includes: 1 integer multiplication, 1 integer division, 1 remainder operation, and 1 addition.

[0054] The calculation method of this embodiment includes: 2 integer multiplications, 1 floating-point multiplication, 1 rounding operation, 2 additions, 2 subtractions and 1 judgment condition.

[0055] This embodiment adds 1 integer multiplication + 1 floating-point multiplication + 1 integer rounding operation + 1 addition + 2 subtractions + 1 if determination to replace 1 integer division and 1 remainder operation of calculation method (1).

[0056] For chips that do not have a dedicated division instruction set, the speed of multiplication operations is much faster than division operations and remainder operations. Using multiplication and addition and subtraction instead of division and remainder operations can increase the calculation speed and improve the real-time performance of embedded systems.

[0057] Specifically, the calculation speed of the numerator / denominator of the electronic gear ratio with a 144Mhz main frequency and 32-bit integer is compared as follows: Calculation method (1): The calculation process of the entire motor position control takes about 6us; In this embodiment, the calculation process of the entire motor position control takes about 2us.

[0058] Furthermore, if a 64-bit integer is used for motor position control, the efficiency difference may be further increased.

[0059] Therefore, this embodiment takes into account both the calculation accuracy and calculation efficiency of the motor position control.

[0060] Embodiment 2 Please refer to Figure 2 A computing device 1 for motor position control includes a memory 3, a processor 2, and a computer program stored in the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, the steps in the above-mentioned embodiment 1 are implemented.

[0061] Since the system / device described in the above embodiments of the present invention is a system / device used to implement the method of the above embodiments of the present invention, a person skilled in the art can understand the specific structure and deformation of the system / device based on the method described in the above embodiments of the present invention, and thus will not be described in detail here. All systems / devices used in the method of the above embodiments of the present invention belong to the scope of protection of the present invention.

[0062] It should be understood by those skilled in the art that embodiments of the present invention may be provided as methods, apparatuses or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0063] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (apparatus) and computer program products according to embodiments of the present invention. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions.

[0064] It should be noted that in the claims, any reference numerals placed between brackets shall not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention may be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In the claims enumerating several means, several of these means may be embodied by the same hardware. The use of the words first, second, third, etc., is for convenience of expression only and does not indicate any order. These words may be understood as part of the component name.

[0065] In addition, it should be noted that, in the description of this specification, the description of the terms "one embodiment", "some embodiments", "embodiment", "example", "specific example" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.

[0066] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments after knowing the basic creative concept. Therefore, the claims should be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present invention.

[0067] Obviously, those skilled in the art can make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention should also include these modifications and variations.

Claims

1. A calculation method for motor position control, characterized in that: Includes steps: S1. Pre-calculate the ratio of the electronic gear ratio G=A / B, where the gear ratio numerator A and the gear ratio denominator B are integer variables, and the ratio G is a floating-point variable; S2, the ratio G and the real-time input pulse X n Multiply them to get the first output pulse Y f , where the real-time input pulse X n is a shaping variable, the first output pulse Y f is a floating point variable; S3, the first output pulse Y f Round off to get the real-time output pulse Y n , wherein the real-time output pulse Y n is an integer variable; S4, through X n ×A=Y n ×B+M n To calculate the real-time remainder M n , according to the real-time remainder M n and the final remainder M of the previous last To calculate the current final remainder M, where the real-time remainder M n , the last final remainder M last and the current final remainder M are both integer variables; S5, according to the final remainder M, the real-time output pulse Y n Error correction is performed to obtain the final output pulse Y for motor position control.

2. A calculation method for motor position control according to claim 1, characterized in that: The step S5 comprises the following steps: If the final remainder M is greater than the gear ratio denominator B, the real-time output pulse Y n After adding 1, it is used as the final output pulse Y of the motor position control. Otherwise, the real-time output pulse Y is directly used. n As the final output pulse Y of motor position control.

3. A calculation method for motor position control according to claim 2, characterized in that: The step S5 further comprises the following steps: If the final remainder M is greater than the gear ratio denominator B, the gear ratio denominator B is subtracted from the final remainder M to obtain the next final remainder M. last .

4. The calculation method for motor position control according to claim 1, characterized in that: In step S4, X n ×A=Y n ×B+M n To calculate the real-time remainder M n The following steps are involved: The real-time input pulse X n Multiplying the gear ratio numerator A by the first result value; The real-time output pulse Y n Multiplying the gear ratio denominator B by the gear ratio denominator B to obtain a second result value; Subtract the second result value from the first result value to obtain a real-time remainder M n .

5. A calculation method for motor position control according to any one of claims 1 to 4, characterized in that: The step S1 is recalculated only when the gear ratio numerator A or the gear ratio denominator B changes.

6. A computing device for motor position control, 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 computer program, the following steps are implemented: S1. Pre-calculate the ratio of the electronic gear ratio G=A / B, where the gear ratio numerator A and the gear ratio denominator B are integer variables, and the ratio G is a floating-point variable; S2, the ratio G and the real-time input pulse X n Multiply them to get the first output pulse Y f , where the real-time input pulse X n is a shaping variable, the first output pulse Y f is a floating point variable; S3, the first output pulse Y f Round off to get the real-time output pulse Y n , wherein the real-time output pulse Y n is an integer variable; S4, through X n ×A=Y n ×B+M n To calculate the real-time remainder M n , according to the real-time remainder M n and the final remainder M of the previous last To calculate the current final remainder M, where the real-time remainder M n , the last final remainder M last and the current final remainder M are both integer variables; S5, according to the final remainder M, the real-time output pulse Y n Error correction is performed to obtain the final output pulse Y for motor position control.

7. A calculation device for motor position control according to claim 6, characterized in that: The step S5 comprises the following steps: If the final remainder M is greater than the gear ratio denominator B, the real-time output pulse Y n After adding 1, it is used as the final output pulse Y of the motor position control. Otherwise, the real-time output pulse Y is directly used. n As the final output pulse Y of motor position control.

8. A calculation device for motor position control according to claim 7, characterized in that: The step S5 further comprises the following steps: If the final remainder M is greater than the gear ratio denominator B, the gear ratio denominator B is subtracted from the final remainder M to obtain the next final remainder M. last .

9. A calculation device for motor position control according to claim 6, characterized in that: In step S4, X n ×A=Y n ×B+M n To calculate the real-time remainder M n The following steps are involved: The real-time input pulse X n Multiplying the gear ratio numerator A by the first result value; The real-time output pulse Y n Multiplying the gear ratio denominator B by the gear ratio denominator B to obtain a second result value; Subtract the second result value from the first result value to obtain a real-time remainder M n .

10. A calculation device for motor position control according to any one of claims 6 to 9, characterized in that: The step S1 is recalculated only when the gear ratio numerator A or the gear ratio denominator B changes.

Citation Information

Patent Citations

  • Method for positioning motor servo controller

    CN101071303A

  • Automatic position preset pulse gear ratio setting method of servo driver

    CN106774147A

  • Follow control method and system based on electronic gear

    CN108512472A

  • Pulse signal generation method and device

    CN109327210A

  • Operation method, device and equipment of floating point divider and storage medium

    CN118689446A