PID control-based stepping motor double-closed-loop control method and system

文档序号:326013 发布日期:2021-11-30 浏览:70次 中文

阅读说明:本技术 一种基于pid控制的步进电机双闭环控制方法及系统 (PID control-based stepping motor double-closed-loop control method and system ) 是由 华庆 陈曦童 郝新源 王寰宇 于 2021-07-27 设计创作,主要内容包括:本公开提供了一种基于PID控制的步进电机双闭环控制方法及系统,包括PID控制器、驱动器、步进电机和编码器,所述驱动器分别与所述PID控制器和步进电机相连接;所述编码器与步进电机相连接;所述PID控制器包括分别与编码器相连接的速度环和位置环;所述PID控制器基于编码器的总脉冲数和上位机所设定的第一目标值进行计算,得到用于控制步进电机方向的位置环期望值;通过PID控制器设置控制系数,结合所得到的位置环期望值判断是否开启速度环控制,使得步进电机在距离目标值远时采用速度环控制、在即将达到目标值时采用位置环控制。(The utility model provides a stepping motor double closed loop control method and system based on PID control, comprising a PID controller, a driver, a stepping motor and an encoder, wherein the driver is respectively connected with the PID controller and the stepping motor; the encoder is connected with the stepping motor; the PID controller comprises a speed ring and a position ring which are respectively connected with the encoder; the PID controller calculates based on the total pulse number of the encoder and a first target value set by an upper computer to obtain a position ring expected value for controlling the direction of the stepping motor; and setting a control coefficient through a PID controller, and judging whether to start speed loop control or not by combining the obtained expected value of the position loop, so that the stepping motor adopts speed loop control when being far away from the target value and adopts position loop control when reaching the target value.)

1. A stepping motor double closed loop control system based on PID control is characterized by comprising a PID controller, a driver, a stepping motor and an encoder, wherein the driver is respectively connected with the PID controller and the stepping motor; the encoder is connected with the stepping motor; the PID controller comprises a speed ring and a position ring which are respectively connected with the encoder;

the PID controller calculates based on the total pulse number of the encoder and a first target value set by an upper computer to obtain a position ring expected value for controlling the direction of the stepping motor; and setting a control coefficient through a PID controller, and judging whether to start speed loop control or not by combining the obtained expected value of the position loop, so that the stepping motor adopts speed loop control when being far away from the target value and adopts position loop control when being close to the target value.

2. A PID control based stepper motor dual closed loop control system as claimed in claim 1, wherein the PID controller further comprises a current loop arranged between the speed loop and the stepper motor.

3. A PID control based stepper motor dual closed loop control system as claimed in claim 2, characterized in that the current loop forms a PID regulated negative feedback inside the current loop by the difference between the output value of the speed loop control and the current voltage signal induced by each phase hall element installed inside the driver.

4. A PID control based stepper motor dual closed loop control system as claimed in claim 1, wherein the PID controller employs STM32 and the encoder employs a rotary encoder.

5. A PID control-based stepper motor dual closed loop control system as claimed in claim 1, wherein the encoder is provided at one side of the stepper motor to sample the rotational speed of the stepper motor.

6. A double closed-loop control method of a stepping motor based on PID control is characterized by comprising the following steps:

calculating a pulse signal acquired by an encoder to obtain the total pulse number and the pulse number of unit time;

inputting the obtained total pulse number serving as a first actual value and a first target value set in an upper computer into a position ring, and calculating to obtain a position ring expected value based on a PID algorithm;

controlling the rotation direction of the stepping motor according to the expected value of the position ring;

setting a control coefficient based on a PID controller, and judging whether to start speed loop control or not by comparing the magnitude between the control coefficient and a position loop expected value; and starting speed loop control when the expected value of the position loop is greater than the control coefficient, calculating the output comparison value of the second PWM of the stepping motor according to the expected value of the speed loop, and otherwise, directly calculating the output comparison value of the first PWM of the stepping motor according to the expected value of the position loop.

7. The double closed-loop control method for the stepping motor based on the PID control as claimed in claim 6, wherein the total pulse number is equal to the sum of the product of the overflow times of the timer and the reloading value of the counter and the counting value of the current timer; the number of pulses per unit time is equal to the difference between the current total number of pulses and the previous total number of pulses.

