Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, fig. 1 is a flowchart of a method for generating motor driving pulses according to an embodiment of the present invention, and as shown in fig. 1, the method includes the following steps:
step 101, obtaining a first parameter, and performing amplitude limiting processing on the first parameter to obtain a second parameter, wherein the first parameter includes a position expected value, a scaling ratio, a pulse duty ratio, a pulse commutation time, a position value of a first sampling period, a position value of a second sampling period, and a fixed sampling period.
Wherein, the position expected value, the scaling ratio, the pulse duty ratio and the pulse commutation time can be artificially set; the position value of the first sampling period, the position value of the second sampling period and the fixed sampling period can be obtained from the position and speed processing unit; the pulse commutation time determines the running direction of the motor, for example: when the position value variable is 0, the motor is in forward transmission, after 2ms, the position value variable is 1, the motor is in reverse rotation, and the motor movement direction discussed below is defaulted to be in the forward direction.
It should be noted that the motor driving pulse may be generated by the cooperation of a position and speed processing unit and a pulse and direction unit, the position and speed processing unit is used for adjusting the position and speed of the motor, the pulse and direction unit is used for sending a pulse signal to the motor, the position and speed processing unit is used for sending the speed increment after the position and speed of the motor are adjusted to the pulse and direction unit, and the pulse and direction unit is used for sending the position feedback value of the motor to the position and speed processing unit, as shown in fig. 2.
And 102, performing self-adaptive adjustment on the first speed and compensating the first speed to obtain a second speed, wherein the first speed is obtained by a position value of a first sampling period, a position value of a second sampling period and a fixed sampling period, and the time of the second sampling period is before the first sampling period.
The first speed can be understood as a speed corresponding to the first sampling period, the expected number of pulses is obtained based on a position expected value and a scaling ratio before the first speed is subjected to self-adaptive adjustment and compensation to obtain a second speed, and the first speed is subjected to self-adaptive adjustment and compensation if the actual number of pulses is smaller than the expected number of pulses; the second sampling period is timed before the first sampling period, and it is understood that the second sampling period is a previous sampling period to the first sampling period.
And 103, carrying out amplitude limiting processing on the second speed to obtain a third speed based on a maximum speed limit and a maximum actual speed, wherein the maximum speed limit and the maximum actual speed are obtained from the second parameter.
The third speed obtained by performing amplitude limiting processing on the second speed may be obtained by performing nonlinear saturation processing on the second speed, and limiting the maximum value of the absolute value of the second speed, so as to ensure that the pulse output speed in practical application is within a reasonable range, the pulse output speed may be understood as the pulse frequency, the reasonable range may be 52Khz to 5Mhz, the reasonable range may be artificially set, and the maximum practical speed may be obtained by limiting the scaling ratio and the maximum speed.
And 104, performing overflow processing on the position values of the pulse and direction units based on the third speed and the second parameter to obtain a first position feedback value, wherein the first position feedback value is used for adaptive adjustment of the first speed of the next round obtained based on the position value of the first sampling period, the position value of the third sampling period and the fixed sampling period, and the time of the third sampling period is after the first sampling period.
The first position feedback value can be understood as a position feedback value corresponding to the first sampling period, and since the adaptive adjustment of the first sampling period is applied to the position feedback value corresponding to the second sampling period, the first position feedback value is applied to the adaptive adjustment of the speed corresponding to the third sampling period (i.e., the first speed of the next round); the overflow processing of the position values of the pulse and direction units is completed in the pulse and direction units; the time of the third sampling period may be after the first sampling period a next sampling period where the third sampling period is the first sampling period.
In addition, in the third sampling period, the third speed may be a speed corresponding to the first sampling period.
It should be noted that, in the motor driving pulse generating method, there is theoretically jitter in the pulse generating process.
In the embodiment of the invention, a first parameter is obtained, and amplitude limiting processing is performed on the first parameter to obtain a second parameter, wherein the first parameter comprises a position expected value, a scaling ratio, a pulse duty ratio, a pulse commutation time, a position value of a first sampling period, a position value of a second sampling period and a fixed sampling period; the method comprises the steps of carrying out self-adaptive adjustment and compensation on a first speed to obtain a second speed, wherein the first speed is obtained by a position value of a first sampling period, a position value of a second sampling period and a fixed sampling period, and the time of the second sampling period is before the first sampling period; performing amplitude limiting processing on the second speed to obtain a third speed based on a maximum speed limit and a maximum actual speed, wherein the maximum speed limit and the maximum actual speed are obtained from the second parameter; and performing overflow processing on the position values of the pulse and direction units based on the third speed and the second parameter to obtain a first position feedback value, wherein the first position feedback value is used for adaptive adjustment of the first speed of the next round based on the position value of the first sampling period, the position value of a third sampling period and the fixed sampling period, and the time of the third sampling period is after the first sampling period. Thus, the first speed is adaptively adjusted and compensated, and the reliability of the conventional motor drive pulse generation method is improved.
Optionally, as shown in fig. 1, the performing amplitude limiting processing on the first parameter to obtain a second parameter includes:
and carrying out amplitude limiting processing on the pulse duty ratio and the pulse reversing time to obtain the second parameter.
The pulse duty ratio and the pulse reversing time are subjected to amplitude limiting processing, so that the pulse and direction unit can regulate the pulse speed to be stable.
It should be noted that the pulse duty ratio is equal to the duration of the high level in one pulse period divided by the duration of one pulse period, the duration of one pulse period is obtained by adding the duration of the high level in the pulse period and the duration of the low level in the pulse period, and the pulse duty ratio is set to complete the pulse width modulation.
In the embodiment of the invention, amplitude limiting processing is carried out on the pulse duty ratio and the pulse commutation time, so that the stability of the motor driving pulse generation method is improved.
Alternatively, as shown in fig. 1, the first speed is obtained by the following formula:
new_position_cmd=stepgen_position_cmd
v1=(new_position_cmd-old_position_cmd)/fperiod
wherein stepgen _ position _ cmd is the position expectation value, new _ position _ cmd is the position value of the first sampling period, v1 is the first velocity, old _ position _ cmd is the position value of the second sampling period, and fperiod is the fixed sampling period.
Assigning the position expected value to the position value of the first sampling period, and calculating a first speed; in a start-up phase of the generation of the motor drive pulse, i.e. when the second sampling period is zero, the position value of the second sampling period may be zero.
In the embodiment of the invention, the first speed is obtained by the position value of the first sampling period, the position value of the second sampling period and the sampling period, and the speed (namely the first speed) corresponding to the first sampling period is calculated by the position expected position (namely the position value of the first sampling period), so that the adjustability of the motor drive pulse generation method is further improved.
Optionally, as shown in fig. 1, the first speed is adaptively adjusted and compensated to obtain a second speed by the following formula:
v12=v1-m*est_err/fperiod
est_err=stepgen_position_fb+old_velocity_cmd*fperiod-new_position_cmd
wherein v12 is a median variable of the first speed and the second speed, m is an adjustment coefficient, scale is a scaling ratio, n is an adjustment coefficient, est _ err is an error value, stepgen _ position _ fb is a position feedback value corresponding to the second sampling period, and old _ velocity _ cmd is a speed corresponding to the second sampling period.
Where v12 has positive and negative values, n may have a value of 0.5, scale may have a value of 1000, and old _ vector _ cmd _ fperiod may be a fine tuning variable.
In the embodiment of the invention, the first speed is subjected to self-adaptive adjustment and compensated to obtain the second speed, so that the position value of the motor approaches to the expected position value, and the reliability of the motor driving pulse generation method is further improved.
Optionally, as shown in fig. 1, the performing amplitude limiting processing on the second speed based on the maximum speed limit and the maximum actual speed to obtain a third speed includes:
taking the smaller of the maximum speed limit and the maximum actual speed and setting it as the maximum value of the second speed;
if the second speed is less than the maximum value of the second speed, determining the second speed as the third speed;
and if the second speed is greater than or equal to the maximum value of the second speed, determining the maximum value of the second speed as the third speed.
In the embodiment of the invention, one of the maximum speed limit and the maximum actual speed which is small is taken and set as the maximum value of the second speed, the second speed is limited, the motor jitter is avoided, and the reliability of the motor driving pulse generating method is further improved.
Alternatively, as shown in fig. 1, the maximum speed limit and the maximum actual speed are obtained by the following formulas:
fmax=1.0/speed/(p_factor+steplen+stepspace)
actual_max=fmax/scale
wherein fmax is the maximum speed limit, actual _ max is the maximum actual speed, p _ factor is an adjustment coefficient, speed is a pulse speed, steplen is a high level duration in one pulse period, and stepspace is a low level duration in one pulse period.
The value range of the p _ factor can be 0-3, the fmax can be finely adjusted, and speed is the pulse speed in the pulse and direction unit and can also be understood as the output pulse speed of the motor.
In the embodiment of the invention, the stability of the motor can be ensured by setting the maximum speed limit and the maximum actual speed, and the reliability of the motor driving pulse generating method is further improved.
Optionally, as shown in fig. 1, the first position feedback value is obtained by the following formula:
v_inc=v3*q0*speed/q1
stepgen_position_fb=velocity_fb*fperiod
velocity_fb=(count-last_count)/scale/fperiod/M
wherein v3 is the third speed, v _ inc is the speed increment, q0 and q1 are both adjustment coefficients, velocity _ fb is the first speed feedback value, count is the pulse count of the first sampling period, last _ count is the pulse count of the second sampling period, and M is an adjustment coefficient.
Wherein q0 is the power of N of 2, the value range of N can be 10-20, the value range of q1 can be 1-8, and the value of M can be 2048.
The method comprises the steps of obtaining a speed increment based on a third speed and a second parameter, conducting overflow processing on position values of a pulse and direction unit to obtain a first speed feedback value, and obtaining a first position feedback value according to the first speed feedback value and a fixed sampling period.
It should be noted that the movement time of the motor may be divided into a certain number of time intervals, after each time interval is timed, after the time interval is adjusted by the position and speed processing unit, the speed increment v _ inc is accumulated to the position value variable, if the position value variable overflows, the pulse and direction unit may output a pulse, the motor operates in one step, the speed increment v _ inc changes according to each position value adjustment change, and as the time is continuously accumulated, the speed increment v _ inc continuously increases, and the position value variable overflows, as shown in fig. 3.
In the embodiment of the invention, the speed increment is obtained based on the third speed and the second parameter, the position values of the pulse and direction units are subjected to overflow processing to obtain the first speed feedback value, and the first position feedback value is obtained according to the first speed feedback value and the fixed sampling period, so that preparation is made for the self-adaptive adjustment corresponding to the next sampling period, and the reliability of the motor driving pulse generation method is further improved.
As shown in fig. 4, fig. 4 is a schematic structural diagram of a motor driving pulse generating device according to an embodiment of the present invention, and as shown in fig. 4, the motor driving pulse generating device 400 includes:
an obtaining module 401, configured to obtain a first parameter, and perform amplitude limiting processing on the first parameter to obtain a second parameter, where the first parameter includes a position expected value, a scaling ratio, a pulse duty cycle, a pulse commutation time, a position value of a first sampling period, a position value of a second sampling period, and a fixed sampling period;
an adjusting module 402, configured to perform adaptive adjustment and compensation on a first speed to obtain a second speed, where the first speed is obtained by a position value of a first sampling period, a position value of a second sampling period, and a fixed sampling period, and a time of the second sampling period is before the first sampling period;
a speed limit module 403, configured to perform amplitude limiting processing on the second speed to obtain a third speed based on a maximum speed limit and a maximum actual speed, where the maximum speed limit and the maximum actual speed are obtained from the second parameter;
a feedback module 404, configured to perform overflow processing on the position values of the pulse and direction units based on the third speed and the second parameter to obtain a first position feedback value, where the first position feedback value is used for adaptive adjustment of a first speed of a next round obtained based on the position value of the first sampling period, the position value of a third sampling period, and the fixed sampling period, and a time of the third sampling period is after the first sampling period.
Optionally, the obtaining module 401 is configured to:
and carrying out amplitude limiting processing on the pulse duty ratio and the pulse reversing time to obtain the second parameter.
Optionally, the adjusting module 402 is configured to calculate the first speed:
new_position_cmd=stepgen_position_cmd
v1=(new_position_cmd-old_position_cmd)/fperiod
wherein stepgen _ position _ cmd is the position expectation value, new _ position _ cmd is the position value of the first sampling period, v1 is the first velocity, old _ position _ cmd is the position value of the second sampling period, and fperiod is the fixed sampling period.
Optionally, the adjusting module 402 is further configured to calculate the second speed:
v12=v1-m*est_err/fperiod
est_err=stepgen_position_fb+old_velocity_cmd*fperiod-new_position_cmd
wherein v12 is a median variable of the first speed and the second speed, m is an adjustment coefficient, scale is a scaling ratio, n is an adjustment coefficient, est _ err is an error value, stepgen _ position _ fb is a position feedback value corresponding to the second sampling period, and old _ velocity _ cmd is a speed corresponding to the second sampling period.
Optionally, the speed limit module 403 is configured to:
taking the smaller of the maximum speed limit and the maximum actual speed and setting it as the maximum value of the second speed;
if the second speed is less than the maximum value of the second speed, determining the second speed as the third speed;
and if the second speed is greater than or equal to the maximum value of the second speed, determining the maximum value of the second speed as the third speed.
Optionally, the speed limit module 403 is further configured to calculate the maximum speed limit and the maximum actual speed:
fmax=1.0/speed/(p_factor+steplen+stepspace)
actual_max=fmax/scale
wherein fmax is the maximum speed limit, actual _ max is the maximum actual speed, p _ factor is an adjustment coefficient, speed is a pulse speed, steplen is a high level duration in one pulse period, and stepspace is a low level duration in one pulse period.
Optionally, the speed limit module 403 is further configured to calculate the first feedback position value:
v_inc=v3*q0*speed/q1
velocity_fb=(count-last_count)/scale/fperiod/M
stepgen_position_fb=velocity_fb*fperiod
wherein v3 is the third speed, v _ inc is the speed increment, q0 and q1 are both adjustment coefficients, velocity _ fb is the first speed feedback value, count is the pulse count of the first sampling period, last _ count is the pulse count of the second sampling period, and M is an adjustment coefficient.
The motor driving pulse generating device provided by the embodiment of the invention can realize each process realized in the method embodiment of fig. 1, can achieve the same beneficial effects, and is not repeated here for avoiding repetition.
As shown in fig. 5, fig. 5 is a schematic structural diagram of another motor driving pulse generating device according to an embodiment of the present invention, including: a processor 501, a memory 502 and a computer program stored on the memory 502 and executable on the processor.
Wherein the computer program when executed by the process 501 implements the steps of:
acquiring a first parameter, and performing amplitude limiting processing on the first parameter to obtain a second parameter, wherein the first parameter comprises a position expected value, a scaling ratio, a pulse duty ratio, a pulse commutation time, a position value of a first sampling period, a position value of a second sampling period and a fixed sampling period;
the method comprises the steps of carrying out self-adaptive adjustment and compensation on a first speed to obtain a second speed, wherein the first speed is obtained by a position value of a first sampling period, a position value of a second sampling period and a fixed sampling period, and the time of the second sampling period is before the first sampling period;
performing amplitude limiting processing on the second speed to obtain a third speed based on a maximum speed limit and a maximum actual speed, wherein the maximum speed limit and the maximum actual speed are obtained from the second parameter;
and performing overflow processing on the position values of the pulse and direction units based on the third speed and the second parameter to obtain a first position feedback value, wherein the first position feedback value is used for adaptive adjustment of the first speed of the next round based on the position value of the first sampling period, the position value of a third sampling period and the fixed sampling period, and the time of the third sampling period is after the first sampling period.
Optionally, the performing, by the processor 501, the amplitude limiting processing on the first parameter to obtain a second parameter includes:
and carrying out amplitude limiting processing on the pulse duty ratio and the pulse reversing time to obtain the second parameter.
Optionally, the first speed executed by the processor 501 is obtained by the following formula:
new_position_cmd=stepgen_position_cmd
v1=(new_position_cmd-old_position_cmd)/fperiod
wherein stepgen _ position _ cmd is the position expectation value, new _ position _ cmd is the position value of the first sampling period, v1 is the first velocity, old _ position _ cmd is the position value of the second sampling period, and fperiod is the fixed sampling period.
Optionally, the processor 501 performs adaptive adjustment on the first speed and performs compensation to obtain a second speed according to the following formula:
v12=v1-m*est_err/fperiod
est_err=stepgen_position_fb+old_velocity_cmd*fperiod-new_position_cmd
wherein v12 is a median variable of the first speed and the second speed, m is an adjustment coefficient, scale is a scaling ratio, n is an adjustment coefficient, est _ err is an error value, stepgen _ position _ fb is a position feedback value corresponding to the second sampling period, and old _ velocity _ cmd is a speed corresponding to the second sampling period.
Optionally, the performing, by the processor 501, a clipping process on the second speed based on the maximum speed limit and the maximum actual speed to obtain a third speed includes:
taking the smaller of the maximum speed limit and the maximum actual speed and setting it as the maximum value of the second speed;
if the second speed is less than the maximum value of the second speed, determining the second speed as the third speed;
and if the second speed is greater than or equal to the maximum value of the second speed, determining the maximum value of the second speed as the third speed.
Optionally, the maximum speed limit and the maximum actual speed executed by the processor 501 are obtained by the following formulas:
fmax=1.0/speed/(p_factor+steplen+stepspace)
actual_max=fmax/scale
wherein fmax is the maximum speed limit, actual _ max is the maximum actual speed, p _ factor is an adjustment coefficient, speed is a pulse speed, steplen is a high level duration in one pulse period, and stepspace is a low level duration in one pulse period.
Optionally, the first position feedback value executed by the processor 501 is obtained by the following formula:
v_inc=v3*q0*speed/q1
velocity_fb=(count-last_count)/scale/fperiod/M
stepgen_position_fb=velocity_fb*fperiod
wherein v3 is the third speed, v _ inc is the speed increment, q0 and q1 are both adjustment coefficients, velocity _ fb is the first speed feedback value, count is the pulse count of the first sampling period, last _ count is the pulse count of the second sampling period, and M is an adjustment coefficient.
The motor driving pulse generating device provided by the embodiment of the invention can realize each process realized in the method embodiment of fig. 1, can achieve the same beneficial effects, and is not repeated here for avoiding repetition.
The embodiment of the present invention further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program implements each process of the digital signal filtering method embodiment, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here. The computer-readable storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.