Brushless direct current motor control method of industrial sewing machine

By improving the whale algorithm to optimize the PID controller and STM32 control chip, the problems of high precision and stability in the control of permanent magnet synchronous motors in industrial sewing machines were solved, achieving efficient control of brushless DC motors and improving the control performance and energy efficiency of sewing machines.

CN122026752APending Publication Date: 2026-05-12RES INST OF ZHEJIANG UNIV TAIZHOU
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
RES INST OF ZHEJIANG UNIV TAIZHOU
Filing Date
2026-02-09
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In existing industrial sewing machines, the control methods for permanent magnet synchronous motors cannot meet the requirements of high precision, speed, and stability, and the cost is relatively high.

Method used

By employing a brushless DC motor and optimizing the PID controller parameters through an improved whale algorithm, combined with an STM32 control chip and motor drive hardware design, efficient control of the brushless DC motor is achieved.

Benefits of technology

It improves the control performance of sewing machines, achieves low carbon and energy saving, and enhances the stability, speed and accuracy of the system, enabling quick and accurate needle stopping.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122026752A_ABST
    Figure CN122026752A_ABST
Patent Text Reader

Abstract

The invention discloses a control method for a brushless direct current motor of an industrial sewing machine. The control method comprises the following steps: step 1, designing the structure of the brushless direct current motor of the industrial sewing machine; 2, setting a brushless direct current motor rotating speed control method based on the whale algorithm optimization PID; 3, designing software and hardware of a brushless direct current motor control system; according to the industrial sewing machine numerical control system parameter design method, by designing the structure of the industrial sewing machine brushless direct current motor, rotating speed control, control system software and hardware and the numerical control system parameters, the control performance is greatly improved, and meanwhile the purposes of low carbon and energy saving are achieved. Meanwhile, the stability, rapidity and accuracy of the system are improved, and needle stopping is rapid and accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of industrial sewing machines and relates to a brushless DC motor control method for industrial sewing machines. Background Technology

[0002] Industrial sewing machines refer to sewing machines used in sewing factories or other industrial sectors for mass production. In the design of high-precision sewing machines, the most important aspect is the accurate control of the motor. This ensures that the needle moves quickly and precisely, with accurate stitch count and thread cutting during high-speed operation. Currently, permanent magnet synchronous motors are the primary type used, but this increases costs. Furthermore, the control methods for permanent magnet synchronous motors are relatively traditional, and their stability, speed, and accuracy cannot meet the higher precision control requirements of industrial sewing machines. Summary of the Invention

[0003] In order to overcome at least one deficiency of the prior art, the present invention provides a brushless DC motor control method for a sewing machine.

[0004] To achieve the above objectives, the present invention adopts the following technical solution: a brushless DC motor control method for a sewing machine, comprising the following steps: Step 1: Design the structure of the brushless DC motor for the sewing machine; Step 2: Establish a brushless DC motor speed control method based on PID optimization using the whale algorithm; Step 3: Design the hardware and software of the brushless DC motor control system; Step 4: Optimize the parameters of the CNC system of the sewing machine.

[0005] Furthermore, step 1 includes: Step 11: Set the outer diameter and effective length of the stator core of the brushless DC motor; Step 12: The brushless DC motor adopts a sloping shoulder round bottom groove structure; Step 13: The brushless DC motor uses neodymium iron boron material.

[0006] Furthermore, the improved whale algorithm in step 2 specifically includes: Step 21: Improve the local search mechanism of the whale algorithm; Step 22: Improve the PID parameter design of the whale algorithm.

[0007] Furthermore, the specific steps of step 2, improving the whale algorithm to optimize PID, are as follows: Step S1: Initialize relevant parameters. Initialize population size (number), current iteration count, maximum iteration count (Tmax), and dimension (dim); Step S2: Calculate the optimal fitness value for an individual whale; Step S3: Position Update: Input the fitness value into the brushless DC motor, tune the values ​​of Ke, Kec, Kp, Ki, and Kd, update the position, and calculate the parameter values; Step S4: Select update mechanism: Compare the P value with Q to select which update mechanism to update the position. If P < Q and A < 1, the whale uses bubble net hunting. If A ≥ 1, it uses random walk to search for prey and update the position. However, if P ≥ Q, it uses encirclement and spiral contraction to update the position. Compare and evaluate the performance indicators of the motor output and return with the whale's performance to determine the optimal position and the historical best position. Step S5: Termination Judgment: Determine if the updated optimal position is better than the best position in the previous iteration, and if the number of iterations has reached the maximum number of iterations, then terminate the algorithm. If the requirements are not met, continue with steps 2-4.