8. The PID control-based double closed-loop control method of the stepping motor according to claim 6, wherein the current error e (k) is obtained by subtracting the first target value and the first actual value, and the accumulated error is obtained by accumulating the current error e (k)Assigning the current error e (k) to the last error e (k-1), and taking the current error e (k) as the last error e (k) -e (k-1) of the next calculation, and accumulating the current error e (k) and the accumulated errorAnd the last error e (K) -e (K-1) calculated next time and a proportionality coefficient K preset in the PID controllerPIntegral coefficient KIAnd a differential coefficient KDPerforming mathematical operation to obtain the expected value of the position ring

9. The PID control-based stepper motor dual closed-loop control method as claimed in claim 6, wherein the stepper motor rotates clockwise if the position loop desired value is regular, and rotates counterclockwise if the position loop desired value is negative.

10. A PID control-based stepper motor dual closed loop control method as claimed in claim 6,

and when the expected value of the position ring is greater than the control coefficient, starting speed ring control, which comprises the following specific processes:

transmitting the expected value of the position ring to another variable, and setting the maximum starting speed;

if the predicted starting speed in the PID controller is higher than the maximum starting speed, the stepping motor cannot be started normally, and the maximum starting speed is set as the starting speed; if the predicted starting speed in the PID controller is less than the maximum starting speed, the stepping motor can be normally started;

inputting the expected value of the position ring as a second target value and the pulse number of unit time as a second actual value into the speed ring, and calculating to obtain the expected value of the speed ring based on a PID algorithm; and calculating an output comparison value of the second PWM of the stepping motor through the speed ring expected value.

Technical Field

The disclosure belongs to the technical field of motor control, and particularly relates to a stepping motor double-closed-loop control method and system based on PID control.

Background

The statements in this section merely provide background information related to the present disclosure and may not necessarily constitute prior art.

The stepping motor is a motor which converts an electric pulse signal into corresponding angular displacement or linear displacement; the rotor rotates an angle or one step before inputting a pulse signal, the output angular displacement or linear displacement is proportional to the input pulse number, and the rotating speed is proportional to the pulse frequency.

As the inventor knows, the conventional proportional-integral-derivative (PID) single closed loop control has certain defects in the control of the stepping motor: although the speed ring closed-loop control can accurately control the rotating speed of the stepping motor, the accurate control on the position of the stepping motor is difficult to realize; although the closed-loop control of the position ring can accurately control the rotation angle of the stepping motor, the locked-rotor of the stepping motor is effectively prevented by artificially limiting the speed. The traditional PID double closed loop control easily causes the overshoot phenomenon of the stepping motor when reaching the set target value.

Therefore, it is necessary to study the double closed loop control of the stepping motor.

Disclosure of Invention

In order to solve the defects of the prior art, the disclosure provides a method and a system for controlling a double closed loop of a stepping motor based on PID control, wherein whether speed loop control is started or not is judged by setting a control coefficient and combining a position loop expected value, so that the stepping motor adopts speed loop control when the distance from a target value is far, and adopts position loop control when the distance is about to reach the target value, thereby effectively solving the overshoot phenomenon of the stepping motor.

In order to achieve the purpose, the following technical scheme is adopted in the disclosure:

according to some embodiments, a first aspect of the present disclosure provides a dual closed-loop control system for a stepper motor based on PID control, which adopts the following technical solutions:

a stepping motor double closed loop control system based on PID control comprises a PID controller, a driver, a stepping motor and an encoder, wherein the driver is respectively connected with the PID controller and the stepping motor; the encoder is connected with the stepping motor; the PID controller comprises a speed ring and a position ring which are respectively connected with the encoder;

the PID controller calculates based on the total pulse number of the encoder and a first target value set by the PID controller to obtain a position ring expected value for controlling the direction of the stepping motor; and setting a control coefficient through a PID controller, and judging whether to start speed loop control or not by combining the obtained expected value of the position loop, so that the stepping motor adopts speed loop control when being far away from the target value and adopts position loop control when reaching the target value.

According to some embodiments, a second aspect of the present disclosure provides a method for controlling a double closed-loop of a stepper motor based on PID control, which adopts the following technical solutions:

a double closed-loop control method of a stepping motor based on PID control comprises the following steps:

calculating a pulse signal acquired by an encoder to obtain the total pulse number and the pulse number of unit time;

inputting the obtained total pulse number serving as a first actual value and a first target value set in an upper computer into a position ring, and calculating to obtain a position ring expected value based on a PID algorithm;

controlling the rotation direction of the stepping motor according to the expected value of the position ring;

setting a control coefficient based on a PID controller, and judging whether to start speed loop control or not by comparing the magnitude between the control coefficient and a position loop expected value; and starting speed loop control when the expected value of the position loop is greater than the control coefficient, calculating the output comparison value of the second PWM of the stepping motor according to the expected value of the speed loop, and otherwise, directly calculating the output comparison value of the first PWM of the stepping motor according to the expected value of the position loop.

