Method and device for judging driving direction of servo motor with absolute encoder
By storing absolute coded values into a one-dimensional array and using counters to determine the position, simplifying the judgment of the driving direction of the servo motor, solving the problems of time-consuming and large code volume in the existing technology, achieving fast and accurate position control, reducing the System cost and probability of error.
Patent Information
- Application Number
- CN202411184288.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2025-01-07
AI Technical Summary
When the existing absolute encoder has high encoding accuracy, the servo motor driving direction judgment method takes a long time and has a large number of codes, resulting in high requirements for the performance of the control chip and errors caused by complex algorithms may occur.
Store the absolute position coded values into a one-dimensional array in sequence, determine the encoding value position through the counter, judge the position relationship between the current and target coded values to determine the driving direction, and reduce the maximum number of judgments to about 2n times, simplify the judgment process and reduce the calculation quantity.
It shortens the calculation time, reduces the performance requirements for the servo controller control chip, improves the reliability and response speed of the control system, and reduces the probability of system errors.
Smart Images

Figure CN119276180A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of encoders, and more specifically, relates to a method and device for determining the driving direction of a servo motor with an absolute encoder. Background Art
[0002] Absolute encoder: The encoder is a sensor that encodes the rotation angle and linear displacement position. The encoder that detects the rotation angle is called a rotary encoder, and the encoder that detects the linear displacement is called a linear encoder. Encoders are divided into mechanical (contact), radio and television, magnetic, and inductive types according to the detection method. Encoders have two ways to detect displacement and position information: relative position detection and absolute position detection. Detecting the amount of movement from one position to the next is called a relative encoder. Encoders that directly detect how far away from the starting position are called absolute encoders. After the absolute encoder is powered off and restarted, the position at the time of restart can be detected. There are two output methods in the absolute encoder, one is to output the binary code as a digital signal; the other is to convert the binary code into an analog voltage and output it. In addition, there are also two output methods for digital signals, one is parallel output, and the binary code obtained from multiple slits is output as is through multiple signal lines; the other is serial output, which uses one signal line for transmission, and converts multiple signals output in parallel into serial data at the same time, and transmits them sequentially over time.
[0003] Servo motors are motors used in servo mechanisms. In order to accurately control the rotation angle of the motor, some servo motors detect the position through an absolute encoder. The servo controller determines the direction of the motor drive based on the current encoder position and the target encoder position. The encoder can detect the motor position indirectly by detecting the position of the transmission mechanism with a fixed transmission ratio connected to the motor output end instead of directly detecting the motor position. Figure 4 As shown, when the absolute encoder has low precision, that is, when there are fewer position codes, it can be implemented through nested judgment statements. For example, if there are 3 position codes, namely x, y and z, respectively, from x to z is forward rotation, and from z to x is reverse rotation. The following method is usually used to implement the judgment of the driving direction: first determine whether the target position code is x, if so, determine whether the current position code is y, if so, reverse, otherwise determine whether the current position code is z, if so, reverse, otherwise exit; if the target position code is not x, determine whether the target position code is y, if so, determine whether the current position code is x, if so, forward rotation, otherwise determine whether the current position code is z, if so, reverse, otherwise exit; if the target position code is not y, determine whether the target position code is z, if so, determine whether the current position code is x, if so, forward rotation, otherwise determine whether the current position code is y, if so, forward rotation, otherwise exit.
[0004] When the number of encoding values is n, the above method will require more than n^2 judgments at most to obtain the current motor drive direction. When the encoder accuracy is high, that is, when there are more encoding positions, the amount of code will increase dramatically. For example, if a motor absolute position encoder has 30 position encoding values, if the above method is used, it may take more than 900 judgments to obtain the current motor drive direction. This method is time-consuming, has a large amount of code, and occupies more memory in the control system. It has higher performance requirements for the control chip. Summary of the invention
[0005] In response to the above defects or improvement needs of the prior art, the present invention provides a method and device for determining the driving direction of a servo motor with an absolute encoder, which can determine the driving direction of the motor with fewer steps. When the number of encoding values is n, a maximum of about 2n judgments can be performed, which can reduce the amount of code and the number of operations in the control system, shorten the calculation time, and reduce the performance requirements for the servo controller control chip.
[0006] To achieve the above object, according to one aspect of the present invention, a method for determining the driving direction of a servo motor with an absolute encoder is provided, comprising the following steps:
[0007] Step 1: Arrange the code values of the absolute position encoder in order according to their actual order and store them in a one-dimensional code array;
[0008] Step 2: Get the current code value and the target code value, and determine whether the current code value is legal. If the previous code value is legal, go to step 3, otherwise, end the determination.
[0009] Step 3, respectively calculating the positions of the current code value and the target code value in the code array;
[0010] Step 4, determine the position of the current code value in the code array and the position of the target code value in the code array. If the position of the current code value in the code array is greater than the position of the target code value in the code array, the servo motor drive direction is reverse, and the judgment ends, and the judgment result is output. If the position of the current code value in the code array is less than the position of the target code value in the code array, the servo motor drive direction is forward, and the judgment ends.
[0011] As a further preferred embodiment, in step 1, in the coding array, each coding value has a unique position index corresponding to it, and the position difference between adjacent coding values is a fixed value.
[0012] As a further preference, in step one, the current encoding value is collected through different sampling circuits according to the output mode of the absolute encoder, and the target encoding value is obtained from outside or inside the servo controller according to the control requirements of the servo controller.
[0013] As a further preferred embodiment, the determining whether the current encoding value is legal includes:
[0014] Compare the current code value with each code value in the code value array. If the current code value is equal to a code value in the code value array, the current code value is legal. If the current code value is not equal to any code value in the code value array, the current code value is illegal.
[0015] As further preferred, the calculating the position of the current code value in the code array includes:
[0016] (1) Obtain the difference between adjacent code value positions in the code value array;
[0017] (2) setting the initial value of the counter to the position index of the first code value in the code value array;
[0018] (3) comparing the current code value with the code value corresponding to the counter as the position index in the code value array;
[0019] (4) If they are equal, the position of the current code value in the code value array is the counter value, and the calculation is exited; otherwise, the counter increases the difference value based on itself and uses the difference value as the new counter value;
[0020] (5) Repeat the above steps (3) and (4) until the calculation is exited and the position of the current code value in the code array is output.
[0021] As further preferred, the position of the calculated target code value in the code array includes:
[0022] (1) Obtain the difference between adjacent code value positions in the code value array;
[0023] (2) setting the initial value of the counter to the position index of the first code value in the code value array;
[0024] (3) comparing the target code value with the code value corresponding to the position index of the counter in the code value array;
[0025] (4) If they are equal, the position of the target code value in the code value array is the counter value, and the calculation is exited; otherwise, the counter increases the difference value based on itself and uses the difference value as the new counter value;
[0026] (5) Repeat the above steps (3) and (4) until the calculation is exited and the position of the target code value in the code score array is output.
[0027] As a further preferred embodiment, in step four, when the servo motor driving direction is set to forward, the position index of the current encoding value in the encoding array will increase, and when the servo motor driving direction is reverse, the position index of the current encoding value in the encoding array will decrease.
[0028] According to another aspect of the present invention, there is also provided a servo motor driving direction determination system with an absolute encoder, comprising:
[0029] The first main control module is used to arrange the code values of the absolute position encoder in sequence according to their actual order and store them in a one-dimensional code array;
[0030] The second main control module is used to obtain the current code value and the target code value, determine whether the current code value is legal, and transmit the determination result to the third main control module;
[0031] The third main control module is used to calculate the positions of the current code value and the target code value in the code array respectively when the current code value is legal;
[0032] The fourth main control module is used to determine the position of the current encoding value in the encoding array and the position of the target encoding value in the encoding array. If the position of the current encoding value in the encoding array is greater than the position of the target encoding value in the encoding array, the servo motor driver is reversed, the judgment is ended, and the judgment result is output; if the position of the current encoding value in the encoding array is less than the position of the target encoding value in the encoding array, the servo motor driver is forward, and the judgment is ended.
[0033] According to another aspect of the present invention, there is also provided an electronic device, comprising:
[0034] At least one processor, at least one memory and a communication interface; wherein,
[0035] The processor, memory and communication interface communicate with each other;
[0036] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute a method for determining the driving direction of a servo motor with an absolute encoder according to any one of the above embodiments or a combination of multiple embodiments.
[0037] According to another aspect of the present invention, a non-transitory computer-readable storage medium is also provided, wherein the non-transitory computer-readable storage medium stores computer instructions, wherein the computer instructions enable the computer to execute a method for determining the driving direction of a servo motor with an absolute encoder according to any one of the above embodiments or a combination of multiple embodiments.
[0038] In general, the above technical solution conceived by the present invention has the following technical advantages compared with the prior art:
[0039] 1. The present invention reduces the amount of code and the number of operations in the control system by simplifying the judgment process of the servo motor driving direction. When the number of code values is n, a maximum of about 2n judgments are performed. This optimization not only shortens the calculation time, but also improves the response speed of the servo motor to the control command, thereby achieving more accurate and rapid position control, which is particularly important for application scenarios that require fast and precise positioning.
[0040] 2. The present invention reduces the amount of calculation and code complexity, and correspondingly reduces the requirements for the performance of the servo controller control chip. Even a low-performance control chip can achieve efficient motor drive direction judgment, thereby reducing system costs, making high-performance servo motor control systems more economical and easy to popularize.
[0041] 3. The present invention reduces the errors that may be caused by complex algorithms by storing the code values in a one-dimensional array and using a simple counter method to determine the position of the code values. The simplified logic flow reduces the probability of system errors and enhances the reliability and stability of the servo motor control system. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a flow chart of a method for determining the driving direction of a servo motor with an absolute encoder according to an embodiment of the present invention;
[0043] Figure 2 is a flow chart of a method for a counter to calculate a current code value in an embodiment of the present invention;
[0044] Figure 3 is a flow chart of a method for a counter to calculate a target code value in an embodiment of the present invention;
[0045] Figure 4 The present invention is a flow chart of determining the driving direction of a servo motor of an absolute encoder in the prior art. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0047] like Figure 1 , Figure 2 as well as Figure 3As shown, an embodiment of the present invention provides a method for determining the driving direction of a servo motor with an absolute encoder, wherein a servo controller determines the driving direction of the motor according to the current encoding position and the target encoding position. The method comprises the following steps:
[0048] First, the code values of the absolute position encoder are arranged in sequence according to their actual order and stored in a one-dimensional array. Each code value in the array has a unique position index corresponding to it, and the position difference of adjacent code values is a fixed value.
[0049] The method for obtaining the driving direction of a servo motor with an absolute encoder is generally divided into five steps: the first step: obtaining the current encoding value and the target encoding value; the second step: determining whether the current encoding value is legal; the third step: calculating the position of the current encoding value in the encoding value array; the fourth step: calculating the position of the target encoding value in the encoding value array; the fifth step: comparing the position of the current encoding value in the encoding value array output in the third and fourth steps with the position of the target encoding value in the encoding value array. According to the relationship between the specified servo motor driving direction and the position encoding array, the motor driving direction is output.
[0050] More specifically, the method includes:
[0051] The first step is to obtain the current encoding value and the target encoding value. The current encoding value can be collected through different sampling circuits according to the output mode of the absolute encoder, and the target encoding value can be obtained from the outside or inside of the servo controller according to the control requirements of the servo controller.
[0052] The second step is to determine whether the current code value is legal. The purpose of determining whether the current code value is legal is that if the current code value is illegal, the code value cannot represent the current angle of the servo motor, and therefore feedback control cannot be achieved. The method for determining whether the current code value is legal is to compare the current code value with each code value in the code value array. If the current code value is equal to one of the code values in the code value array, the current code value is legal. If no code value in the code value array is equal to the current code value, the current code value is illegal.
[0053] The third step is to calculate the position of the current encoding value in the encoding value array.
[0054] In this step, a counter is used to obtain the encoding value, specifically:
[0055] 1) First, the initial value of the counter is set to the position index of the first code value in the code value array. For example, if the position index of the first code value in the code value array is 0, the initial value of the counter is set to 0;
[0056] 2) Compare the current code value with the code value corresponding to the position index in the code value array using the counter as the code value. If they are equal, the position of the current code value in the code value array is the counter value, and the calculation is exited. Otherwise, proceed to the next step.
[0057] 3) The counter increases the position difference of adjacent code values in the code value array based on the original value. For example, if the position difference of adjacent code values in the code value array is 1, the counter increases by 1 based on the original value;
[0058] 4) Repeat steps 2) and 3) until the calculation is exited. Because the legitimacy of the current code value has been judged in the second step, there must be a counter value whose code value in the code value array corresponding to the code value position index is consistent with the current code value.
[0059] Step 4: Calculate the position of the target code value in the code value array. This step is the same as step 3, and calculates the position of the target code value in the code value array. The order of step 3 and step 4 can be replaced at will.
[0060] The fifth step is to compare the position of the current code value in the code value array output in the third step and the fourth step with the position of the target code value in the code value array. According to the relationship between the specified servo motor drive direction and the position code array, the motor drive direction is output. If the servo motor is specified to rotate forward, the code value position index in the position code array corresponding to the current code value will increase. If the position of the current position code value obtained in the third step in the code value array is greater than the position of the target code value obtained in the fourth step in the code value array, the motor drive direction is output as reverse rotation, otherwise the output is forward rotation. If the servo motor is specified to rotate forward, the code value position index in the position code array corresponding to the current code value will decrease. If the position of the current position code value obtained in the third step in the code value array is greater than the position of the target code value obtained in the fourth step in the code value array, the motor drive direction is output as reverse rotation, otherwise the motor drive direction is output as forward rotation.
[0061] The method for determining the driving direction of a servo motor with an absolute encoder provided in this embodiment reduces the number of times the current code value and the target code value are determined in the third, fourth, and fifth steps. When the number of code values is n, a maximum of about 2n determinations are made. This method can reduce the amount of code and the number of operations in the control system, shorten the calculation time, and reduce the performance requirements for the servo controller control chip.
[0062] In this embodiment, for a servo motor with an absolute encoder, a method for obtaining the motor driving direction is not used to judge the current code value and the target code value by using a nested judgment statement, but a method is proposed to arrange the code values in their actual order and store them in a one-dimensional array, each code value in the array has a unique position index corresponding to it, and the position difference of adjacent code values is a fixed value. The method of obtaining the motor driving direction is obtained by comparing the positions of the current code value and the target code value in the code value array.
[0063] The implementation basis of each embodiment of the present invention is to implement programmed processing through a device with a processor function. Therefore, in engineering practice, the technical solutions and functions of each embodiment of the present invention can be packaged into various modules. Based on this reality, on the basis of the above embodiments, an embodiment of the present invention provides a servo motor drive direction judgment system with an absolute encoder, which is used to implement the method of any of the above embodiments or a combination of multiple embodiments, including: a first main control module, which is used to arrange the absolute position encoder code values in sequence according to their actual order and store them in a one-dimensional code array; a second main control module, which is used to obtain the current code value and the target code value, determine whether the current code value is legal, and transmit the judgment result to the third main control module; the third main control module is used to calculate the position of the current code value and the target code value in the code array respectively when the current code value is legal; a fourth main control module, which is used to determine the position of the current code value in the code array and the position of the target code value in the code array, if the position of the current code value in the code array is greater than the position of the target code value in the code array, the servo motor drive side is reverse, the judgment is ended, and the judgment result is output; if the position of the current code value in the code array is less than the position of the target code value in the code array, the servo motor drive side is forward, and the judgment is ended.
[0064] The method of the embodiment of the present invention is implemented by relying on electronic devices, so it is necessary to introduce the relevant electronic devices. Based on this purpose, the embodiment of the present invention provides an electronic device, such as Figure 3 As shown, the electronic device includes: at least one processor, a communication interface, at least one memory, and a communication bus, wherein at least one processor, the communication interface, and at least one memory communicate with each other through the communication bus. At least one processor can call the logic instructions in at least one memory to execute all or part of the steps of the method provided by the aforementioned various method embodiments.
[0065] In addition, the logic instructions in the at least one memory mentioned above can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each method embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0066] The device embodiments described above are merely illustrative, 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 scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0067] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0068] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present invention. Based on this understanding, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and sometimes in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0069] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for determining the driving direction of a servo motor with an absolute encoder, characterized in that: The following steps are involved: Step 1: Arrange the code values of the absolute position encoder in order according to their actual order and store them in a one-dimensional code array; Step 2: Get the current code value and the target code value, and determine whether the current code value is legal. If the previous code value is legal, go to step 3, otherwise, end the determination. Step 3, respectively calculating the positions of the current code value and the target code value in the code array; Step 4, determine the position of the current code value in the code array and the position of the target code value in the code array. If the position of the current code value in the code array is greater than the position of the target code value in the code array, the servo motor drive direction is reverse, and the judgment ends, and the judgment result is output. If the position of the current code value in the code array is less than the position of the target code value in the code array, the servo motor drive direction is forward, and the judgment ends.
2. A method for determining the driving direction of a servo motor with an absolute encoder according to claim 1, characterized in that: In step 1, in the encoding array, each encoding value has a unique position index corresponding to it, and the position difference between adjacent encoding values is a fixed value.
3. A method for determining the driving direction of a servo motor with an absolute encoder according to claim 1, characterized in that: In step 1, the current encoding value is collected through different sampling circuits according to the output mode of the absolute encoder, and the target encoding value is obtained from the outside or inside of the servo controller according to the control requirements of the servo controller.
4. The method for determining the driving direction of a servo motor with an absolute encoder according to claim 1, characterized in that: The determination of whether the current encoding value is legal includes: Compare the current code value with each code value in the code value array. If the current code value is equal to a code value in the code value array, the current code value is legal. If the current code value is not equal to any code value in the code value array, the current code value is illegal.
5. The method for determining the driving direction of a servo motor with an absolute encoder according to claim 1, characterized in that: The calculation of the position of the current encoding value in the encoding array includes: (1) Obtain the difference between adjacent code value positions in the code value array; (2) setting the initial value of the counter to the position index of the first code value in the code value array; (3) comparing the current code value with the code value corresponding to the counter as the position index in the code value array; (4) If they are equal, the position of the current code value in the code value array is the counter value, and the calculation is exited; otherwise, the counter increases the difference value based on itself and uses the difference value as the new counter value; (5) Repeat the above steps (3) and (4) until the calculation is exited and the position of the current code value in the code array is output.
6. A method for determining the driving direction of a servo motor with an absolute encoder according to claim 1, characterized in that: The position of the calculated target encoding value in the encoding array includes: (1) Obtain the difference between adjacent code value positions in the code value array; (2) setting the initial value of the counter to the position index of the first code value in the code value array; (3) comparing the target code value with the code value corresponding to the counter as the position index in the code value array; (4) If they are equal, the position of the target code value in the code value array is the counter value, and the calculation is exited; otherwise, the counter increases the difference value based on itself and uses the difference value as the new counter value; (5) Repeat the above steps (3) and (4) until the calculation is exited and the position of the target code value in the code score array is output.
7. A method for determining the driving direction of a servo motor with an absolute encoder according to claim 1, characterized in that: In step 4, when the servo motor driving direction is set to forward rotation, the position index of the current encoding value in the encoding array will increase. When the servo motor driving direction is reverse rotation, the position index of the current encoding value in the encoding array will decrease.
8. A servo motor driving direction determination system with an absolute encoder, characterized in that: include: The first main control module is used to arrange the code values of the absolute position encoder in sequence according to their actual order and store them in a one-dimensional code array; The second main control module is used to obtain the current code value and the target code value, determine whether the current code value is legal, and transmit the determination result to the third main control module; The third main control module is used to calculate the positions of the current code value and the target code value in the code array respectively when the current code value is legal; The fourth main control module is used to determine the position of the current encoding value in the encoding array and the position of the target encoding value in the encoding array. If the position of the current encoding value in the encoding array is greater than the position of the target encoding value in the encoding array, the servo motor driving direction is reverse, the judgment is ended, and the judgment result is output; if the position of the current encoding value in the encoding array is less than the position of the target encoding value in the encoding array, the servo motor driving direction is forward, and the judgment is ended.
9. An electronic device, characterized in that: include: At least one processor, at least one memory and a communication interface; wherein, The processor, memory and communication interface communicate with each other; The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute a method for determining the driving direction of a servo motor with an absolute encoder as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the method for determining the driving direction of a servo motor with an absolute encoder as described in any one of claims 1 to 7.
Citation Information
Cited By
Improved M method for improving speed measurement precision of servo motor
CN121347841A