[0008] Step S6: Establish the motor model; Step S7: Assign the optimal fitness value, Ke, Kec, Kp, Ki, and Kd to the individual whale; Step S8: Run the motor model to obtain various performance indicators of the motor under no-load and load conditions.

[0009] Furthermore, step 3 includes: Step 31: Design the hardware for the motor drive control system; Step 32: Design the motor drive control system software.

[0010] Furthermore, the method for improving the local search mechanism of the whale algorithm in step 21 is as follows: The convergence factor and probability threshold are optimized, and a Gaussian mutation strategy factor and an adaptive factor are added. The adaptive weight strategy factor and the Gaussian mutation factor are introduced into the whale algorithm. The Gaussian mutation strategy factor and the adaptive weight factor are expressed as follows: In the formula, Tmax is the maximum number of iterations, r is a random number between [0,1], t is time, k is the variance of Gaussian mutation, and w is the adaptive weight factor. r follows a Gaussian mutation factor with a mean of 0 and a variance of k. The adaptive weight factor enables dynamic analysis and adjustment of the behavior of the whale pod and the characteristics of the problem. By adaptively adjusting the weight factor, the algorithm adapts to different problem scenarios and search spaces. w gradually decreases with the increase of the number of iterations, and k shows a decreasing trend as t increases from 1 to Tmax, which facilitates better convergence and accuracy of the search in the later stages.

[0011] Furthermore, the method for designing PID parameters for the improved whale algorithm in step 22 involves using the improved whale algorithm to optimize PID controller parameters. The PID algorithm parameters are then treated as target variables to be optimized, transforming the problem into a multivariate, multi-dimensional optimization problem. Simultaneously, these three parameters are input into the whale algorithm for optimization. The optimal solution is found through continuous iteration to obtain the best PID parameter values. The integral absolute error is used as the fitness function, and the integral of the product of the absolute value of the PID parameter deviation and time is used as the objective function for PID parameter tuning.

[0012] Furthermore, step 31 involves designing the hardware for the motor drive control system as follows: The main control chip is an STM32 controller chip. The STM32 chip has a motor control timer, and each timer has an independent DMA request mechanism. The chip simultaneously controls the output of 6 PWM waves. The STM32 is also equipped with two 12-bit AD converters. The drive circuit of the brushless DC motor adopts a three-phase half-bridge drive. The MOSFET model IRF540N is selected as the power switch. The output filter circuit filters out the high-frequency signals during motor operation. The signal acquisition and feedback circuit includes current signal detection and voltage signal detection. It collects the current during motor operation, processes it, and uses it as the control quantity in the control system. By adjusting the current, corresponding control and protection actions are performed.

[0013] Furthermore, the method for designing the motor drive control system software in step 32 involves initializing the system, including describing and assigning values ​​to variables, setting various ports, initializing the interrupt system, and the main program determining the rotor position of the motor through the received Hall sensor signal. Based on the working principle and control algorithm of the brushless DC motor, the program inputs corresponding on / off conditions to the power transistors through the driver. The motor repeats the algorithm program based on the feedback signal of the rotor position information, adjusting the motor speed to reach the set reference speed. The communication system software flow design begins with setting the serial port configuration, including setting the baud rate, data bits, and stop bits. Then, the serial port is initialized, defining the data frame header and trailer, updating the data in the data frame, and sending it to the host computer. This establishes successful communication between the microcontroller and the host computer based on the hardware circuitry. Information is continuously sent to the host computer through the communication serial port. After the A / D sampling and communication system debugging is completed, the system will continue to execute the algorithm control program, transmitting the collected phase voltage, phase current, and rotor position angle information to the STM32 microcontroller. The microcontroller, a control chip, calculates estimated values ​​of control quantities and speed based on the algorithm program design. Combining the estimated values ​​with the improved whale algorithm-optimized PID control results, the microcontroller issues control commands to turn on and off each power switch transistor through a pulse width modulation generator. This controls the on and off states of each power device, keeping the motor speed near the desired value, achieving the set speed and maintaining a stable state, thus realizing speed control of the brushless DC motor.