Compared with the prior art, the beneficial effect of this disclosure is:

according to the method and the device, the control coefficient is set, and whether the speed loop control is started or not is judged by combining the expected value of the position loop, so that the speed loop control is adopted when the control coefficient is far away from the target value of the position loop, and the position loop control is adopted when the target value of the position loop is reached, so that the overshoot phenomenon of the stepping motor is effectively solved.

Drawings

The accompanying drawings, which are included to provide a further understanding of the disclosure, illustrate embodiments of the disclosure and together with the description serve to explain the disclosure and are not to limit the disclosure.

Fig. 1 is a block diagram of a double closed-loop control system of a stepping motor based on PID control in a first embodiment of the disclosure;

fig. 2 is a flowchart of a method for controlling a double closed-loop of a stepping motor based on PID control in the second embodiment of the disclosure.

The specific implementation mode is as follows:

the present disclosure is further described with reference to the following drawings and examples.

It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the disclosure. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs.

It is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of example embodiments according to the present disclosure. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, and it should be understood that when the terms "comprises" and/or "comprising" are used in this specification, they specify the presence of stated features, steps, operations, devices, components, and/or combinations thereof, unless the context clearly indicates otherwise.

The embodiments and features of the embodiments in the present disclosure may be combined with each other without conflict.

Example one

The first embodiment of the disclosure provides a stepping motor double-closed-loop control system based on PID control.

The stepping motor double closed loop control system based on PID control shown in FIG. 1 comprises a PID controller, a driver, a stepping motor and an encoder, wherein the driver is respectively connected with the PID controller and the stepping motor; the encoder is connected with the stepping motor; the PID controller comprises a current loop, a speed loop and a position loop which are respectively connected with an encoder.

The PID controller calculates based on the total pulse number of the encoder and a first target value set by an upper computer to obtain a position ring expected value for controlling the direction of the stepping motor; and setting a control coefficient through a PID controller, and judging whether to start speed loop control or not by combining the obtained expected value of the position loop, so that the stepping motor adopts speed loop control when being far away from the target value and adopts position loop control when reaching the target value.

As one or more embodiments, the PID controller is typically a three-loop control system, with a current loop, a speed loop, and a position loop in order from inside to outside.

The input value of the current loop (namely the current loop set value) is the output value of the speed loop after PID adjustment, the current loop set value and the feedback value of the current loop are compared and compared to obtain a difference value, and the obtained difference value is subjected to PID adjustment in the current loop to be output to the stepping motor; the feedback of the current loop here is not the feedback in the encoder, but a hall element (magnetic field induced to become a current-voltage signal) installed inside the driver at each phase is fed back to the current loop. The current loop forms a negative feedback of PID regulation inside the current loop through the difference between the output value controlled by the speed loop and the current voltage signal induced by each phase of Hall element installed inside the driver.

The input of the speed loop (namely speed setting) is the output value of the position loop after PID adjustment and the feedforward value of the position setting, the speed setting and the feedback value of the speed loop are compared and compared to be differenced, the obtained difference value is output after the PID adjustment (mainly proportional gain and integral processing) is carried out on the speed loop, and the output value is the current loop set value in the current loop. The feedback of the speed loop is obtained by a speed arithmetic unit from the feedback value of the encoder.

The input of the position loop is an external pulse signal (usually, the servo exception of directly writing data to a driver address), the external pulse signal is used as a position loop set value after being subjected to smoothing filtering processing and electronic gear calculation, the position loop set value and a numerical value obtained by subjecting the pulse signal fed back from an encoder to calculation of a deviation counter are subjected to PID (proportion integration differentiation) adjustment (proportional gain adjustment and non-integral differential link) of the position loop, and then a resultant value of the position loop set value and a feedforward signal given by the position is output, and the resultant value is set by the speed loop. Feedback for the position loop also comes from the encoder.

The encoder is arranged at the tail part of the stepping motor and is not in any connection with the current loop, the sampling signal of the encoder is from the rotation of the motor instead of the motor current, and the input, the output and the feedback of the current loop are not in any connection. The current loop is formed inside the driver, and even without a motor, feedback operation can be formed by only installing an analog load (e.g., light bulb) current loop on each phase.

In this implementation, the PID controller employs STM32 and the encoder employs a rotary encoder.

Example two

The second embodiment of the disclosure provides a stepping motor double closed-loop control method based on PID control, and adopts the stepping motor double closed-loop control system based on PID control provided in the first embodiment.

As shown in fig. 2, the double closed-loop control system for the stepper motor based on PID control includes the following steps:

step S01: calculating a pulse signal acquired by an encoder to obtain the total pulse number and the pulse number of unit time;

step S02: inputting the obtained total pulse number serving as a first actual value and a first target value set in an upper computer into a position ring, and calculating to obtain a position ring expected value based on a PID algorithm;

step S03: controlling the rotation direction of the stepping motor according to the expected value of the position ring;

step S04: setting a control coefficient based on a PID controller, and judging whether to start speed loop control or not by comparing the magnitude between the control coefficient and a position loop expected value; when the expected value of the position ring is larger than the control coefficient, starting speed ring control, executing step S05, otherwise, directly calculating the output comparison value of the first PWM of the stepping motor according to the expected value of the position ring;

step S05: processing data before calculating the expected value of the speed ring;

step S06: and calculating the speed ring expected value and the output value of the second PWM of the stepping motor.

As one or more embodiments, before step S01, the clock and the peripheral devices of the control system are initialized, and the input of the first target value is performed by the upper computer.

In one or more embodiments, in step S01, the total pulse number is equal to the sum of the product of the timer overflow count and the counter reload value, and the current timer count value; the number of pulses per unit time is equal to the difference between the current total number of pulses and the previous total number of pulses.

In one or more embodiments, in step S02, the first target value and the first actual value are subtracted to obtain a current error e (k), and the current error e (k) is accumulated to obtain an accumulated errorAssigning the current error e (k) to the last error e (k-1), and taking the current error e (k) as the last error e (k) -e (k-1) of the next calculation, and accumulating the current error e (k) and the accumulated errorAnd the last error e (K) -e (K-1) calculated next time and a proportionality coefficient K preset in the PID controllerPIntegral coefficient KIAnd a differential coefficient KDPerforming mathematical operation to obtain the expected value of the position ring

In one or more embodiments, in step S03, the stepper motor rotates clockwise if the position ring desired value is normal and rotates counterclockwise if the position ring desired value is negative.

As one or more embodiments, in step S04, the output comparison value of the first PWM of the stepping motor is used to control the duty ratio of the PWM wave of the stepping motor, and is related to the counting frequency of the comparison counter, the expected value of the position loop, the sampling frequency of the encoder, and the pulse signal ratio (the pulse signal ratio is the ratio of the number of pulses per single turn of the stepping motor to the number of pulses per single turn of the encoder), that is, the ratio

As one or more embodiments, in step S05, the position loop desired value is passed to another variable and the maximum start speed is set;

if the predicted starting speed in the PID controller is higher than the maximum starting speed, the stepping motor cannot be started normally, and the maximum starting speed is set as the starting speed; if the predicted starting speed in the PID controller is lower than the maximum starting speed, the stepping motor can be normally started, and the step motor is effectively prevented from being locked during starting.

In one or more embodiments, in step S06, the position loop expected value is input to the speed loop as the second target value, and the pulse number per unit time is input to the speed loop as the second actual value, and the speed loop expected value is calculated based on the PID algorithm; and calculating an output comparison value of the second PWM of the stepping motor through the speed ring expected value.

Specifically, the second target value and the second actual value are subtracted to obtain a current error e (k), and the current error e (k) is accumulated to obtain an accumulated errorAssigning the current error E (k) to the last error E (k-1), and assigning the current error E (k) to the last error E (k-1) as the next error E (k) -E (k-1), and accumulating the current error E (k) and the accumulated errorAnd the last error E (K) -E (K-1) calculated next time and a proportionality coefficient K preset in the PID controllerPIntegral coefficient KIAnd a differential coefficient KDPerforming mathematical operation to obtain the expected value of the speed loop

The output comparison value of the second PWM of the stepping motor is used for controlling the duty ratio of the PWM wave of the stepping motor and is related to the counting frequency of the comparison counter, the expected value of a speed ring, the sampling frequency of the encoder and the pulse signal ratio (the pulse signal ratio is the ratio of the number of single-circle pulses of the stepping motor to the number of single-circle pulses of the encoder), namely

According to the method and the device, the control coefficient is set, and whether the speed loop control is started or not is judged by combining the expected value of the position loop, so that the speed loop control is adopted when the control coefficient is far away from the target value of the position loop, and the position loop control is adopted when the target value of the position loop is reached, so that the overshoot phenomenon of the stepping motor is effectively solved.

The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure, and various modifications and changes may be made to the present disclosure by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present disclosure should be included in the protection scope of the present disclosure.

10页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种旋转风力发电机的方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!