[0014] Furthermore, the method for optimizing the design parameters of the CNC system of the sewing machine in step 4 is that the control principle of the CNC system of the sewing machine adopts cascade control, with the position control loop preceding the speed control loop and taking precedence over the current control loop.

[0015] In summary, the advantages of this invention are: This invention significantly improves control performance and achieves low-carbon energy saving by redesigning the structure, speed control, control system hardware and software, and CNC system parameters of the brushless DC motor of the sewing machine. It also enhances the system's stability, speed, and accuracy, resulting in rapid and precise needle stopping. Attached Figure Description

[0016] Figure 1 This is a framework diagram for PID parameter tuning of the whale according to the present invention.

[0017] Figure 2 The flowchart for the improved whale algorithm optimized PID of this invention is shown below.

[0018] Figure 3 This is a flowchart of the main program of the motor control system software of the present invention. Detailed Implementation

[0019] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and features described therein can be combined with each other.

[0020] Example: like Figures 1-3 As shown, a brushless DC motor control method for a sewing machine includes the following steps: Step 1: Design the structure of the brushless DC motor for the sewing machine; Step 11: Set the outer diameter and effective length of the stator core of the brushless DC motor; The outer diameter of the stator core is related to the motor power, the permanent magnet pole arc coefficient, the electrical load, and the magnetic load, and satisfies the following formula: In the above formula, D a L is the outer diameter of the stator core. ef α is the effective length of the stator core; n is the rated speed (r / min) of the motor; P' is the calculated power of the motor; i To calculate the polar arc coefficient; A is the armature load; B δ The value is the air gap magnetic induction intensity.

[0021] Step 12: The brushless DC motor adopts a sloping shoulder round bottom groove structure; Step 13: The brushless DC motor uses neodymium iron boron material.

[0022] Step 2: Establish a brushless DC motor speed control method based on PID optimization using the whale algorithm; The Whale Algorithm takes the PID system error evaluation function as input, calculates the conditional function value, and optimizes the PID controller parameters to improve system control performance. Figure 1 In this diagram, R(t) represents the system's input signal, y(t) represents the system's output signal, E(t) represents the input-output deviation, and Kp, Ki, and Kd represent the key parameters of the PID controller. Changes in these parameters directly affect the performance of the PID controller.

[0023] Step 2, which improves the whale algorithm, specifically includes... Step 21: Improve the local search mechanism of the whale algorithm; The convergence factor and probability threshold are optimized, and a Gaussian mutation strategy factor and an adaptive factor are added. In the whale algorithm, the linearly varying convergence factor 'a' contributes poorly to adjusting global convergence and local exploitation capabilities. Therefore, a nonlinear convergence factor 'a' is proposed. As the number of iterations increases, 'a' continuously decreases, the whale's swimming stride becomes smaller, making it easier to approach prey, and the convergence accuracy increases. However, when searching for the optimal solution, it may fail to correctly escape local optima, prematurely ending the search for the optimal solution. To address the whale algorithm's inability to correctly escape local optima, an adaptive weight strategy factor and a Gaussian mutation factor are introduced into the whale algorithm. The Gaussian mutation strategy factor and the adaptive weight factor are expressed as: In the formula, Tmax is the maximum number of iterations, r is a random number between [0,1], t is time, k is the variance of the Gaussian mutation, and w is the adaptive weight factor. r follows a Gaussian mutation factor with a mean of 0 and a variance of k. Compared with a uniform distribution, a Gaussian distribution is more concentrated near the center, thus it is more conducive to escaping local optima and iterating towards the global optimum during the search process. The adaptive weight factor allows for dynamic analysis and adjustment of the whale swarm's behavior and problem characteristics, which can improve the robustness and convergence of the whale algorithm. By adaptively adjusting the weight factor, the algorithm can more flexibly adapt to different problem scenarios and search spaces, thereby more effectively guiding the whale swarm's search process. This dynamic adjustment mechanism enables the algorithm to maintain efficiency and reliability when facing complex and diverse problems, and better cope with changes and challenges in the problem. w gradually decreases with the increase of the number of iterations, and k shows a decreasing trend as t increases from 1 to Tmax, which facilitates better convergence and accuracy in the later stages of the search.

[0024] Step 22: Improve the PID parameter design of the whale algorithm; When using the improved whale algorithm to optimize PID controller parameters, the PID algorithm parameters (Kp, Ki, Kd) are treated as the target variables to be optimized, transforming it into a multivariate, multi-dimensional optimization problem. These three parameters are then fed into the whale algorithm for optimization, iterating to find the optimal solution and obtain the best PID parameter values. This embodiment uses the integral absolute error as the fitness function. The integral of the product of the absolute value of the PID parameter deviation and time is used as the objective function for PID parameter tuning, as shown in the following formula: The formula for calculating the fitness of whales is: .

[0025] Step 2: Improve the whale algorithm and optimize PID. The specific steps are as follows: Step S1: Initialize relevant parameters. Initialize population size (number), current iteration count, maximum iteration count (Tmax), and dimension (dim); Step S2: Calculate the optimal fitness value for an individual whale; Step S3: Position Update: Input the fitness value into the brushless DC motor, tune the values ​​of Ke, Kec, Kp, Ki, and Kd, update the position, and calculate the parameter values; Step S4: Select update mechanism: Compare the P value with Q to select which update mechanism to update the position. If P < Q and A < 1, the whale uses bubble net hunting. If A ≥ 1, it uses random walk to search for prey and update the position. However, if P ≥ Q, it uses encirclement and spiral contraction to update the position. Compare and evaluate the performance indicators of the motor output and return with the whale's performance to determine the optimal position and the historical best position. Step S5: Termination Judgment: Determine if the updated optimal position is better than the best position in the previous iteration, and if the number of iterations has reached the maximum number of iterations, then terminate the algorithm. If the requirements are not met, continue with steps 2-4.

[0026] Step S6: Establish the motor model; Step S7: Assign the optimal fitness value, Ke, Kec, Kp, Ki, and Kd to the individual whale; Step S8: Run the motor model to obtain various performance indicators of the motor under no-load and load conditions.

[0027] Step 3: Design the hardware and software of the brushless DC motor control system; Step 31: Design the hardware for the motor drive control system; The main control chip is an STM32 controller. The STM32 chip has a motor control timer, each with an independent DMA request mechanism. This chip can simultaneously control the output of six PWM waves. In addition, the STM32 is equipped with two 12-bit AD converters for direct voltage signal acquisition and a built-in temperature sensor for direct temperature signal acquisition. The power supply module mainly uses 12V, 5V, and 3.3V voltage regulator circuits. The 12V power supply uses the LM317G-TN3-R DC-DC chip to power the driver chip and various voltage regulator circuits in the driver module. This chip has a maximum input voltage of 40V and a maximum current of 1A, making the driver board compatible with 12V, 24V, and 36V motor drives, greatly increasing its application range. The 5V voltage regulator circuit uses the LM7805 chip to power the Hall sensor, USB-to-serial port, signal detection circuit, etc. The 3.3V voltage regulator circuit uses the AMS1117-3.3 chip, which mainly supplies power to the microcontroller, current sampling circuit, protection circuit, etc.

[0028] The drive circuit for the brushless DC motor uses a three-phase half-bridge drive, selecting IRF540N MOSFETs as power switching devices. These can be surface-mount or through-hole soldered, and heat sinks can be added. The output filter circuit filters out high-frequency signals generated during motor operation, ensuring smooth motor operation. The signal acquisition and feedback circuit mainly includes current and voltage signal detection. Its primary function is to collect the motor's operating current, process it, and use it as a control quantity in the control system. By adjusting the current, corresponding control and protection actions are taken. Furthermore, the nature and magnitude of the motor operating voltage and the control signal voltage collected in this system differ; therefore, the sampling and protection circuits in the current detection circuit also require rectification functions.

[0029] Step 32: Design the motor drive control system software; The main program of the control system is shown in Figure 3. First, the system is initialized, including the description and assignment of variables, the setting of each port, and the initialization of the interrupt system. Initialization ensures that the system runs sequentially according to the predetermined program. The main program determines the rotor position of the motor through the received Hall sensor signal and, based on the working principle and control algorithm of the brushless DC motor, inputs the corresponding on / off conditions to the power transistors through the driver. The motor repeats the algorithm program based on the feedback signal of the rotor position information, adjusting the motor speed to reach the set reference speed and maintaining stable motor operation.

[0030] The startup subroutine design begins with the initialization program. Knowing the initial position of the motor, it energizes the motor rotor winding coils sequentially. It then determines whether the motor has started successfully. If starting successfully, it acquires the position and performs normal commutation. Otherwise, it needs to reposition the motor rotor. This completes the motor startup. To ensure successful commutation of the winding coils in subsequent startups, the rotor position needs to be repositioned again after a successful start to guarantee normal motor operation.

[0031] The communication system software flow design begins with configuring the serial port, including setting the baud rate, data bits, and stop bits. This is followed by serial port initialization, defining the data frame header and trailer, updating the data in the frame, and sending it to the host computer. This establishes successful communication between the microcontroller and the host computer based on the hardware circuitry. Information can then be continuously sent to the host computer via the serial port. Typically, the host computer's communication interface is pre-configured; communication is achieved simply by configuring the serial port and connecting the wires, making it very convenient and quick.

[0032] After the A / D sampling and communication system is debugged, the system will continue to execute the algorithm control program. The acquired phase voltage, phase current, rotor position angle, and other information are transmitted to the STM32 microcontroller. The control chip, based on the algorithm program design, calculates estimated values ​​for the control quantity and speed. Combining the estimated values ​​with the improved whale algorithm-optimized PID control results, the microcontroller issues control commands to turn on and off each power switch via a pulse width modulation generator. This controls the on / off state of each power device, keeping the motor speed near the desired value, achieving the set speed and maintaining a stable state, thus realizing the speed control of the brushless DC motor.

[0033] Step 4: Optimize the parameters of the CNC system for the sewing machine; The CNC system of the sewing machine adopts cascade control, with the position control loop preceding the speed control loop and taking precedence over the current control loop. The advantages of this control method are: 1. The structure of each control loop is transparent. 2. Interference can be compensated by subsequent controllers, effectively reducing the load on the upstream controllers. 3. Each external control loop protects the internal control loop by limiting command variables. 4. Individual debugging of each control loop begins from the innermost loop.

[0034] Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort should fall within the scope of protection of the present invention.

Claims

1. A method for controlling a brushless DC motor in a sewing machine, characterized in that: Includes the following steps: Step 1: Design the structure of the brushless DC motor for the sewing machine; Step 2: Establish a brushless DC motor speed control method based on PID optimization using the whale algorithm; Step 3: Design the hardware and software of the brushless DC motor control system; Step 4: Optimize the parameters of the CNC system of the sewing machine.

2. The brushless DC motor control method for a sewing machine according to claim 1, characterized in that: Step 1 includes: Step 11: Set the outer diameter and effective length of the stator core of the brushless DC motor; Step 12: The brushless DC motor adopts a sloping shoulder round bottom groove structure; Step 13: The brushless DC motor uses neodymium iron boron material.

3. The brushless DC motor control method for a sewing machine according to claim 1, characterized in that: The improved whale algorithm in step 2 specifically includes: Step 21: Improve the local search mechanism of the whale algorithm; Step 22: Improve the PID parameter design of the whale algorithm.

4. The brushless DC motor control method for a sewing machine according to claim 1, characterized in that: The specific steps for improving the whale algorithm and optimizing PID in step 2 are as follows: Step S1: Initialize relevant parameters. Initialize population size (number), current iteration count, maximum iteration count (Tmax), and dimension (dim); Step S2: Calculate the optimal fitness value for an individual whale; Step S3: Position Update: Input the fitness value into the brushless DC motor, tune the values ​​of Ke, Kec, Kp, Ki, and Kd, update the position, and calculate the parameter values; Step S4: Select update mechanism: Compare the P value with Q to select which update mechanism to update the position. If P < Q and A < 1, the whale uses bubble net hunting. If A ≥ 1, it uses random walk to search for prey and update the position. However, if P ≥ Q, it uses encirclement and spiral contraction to update the position. Compare and evaluate the performance indicators of the motor output and return with the whale's performance to determine the optimal position and the historical best position. Step S5: Termination Judgment: Determine if the updated optimal position is better than the best position in the previous iteration, and if the number of iterations has reached the maximum number of iterations, then terminate the algorithm. If the requirements are not met, continue with steps 2-4. Step S6: Establish the motor model; Step S7: Assign the optimal fitness value, Ke, Kec, Kp, Ki, and Kd to the individual whale; Step S8: Run the motor model to obtain various performance indicators of the motor under no-load and load conditions.

5. The brushless DC motor control method for a sewing machine according to claim 1, characterized in that: Step 3 includes: Step 31: Design the hardware for the motor drive control system; Step 32: Design the motor drive control system software.

6. The brushless DC motor control method for a sewing machine according to claim 3, characterized in that: The method for improving the local search mechanism of the whale algorithm in step 21 is as follows: The convergence factor and probability threshold are optimized, and a Gaussian mutation strategy factor and an adaptive factor are added. The adaptive weight strategy factor and the Gaussian mutation factor are introduced into the whale algorithm. The Gaussian mutation strategy factor and the adaptive weight factor are expressed as follows: ; In the formula, Tmax is the maximum number of iterations, r is a random number between [0,1], t is time, k is the variance of Gaussian mutation, and w is the adaptive weight factor. r follows a Gaussian mutation factor with a mean of 0 and a variance of k. The adaptive weight factor enables dynamic analysis and adjustment of the behavior of the whale pod and the characteristics of the problem. By adaptively adjusting the weight factor, the algorithm adapts to different problem scenarios and search spaces. w gradually decreases with the increase of the number of iterations, and k shows a decreasing trend as t increases from 1 to Tmax, which facilitates better convergence and accuracy of the search in the later stages.

7. The brushless DC motor control method for a sewing machine according to claim 3, characterized in that: The method for designing PID parameters for the improved whale algorithm in step 22 is as follows: When using the improved whale algorithm to optimize PID controller parameters, the PID algorithm parameters are treated as the target variables to be optimized, transforming it into a multivariate, multi-dimensional optimization problem. Simultaneously, these three parameters are fed into the whale algorithm for optimization, and the optimal solution is sought through continuous iteration to obtain the best PID parameter values. The integral absolute error is used as the fitness function, and the integral of the product of the absolute value of the PID parameter deviation and time is used as the objective function for PID parameter tuning.

8. The brushless DC motor control method for a sewing machine according to claim 5, characterized in that: Step 31 involves designing the hardware for the motor drive control system. The main control chip is an STM32 controller chip. The STM32 chip has a motor control timer, and each timer has an independent DMA request mechanism. The chip simultaneously controls the output of 6 PWM waves. The STM32 is also equipped with two 12-bit AD converters. The drive circuit of the brushless DC motor adopts a three-phase half-bridge drive. The MOSFET model IRF540N is selected as the power switch. The output filter circuit filters out the high-frequency signals during motor operation. The signal acquisition and feedback circuit includes current signal detection and voltage signal detection. It collects the current during motor operation, processes it, and uses it as the control quantity in the control system. By adjusting the current, corresponding control and protection actions are performed.

9. The brushless DC motor control method for a sewing machine according to claim 5, characterized in that: The method for designing the motor drive control system software in step 32 involves initializing the system, including describing and assigning variables, setting each port, initializing the interrupt system, and the main program determining the rotor position of the motor through the received Hall sensor signal. Based on the working principle and control algorithm of the brushless DC motor, the driver inputs the corresponding on / off conditions to the power transistor. The motor repeats the algorithm program based on the feedback signal of the rotor position information, adjusting the motor speed to reach the set reference speed. The communication system software flow design begins with setting the serial port configuration, including setting the baud rate, data bits, and stop bits. Serial port initialization is then performed, defining the data frame header and trailer, updating the data in the data frame, and sending it to the host computer. This establishes successful communication between the microcontroller and the host computer based on the hardware circuitry. Information is continuously sent to the host computer through the communication serial port. After the A / D sampling and communication system debugging is completed, the system continues to execute the algorithm control program, transmitting the collected phase voltage, phase current, and rotor position angle information to the STM32 microcontroller. The control chip calculates the estimated values ​​of the control quantity and speed based on the algorithm program design. The improved whale algorithm, combining the estimated values ​​with the given values, optimizes the PID control. Based on the control comparison results, the microcontroller issues control commands to turn on and off each power switch transistor through the pulse width modulation generator, controlling the on and off states of each power device to keep the motor speed near the desired value, so that the motor speed reaches the set value and remains stable, thus realizing the speed control of the brushless DC motor.

10. The brushless DC motor control method for a sewing machine according to claim 1, characterized in that: The method for optimizing the parameters of the CNC system of the sewing machine in step 4 is that the control principle of the CNC system of the sewing machine adopts cascade control, with the position control loop preceding the speed control loop and taking precedence over the current control loop.