Steering engine control method and system based on PCA9685 module

Through the coordinated work of the main control module, PCA9685 module and L298N module, a modular and multi-servo synchronization control solution was built, which solved the problems of poor synchronization and slow response of servo control in the existing technology, and achieved high-precision and high-efficiency servo control.

CN119748453AActive Publication Date: 2025-04-04SHANGHAI XINSANMIN SUPPLY CHAIN MANAGEMENT CO LTD
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202510012719.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-06
Publication Date
2025-04-04
Estimated Expiration
2045-01-06

AI Technical Summary

Technical Problem

In the prior art, the servo control has problems such as poor synchronization, large signal interference and high control complexity. The traditional PWM signal generation method has a slow response speed, so it is impossible to flexibly adjust the duty cycle and angle of each servo.

Method used

Through the collaboration between the main control module, the PCA9685 module and the L298N module, the multi-device cascade capability of the I2C bus and the high-resolution PWM signal generation capability of the PCA9685 module are used to build a modular and multi-servo synchronization control solution. Optimize harmonic switching angle and duty cycle adjustment to achieve accurate control of multiple servo machines.

Benefits of technology

It significantly improves control accuracy and efficiency, solves the problems of poor synchronization and slow response of multiple servo machines, and meets the needs of collaborative control of multiple servo machines in complex scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119748453A_ABST
    Figure CN119748453A_ABST
Patent Text Reader

Abstract

The invention discloses a steering engine control method and system based on PCA9685 modules, and the method comprises the steps: carrying out the cascade connection of a main control module and a plurality of PCA9685 modules through an I2C interface, and constructing a unified control frame for a plurality of steering engines. Based on the rotation angle of the target steering engine, the PWM signal duty ratio for controlling the steering engine is calculated, and a binary PWM signal calculation model for modulating the ith steering engine by the nth L298N module connected with each PCA9865 module is constructed; and positive and negative rotation and high and low level output of each steering engine are controlled by optimizing the switching angle of the L298N module, so that accurate control on turning on, turning off and angle adjustment of the steering engines is realized. The invention provides a multi-steering-engine control scheme with synchronous control, efficient duty ratio adjustment and modular expansion capabilities, the accuracy, synchronism and energy efficiency of steering engine movement are remarkably improved, and the multi-steering-engine control method is suitable for multi-field scenes such as complex industrial automation and robots.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of using a digital processing device with a program control system to perform program control on robot joints, and in particular relates to a steering gear control method and system based on a PCA9685 module. Background Art

[0002] In industrial automation and robotics, servos are a commonly used actuator and are widely used in the fields of robotic arms, automated transportation, logistics sorting, etc. In the prior art, such as the servo control methods or systems disclosed in publication numbers CN111376245A and CN109696910A, the servo control usually uses the GPIO pin of a single-chip microcomputer or an independent PWM generator to generate signals. This method faces the problems of poor synchronization, large signal interference, and high control complexity when multiple servos work together. In addition, the traditional PWM signal generation method relies on hardware circuits or software simulation, has a slow response speed, and cannot flexibly adjust the duty cycle and angle of each servo.

[0003] At the same time, the forward and reverse control of the servo usually requires additional hardware support, making it difficult to achieve efficient direction switching and dynamic adjustment. Expanding the control requirements for more servos will further increase hardware costs and design difficulty. Summary of the invention

[0004] The present invention aims at the above-mentioned defects and provides a steering gear control method and system based on PCA9685 module. The present invention uses I 2 The multi-device cascading capability of the C bus and the high-resolution PWM signal generation capability of the PCA9685 module have built a modular, multi-servo synchronous control solution. By optimizing the harmonic switching angle and duty cycle adjustment, the present invention overcomes the problems of poor synchronization, slow response and limited scalability of multiple servos in the prior art, significantly improves the control accuracy and efficiency, and meets the needs of multi-servo collaborative control in complex scenarios.

[0005] The present invention provides the following technical solution: a steering gear control method based on a PCA9685 module, wherein the method uniformly controls multiple steering gears through the PCA9685 module, and controls the switching time and duty cycle of each steering gear based on a program written into the register of the PCA9685 module by a main control module, thereby achieving the effect of regulating different steering gears to start movement or shut down and stop movement when needed, comprising the following steps:

[0006] S1: I of the main control module 2 C pin with multiple PCA9685 modules 2The C interface performs serial address configuration to realize cascade connection, receive control instructions or upload real-time monitoring data;

[0007] S2: Calculate the duty cycle of the PWM signal for controlling each servo according to the target rotation angle of each servo, construct a binary PWM signal calculation model for the nth L298N module connected to each PCA9865 module to modulate the i-th servo, write it into the register of the PCA9685 module, and adjust the program to update the binary PWM signal;

[0008] S3: Further calculate the duty cycle D of each servo according to step S2 ni Calculate the high level voltage V of the nth L298N module connected to each PCA9865 module to the i-th servo ni (t), optimize the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo

[0009] S4: Compare the voltage u of the reference signal r(t) for controlling the nth L298N module written by the main control module into the PCA9685 module register r,n And the internal carrier signal c(t) voltage u set in the PCA9685 module to control the nth L298N module c,n , by comparing the voltage u of the reference signal r(t) r,n and the voltage u of the internal carrier signal c(t) c,n , and then control whether the i-th servo connected to the n-th L298N module is turned on or off, and rotates forward or reverse to the desired angle γ after it is turned on ni , and when it is turned on, the output has the kth order optimal harmonic switching angle The optimal positive and negative high-level voltage ±V ni,best (t), and the output voltage value is 0 at the turn-off time.

[0010] Furthermore, in the step S1, multiple PCA9685 modules are connected via I 2 C interface and the main control module's I 2 C pin cascade connection, including:

[0011] S11: Obtain the I of the A0-A5 pins of the nth PCA9685 module by identifying the A0-A5 pin jumper configuration status of each PCA9685 module 2 C binary address set A n ={add A0,n ,add A1,n ,add A2,n ,add A3,n ,add A4,n,add A5,n}; among them, add A1,n 、add A2,,n 、add A3,n 、add A4,n and add A5,n The I pins of A0, A1, A2, A3, A4 and A5 of the nth PCA9685 module are 2 C binary value; add A1,n 、add A2,n 、add A3,n 、add A4,n and add A5,n The values ​​of are all 0 or 1;

[0012] S12: According to the obtained A0-A5 pin I of the nth PCA9685 module 2 C binary value, the main control module calculates the I configured to the nth PCA9685 module 2 C hexadecimal address ADD n =0x40+(add A5,n ×2 5 )+(add A4,n ×2 4 )+(add A3,n ×2 3 )+(add A2,n ×2 2 )=(add A1,n ×2 1 )+(add A0,n ×2 0 ); where 0x40 represents the hexadecimal number 40;

[0013] S13: The main control module calculates the I 2 C hexadecimal address to transmit the corresponding control instructions to each PCA9685 module.

[0014] Furthermore, the step S2 includes the following steps:

[0015] S21: Determine the rotation angle γ that each servo needs to reach ni , according to which the high-level pulse width T in the PWM control cycle is calculated on,ni ; γ ni The target rotation angle of the ith servo controlled by the nth L298N module connected to each PCA9865 module;

[0016] S22: Further calculation of the rotation angle to be achieved is γ ni The duty cycle of the PWM control cycle is D ni :

[0017] Among them, T on,ni , T off,ni are respectively the high level pulse width and low level pulse width in a switching cycle, T on,ni +T off,ni =T ni , T ni The switching pulse width of a switch of the i-th servo controlled by the n-th L298N module; where i = 1 or 2, n = 1, 2, ... N; N is the total number of L298N modules connected to each PCA9685 module;

[0018] S23: Duty cycle D obtained according to step S22 ni , construct the binary PWM signal calculation model for each PCA9865 module connected to the nth L298N module to modulate the i-th servo:

[0019]

[0020] Where a is the ath switching cycle, a=1,2,…; θ c,ni is the initial phase angle of the ith servo controlled by the nth L298N module, θ c,n1 =0,θ c,n2 = -π; f m is the control frequency of the PWM signal, f m =50Hz; the total pulse width T of a PWM signal control cycle is 20ms; let D n1 =D n , then D n2 =1-D n , D n The duty cycle of the first servo controlled by the nth L298N module in a switching cycle.

[0021] Furthermore, the step S21 includes:

[0022] S211: Setting T ni =2ms, calculate the PWM count value Count of a switching cycle:

[0023] Count = T ni / T×4096=410;

[0024] S212: Calculate the number of PWM counts required for each rotation of 1 degree according to different servo types E = Count / γ max ; Among them, γ max The maximum angle that different servo types can rotate to; servo types include γ max =90°,γ max=180°,γ max =270° or γ max =Any one or more of 360°;

[0025] S213: Rotate according to target angle γ ni , calculate the total PWM count value required to achieve it, which is the end time t of the high-level pulse width in a switching cycle off,ni :t off,ni =γ ni ×E+t on,ni ; T off,ni =(4096-T on,ni )×20; when the rotation angle corresponding to the initial on value is 0 degrees, t on,ni =102.4; T on,ni =[(γ ni ×E) / 4096]×20;

[0026] S214: Then obtain the corresponding target angle γ within a switching cycle ni The off value t off,ni , t off,ni =T on,ni +t on,ni ;t on,ni is the target angle γ corresponding to one switching cycle ni The on value is the moment when the binary PWM signal controls the start of the i-th servo; the off value is t off,ni The binary PWM signal controls the moment when the i-th servo is turned off.

[0027] Furthermore, the S3 step includes:

[0028] S31: Calculate the high level voltage V output by the nth L298N module to control the first servo n1 (t), the nth L298N module controls the high level voltage V output by the second servo n2 (t):

[0029]

[0030]

[0031] in, is the kth harmonic switching angle of the ith servo controlled by the nth L298N module; b is the total number of high-level voltage outputs in one switching cycle; V d Provide power supply voltage for the nth L298N module with external power supply; is the a-order Bessel coefficient for adjusting the amplitude of the high-level voltage output by the i-th servo. When a=0, is the 0th-order Bessel coefficient;

[0032]

[0033] S32: Construct the first nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components:

[0034]

[0035] in, A nonlinear equation to make the amplitude of the odd harmonic components of the kth harmonic switching angle of the first servo controlled by the nth L298N module zero;

[0036] Where, q=3,5,7,…2k+1; V q for Abbreviation of is the voltage amplitude of the qth-order odd harmonic component generated by the qth-order harmonic switching angle; is the hth harmonic switching angle of the i-th servo controlled by the n-th L298N module; h=1,2,…,k;

[0037] Construct the second nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components:

[0038]

[0039] in, A nonlinear equation to make the amplitude of the odd harmonic components of the kth harmonic switching angle of the second servo controlled by the nth L298N module zero;

[0040] Where p = 3, 5, 7, ... 2k + 1; v p for Abbreviation of is the voltage amplitude of the p-th order odd harmonic component generated by the p-th order harmonic switching angle;

[0041] S33: Through Taylor expansion, the nonlinear equations in the first nonlinear equation group are The nonlinear equation in the second nonlinear system In the corresponding current d-generation solution Expand at:

[0042]

[0043] Among them, g∈{1,2,…,k}, They are the g-th harmonic switching angle of the first servo controlled by the n-th L298N module and the g-th harmonic switching angle of the second servo controlled by the n-th L298N module; They are the d-th generation solutions of the g-th order harmonic switching angle of the ith servo controlled by the n-th L298N module;

[0044] S34: Simplified into matrix form:

[0045] is the k×k element Jacobian matrix of the first nonlinear system of equations; is the nonlinear equation in the first nonlinear equation system The d-th generation solution and its d-1-th generation solution The difference between is the d-th generation solution vector matrix of the first nonlinear equation system,

[0046] is the k×k element Jacobian matrix of the second nonlinear system of equations; is the nonlinear equation in the second nonlinear equation system The d-th generation solution and its d-1-th generation solution The difference between is the d-th generation solution vector matrix of the second nonlinear equation system,

[0047] S35: According to the matrix form obtained in step S34, further iteratively solve the d+1th generation solution of the first nonlinear equation group and the second nonlinear equation group:

[0048]

[0049] S36: Calculate the total harmonic distortion THD of the first servo controlled by the nth L298N module n1 Total harmonic distortion THD of the second servo n2 :

[0050]

[0051]

[0052] Determine the total harmonic distortion THD of the first servo n1 Total harmonic distortion THD of the second servo n2 Are they all less than 0.35? If so, stop the iteration and output the optimal k-th harmonic switching angle of the ith servo controlled by the nth L298N module i=1,2; otherwise, repeat the steps S31-S35 until the total harmonic distortion THD of the first servo is n1 Total harmonic distortion THD of the second servo n2 When all are less than 0.35, the kth optimal harmonic switching angle of the ith servo controlled by the nth L298N module is output.

[0053] Furthermore, in step S4, by comparing the reference signal voltage u r,n and the internal triangular carrier signal voltage u c,n , and then control the output voltage of the nth L298N module, whether the i-th servo is turned on or off, and whether it rotates forward or reverse to the desired angle γ after being turned on ni The rule is: when |u r,n |>|u c,n |, the first IGBT switch and the third IGBT switch of the i-th servo are turned on. r,n In the positive half cycle, the optimal positive high level voltage +V is output ni,best (t), make the i-th servo rotate forward to the desired angle γ ni ; in u r,n In the negative half cycle, the output voltage is low level 0;

[0054] When|u r,n |<|u c,n |, the second IGBT switch and the fourth IGBT of the i-th servo are controlled to turn on. r,n In the positive half cycle, the output voltage is low level 0; r,n In the negative half cycle, the optimal negative high level voltage -V is output ni,best (t), the i-th servo is reversed to the desired angle γ ni .

[0055] The present invention also provides a steering gear control system based on a PCA9685 module for executing the above method, the system comprising a main control module, a plurality of PCA9685 modules and a plurality of L298N modules; the plurality of PCA9685 modules are cascaded with the main control module, and each PCA9685 module is connected to four L298N modules; the main control module is an Arduino Uno module;

[0056] The main control module also includes a duty cycle calculation module corresponding to the desired angle of the steering gear, a binary PWM signal calculation module, a sinusoidal reference wave signal r(t) generation module, and a harmonic suppression module;

[0057] The main control module is used to 2 C pin with multiple PCA9685 modules 2The C interface performs serial address configuration to realize cascade connection, receive control instructions or upload real-time monitoring data;

[0058] The duty cycle calculation module corresponding to the desired steering gear angle is used to calculate the duty cycle of the PWM signal for controlling the steering gear according to the target rotation angle of each steering gear;

[0059] The binary PWM signal calculation module is used to construct a binary PWM signal calculation model for modulating the i-th servo by the n-th L298N module connected to each PCA9865 module, and write it into the register of the PCA9685 module to adjust the program to update the binary PWM signal;

[0060] The sinusoidal reference wave signal r(t) generating module is used to generate a sinusoidal reference signal r(t) and write it into the PCA9685 module register;

[0061] The harmonic suppression module is used to calculate the duty cycle D of each servo according to the duty cycle calculation module corresponding to the desired angle of the servo. ni Calculate the high level voltage V of the nth L298N module connected to each PCA9865 module to the i-th servo ni (t), optimize the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo

[0062] The PCA9685 module includes an internal triangular carrier signal c(t) generation module, a comparator module, and a PWM modulation signal output module; the internal triangular carrier signal c(t) generation module is used to generate a triangular carrier signal c(t);

[0063] The PWM modulation signal output module is used to compare the voltage u of the sine wave reference signal r(t) generated by the sine wave reference signal r(t) generation module according to the comparator module. r,n The voltage u of the triangular carrier signal c(t) generated by the triangular carrier signal c(t) generating module c,n The size of the harmonic suppression module is optimized to control the output of the nth L298N module to have the kth optimal harmonic switching angle The optimal positive and negative high-level voltage ±V ni,best (t), whether the i-th servo is turned on or not, and after it is turned on, the duty cycle D of the i-th servo calculated by the duty cycle calculation module corresponding to the desired angle of the servo ni The nth L298N module modulates the i-th servo with a binary PWM signal b PWM,ni (t), forward or reverse to the desired angle γ ni .

[0064] Furthermore, the left SDA pin and SCL pin of the first PCA9685M module among the multiple PCA9685 modules connected to the Arduino Uno module are connected to the A4 pin and A5 pin of the Arduino Uno module, the 5V pin of the Arduino Uno module and the left VCC pin of the first PCA9685 module among the multiple PCA9685 modules cascaded with it output the +5V voltage power supply required for the internal logic operation of the multiple PCA9685 modules, and the GND pin of the Arduino Uno module and the left GND pins of the multiple PCA9685 modules and the negative electrode of the external power supply are grounded together; the right GND pin, right OE pin, right SCL pin, right SDA pin, right VCC pin and right V+ pin of the first PCA9685 module are respectively connected to the Arduino Uno module and the left VCC pin of the first PCA9685M module and the negative electrode of the external power supply are grounded together. The left GND pin, left OE pin, left SCL pin, left SDA pin, left VCC pin and left V+ pin of the second PCA9685 module in the Uno module cascade are connected through different leads respectively, and then the cascade of the second PCA9685 module to the last PCA9685 module and the Arduino Uno module is completed according to this pin connection rule.

[0065] Further, channels 0-15 of each PCA9685 module are connected to four L298N modules; wherein, channels 0-3 of each PCA9685 module are connected to the first L298N module, channels 4-7 are connected to the second L298N module, channels 8-11 are connected to the third L298N module, and channels 12-16 are connected to the fourth L298N module;

[0066] The +5V pin of each L298N is connected to the red VCC pins of the four corresponding channels of the PCA9685 connected to it, so as to receive the +5V voltage power supply required for its internal logic operation; the GND pin of each L298N module is connected to the negative pole of the external power supply, and the +12V pin is connected to the positive pole of the external power supply, and the IN1 pin, IN2 pin, IN3 pin and IN4 pin of each L298N module are respectively connected to the corresponding four channels, so as to receive the calculated k-th optimal harmonic switching angle of the n-th L298N module connected to each PCA9685 module after optimization and written into the register of the PCA9685 module by the Arduino Uno module. The corresponding high level voltage V for the i-th servo ni,best(t); The ENA enable pin and the ENB enable pin of each L298N module are respectively connected to the digital pin 11 and the digital pin 3 of the Arduino Uno module, so as to receive the intermittent start control instruction of the i-th servo related to the binary PWM signal written into the corresponding PCA9865 module and the voltage comparison result of the reference signal r(t) output by the PWM modulation signal output module in the PCA9685 module and the carrier signal c(t);

[0067] Each L298N module is connected to two servos: the first servo and the second servo; the OUT1 pin and OUT2 pin of each L298N module are respectively connected to the two ends of the first coil and the two ends of the second coil of the first servo, and the OUT3 pin and OUT4 pin of each L298N module are respectively connected to the two ends of the first coil and the two ends of the second coil of the second servo.

[0068] The beneficial effects of the present invention are:

[0069] 1. The present invention can realize the centralized control of multiple steering gears (each PCA9685 module can control 16 steering gears) by cascading the main control module with multiple PCA9685 modules. 2 C communication protocol and jumper cap welding address configuration design, convenient for hardware upgrade and maintenance, integrated I 2 C protocol and modular hardware design reduce development time and maintenance complexity.

[0070] 2. The method of the present invention comprises steps S31-S36, firstly constructing a Bessel coefficient in step S31 The voltage calculation formula output to the i-th servo is used to dynamically adjust the output voltage amplitude according to the number of switching cycles and the amplitude and accuracy of the output voltage, providing multi-dimensional freedom for signal generation and adjustment. When the load of the i-th servo changes, the Bessel coefficient can be adjusted dynamically in real time to maintain the stability of the output signal and output voltage. Then, through the S32-S36 steps, the harmonic switching angle of the overmodulated signal is used to selectively eliminate specific harmonic components (3rd, 5th, 7th, 9th and other high-order harmonics), significantly reducing the amplitude of low-order harmonics, reducing the transmission of useless harmonic energy, and concentrating more energy on the fundamental frequency, thereby improving the harmonic distortion rate (THD) of the output signal, and finally achieving the precise elimination of specific-order harmonics, improving the quality of the output waveform, and making the signal closer to the ideal sine wave.

[0071] 3. This technology achieves high-precision control of the start and stop and forward and reverse rotation of the servo by comparing the reference signal and the carrier signal and adjusting the optimal positive and negative voltages, significantly improving the efficiency, stability and flexibility of the servo system. It also has the characteristics of low energy consumption, low interference and high robustness, and is suitable for a variety of high-precision, multi-task control scenarios. At the same time, the servo can be controlled to output a low-level voltage of 0 in the stopped state, effectively reducing the energy consumption in standby mode. By adjusting the voltage u of the reference signal r(t) r,n The absolute value of the carrier signal c(t) and the voltage u c,n The absolute value of u r,n By comparing the positive half-cycle of the L298N module, the intermittent connection of OUT1-OUT4 of the L298N module is controlled, which realizes smooth voltage output and switching, reduces the loss of the first IGBT switch to the fourth IGBT switch, prolongs the service life of the drive module, and reduces maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0072] The present invention will be described in more detail below based on embodiments and with reference to the accompanying drawings, wherein:

[0073] Figure 1 A schematic flow chart of a steering gear control method based on a PCA9685 module provided by the present invention;

[0074] Figure 2 A schematic diagram of the welding operation of the A0 pin of the PCA9685 module in the A0-A5 pin jumper configuration state according to an embodiment of the present invention;

[0075] Figure 3 is the voltage u of the reference signal r(t) r,n The determination of the on value and off value of the duty cycle of the output voltage generated by comparing its absolute value with the absolute value of the voltage of the carrier signal c(t) in the positive and negative cycles, and T on,ni and T off,ni Schematic diagram of the determination rules;

[0076] Figure 4 Schematic diagram of the change of Bessel coefficient over time for the first servo in the switching cycle of a=0-10 in an embodiment of the present invention;

[0077] Figure 5 It is a schematic diagram of the influence of the odd harmonics within the 9th order harmonics and the switching angle on the rectangular fundamental wave waveform diagram by the method of the present invention;

[0078] Figure 6 It is a schematic diagram of the change of the optimal switching angle of harmonics with the output voltage after being optimized by the method of the present invention and the traditional CNN method;

[0079] Figure 7It is a schematic diagram of the change of output voltage over time after optimization using the method of the present invention and the traditional CNN method and the Fourier analysis result;

[0080] Figure 8 The THD of the output voltage V when the output voltage changes after the optimization of the method of the present invention and the traditional CNN method in the embodiment of the present invention. out Schematic diagram of the changes;

[0081] Fig. 9 A schematic diagram of the structure of a steering gear control system based on the PCA9685 module provided by the present invention;

[0082] Fig.10 This is a schematic diagram of the structure of an Arduino Uno module in an embodiment of the present invention;

[0083] Fig.11 Schematic diagram of the PCA9685 module structure in an embodiment of the present invention;

[0084] Fig.12 Schematic diagram of the PCA9685 module circuit in an embodiment of the present invention;

[0085] Fig.13 Schematic diagram of the structure of the L298N module in an embodiment of the present invention;

[0086] Fig.14 Schematic diagram of the L298N module circuit in an embodiment of the present invention;

[0087] Fig.15 Schematic diagram of a dual H-bridge circuit including eight IGBT switches in an L298N module in an embodiment of the present invention;

[0088] Fig.16 is the voltage u of the reference signal in the embodiment of the present invention r,n The L298N module receives the start / stop status of the first and second servos connected to it and the forward / reverse output high-level voltage during the positive and negative half-cycles;

[0089] Fig.17 A pin connection diagram of an Arduino Uno module and a plurality of PCA9685 modules cascaded in an embodiment of the present invention;

[0090] Fig.18 This is a pin connection diagram of using an Arduino Uno master PCA9685 module to connect an L298N module to control the motion of two servos in the first power supply mode in an embodiment of the present invention;

[0091] Fig.19This is a pin connection diagram of using an Arduino Uno master control PCA9685 module to connect an L298N module to control the motion of two servos under the second power supply mode in an embodiment of the present invention. DETAILED DESCRIPTION

[0092] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0093] like Figure 1 FIG. 1 is a flow chart of a steering gear control method based on a PCA9685 module provided by the present invention. The method of the present invention controls multiple steering gears in a unified manner through a PCA9685 module, and controls the switching time and duty cycle of each steering gear based on a program written into a register of the PCA9685 module by a main control module, thereby achieving the effect of regulating different steering gears to start or stop moving when needed, and includes the following steps:

[0094] S1: I of the main control module 2 C pin with multiple PCA9685 modules 2 The C interface performs serial address configuration to realize cascade connection, receive control instructions or upload real-time monitoring data;

[0095] S2: Calculate the duty cycle of the PWM signal for controlling each servo according to the target rotation angle of each servo, construct a binary PWM signal calculation model for the nth L298N module connected to each PCA9865 module to modulate the i-th servo, write it into the register of the PCA9685 module, and adjust the program to update the binary PWM signal;

[0096] S3: Further calculate the duty cycle D of each servo according to step S2 ni Calculate the high level voltage V of the nth L298N module connected to each PCA9865 module to the i-th servo ni (t), optimize the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo

[0097] S4: Compare the voltage u of the reference signal r(t) for controlling the nth L298N module written by the main control module into the PCA9685 module register r,n And the internal carrier signal c(t) voltage u set in the PCA9685 module to control the nth L298N modulec,n , by comparing the voltage u of the reference signal r(t) r,n and the voltage u of the internal carrier signal c(t) c,n , and then control whether the i-th servo connected to the n-th L298N module is turned on or off, and rotates forward or reverse to the desired angle γ after it is turned on ni , and when it is turned on, the output has the kth order optimal harmonic switching angle The optimal positive and negative high-level voltage ±V ni,best (t), and the output voltage value is 0 at the turn-off time.

[0098] The present invention uses the I of the main control module and the PCA9685 module 2 C interface for cascade connection, unified generation of PWM signals, ensuring synchronous control of multiple servos, reducing delays and errors in signal transmission, and being able to accurately and synchronously control the movement of multiple servos, thereby overcoming the problems that the control of multiple servos in the prior art usually relies on independent signal generators or GPIO pins of single-chip microcomputers, which have problems such as poor synchronization and large signal interference. In addition, the present invention utilizes the duty cycle calculation model of the built-in register of the PCA9685 module to quickly generate accurate PWM signals, avoiding the problem that the duty cycle adjustment of the PWM signal relies on independent hardware circuits or software simulations, which has the problems of slow response speed and high calculation complexity, and greatly improves the accuracy and response speed of servo control.

[0099] The present invention connects a main control module with multiple PCA9685 modules, and each PCA9685 module is connected to an L298N module for every four channels. Thus, one PCA9685 module can be connected to four L298N modules, and each L298N module can perform signal control on two servos, allowing for flexible expansion of the number of servos to meet the needs of different scenarios, thereby solving the problem of insufficient flexibility in traditional control schemes due to limited expansion. By implementing a strategy of combining positive and negative high-level outputs with an optimal harmonic switching angle through each L298N module, the present invention significantly optimizes the control effect of the forward and reverse rotation of the servo, thereby ensuring the reliability and stability of the control.

[0100] In order to realize the control instructions and PWM signal transmission of the main control module and multiple PCA9685 modules cascaded with it, and then control the opening and closing and forward and reverse rotation of the L298N module and multiple servos, it is necessary to use I 2 C protocol realizes the address configuration of multiple PCA9685 modules as slave devices and the main control module. Therefore, as another preferred embodiment of the present invention, in step S1, multiple PCA9685 modules are connected to the main control module through I 2 C interface and the main control module's I 2 C pin cascade connection, including:

[0101] S11: Obtain the I of the A0-A5 pins of the nth PCA9685 module by identifying the A0-A5 pin jumper configuration status of each PCA9685 module 2 C binary address set A n ={add A0,n ,add A1,n ,add A2,n ,add A3,n ,add A4,n ,add A5,n}; among them, add A1,n 、add A2,,n 、add A3,n 、add A4,n and add A5,n The I pins of A0, A1, A2, A3, A4 and A5 of the nth PCA9685 module are 2 C binary value; add A1,n 、add A2,n 、add A3,n 、add A4,n and add A5,n The value of is 0 or 1; that is, add A0,n =0 or 1, add A1,n =0 or 1, add A2,n =0 or 1, add A3,n =0 or 1, add A4,n =0 or 1, add A5,n =0 or 1;

[0102] S12: According to the obtained A0-A5 pin I of the nth PCA9685 module 2 C binary value, the main control module calculates the I configured to the nth PCA9685 module 2 C hexadecimal address ADD n =0x40+(add A5,n ×2 5 )+(add A4,n ×2 4 )+(add A3,n ×2 3 )+(add A2,n ×2 2 )=(add A1,n ×2 1 )+(add A0,n ×2 0 );

[0103] ; Among them, 0x40 represents the hexadecimal number 40, and its corresponding binary number is 00000, and 00000 represents the initial default state of the A0-A5 pin jumpers of the PCA9685 module without solder connection;

[0104] S13: The main control module calculates the I 2 C hexadecimal address to transmit the corresponding control instructions to each PCA9685 module.

[0105] Defaults to the PCA9685 default I 2 The address configuration mode of C address is 0x40 (hexadecimal). The available address range is 0x40. The address configuration of the serially connected PCA9685 modules is set at the hardware module level by connecting jumper solder. Figure 2 As shown, for each Fig.11 The initial addresses of the six pins A0-A5 in the upper right corner of the PCA9685 module shown are all 0x40. If the jumper of any of the six pins A0-A5 is physically connected by soldering, the pin is represented by the binary number "1" in the series address configuration calculation formula. Initially, the six pins A0-A5 are physically disconnected and the jumper is not connected, so they are all represented by the binary number "0".

[0106] The main control module recognizes the A0-A5 pin jumper configuration status of each PCA9685 module and can connect and transmit independent PWM signals to multiple PCA9685 modules. 2 The jumper configuration of the C address ensures the independence and compatibility between modules. The jumper welding address configuration design simplifies the hardware configuration process, improves production and development efficiency, and also supports the scalability and flexibility of the system.

[0107] As another preferred embodiment of the present invention, step S2 includes the following steps:

[0108] S21: Determine the rotation angle γ that each servo needs to reach ni , according to which the high-level pulse width T in the PWM control cycle is calculated on,ni ; γ ni The target rotation angle of the ith servo controlled by the nth L298N module connected to each PCA9865 module;

[0109] S22: Further calculation of the rotation angle to be achieved is γ ni The duty cycle of the PWM control cycle is D ni :

[0110]

[0111] Among them, Figure 3 As shown, T on,ni 、T off,ni are respectively the high level pulse width and low level pulse width in a switching cycle, T on,ni +T off,ni =T ni , T ni is the switching pulse width of a switch of the i-th servo controlled by the n-th L298N module; where i=1 or 2, n=1,2,…N; N is the total number of L298N modules connected to each PCA9685 module; therefore, N=4 (because the PCA9685 module has 16 channels, and every four channels are connected to an L298N module to control two servos); the total number of PCA9685 modules is set to M, that is, one Arduino Uno main control module is connected to M PCA9685 modules; the duty cycle of the MOS tube path controlling each servo is complementary, that is, the duty cycle of the 1st and 4th transistor paths is D n1 and the duty cycle D of transistors 2 and 3 n2 The sum is 1.

[0112] S23: Duty cycle D obtained according to step S22 ni , construct the binary PWM signal calculation model for each PCA9865 module connected to the nth L298N module to modulate the i-th servo:

[0113]

[0114] Where a is the ath switching cycle, a=1,2,…; θ c,ni is the initial phase angle of the ith servo controlled by the nth L298N module, θ c,n1 =0,θ c,n2 = -π; f m is the control frequency of the PWM signal, f m =50Hz; the total pulse width T of a PWM signal control cycle is 20ms. There will be a switching cycle in the total pulse width of a PWM signal control cycle, that is, a switching pulse width T is included in a PWM signal control cycle T (20ms). ni . D ni is the duty cycle of the PWM signal of the i-th servo controlled by the n-th L298N module, let D n1 =D n Since the L298N module controls the first and third IGBT switches to turn on the conduction path (to turn on the first servo) and the second and fourth IGBT switches to turn on the conduction path (to turn on the second servo) are complementary in one switching cycle, then in D n1 =Dn Under the condition of, the duty cycle of the PWM signal of the second servo controlled by the nth L298N module, D n2 =1-D n . D n The duty cycle of the first servo controlled by the nth L298N module in a switching cycle.

[0115] The pins on the PCA9685 module that control the rotation angle of the servo and thus adjust the duty cycle are PWM output pins 0 to 15. The method for the PCA9685 module to modify the angle in each switching cycle is to set a switching cycle to 4096 parts, the on value is the PWM rising count value, and its range is 0 to 4096, and the off value is the PWM falling count value, and its range is also 0 to 4096. It starts from 0 + 1 and jumps to a high level when the on value is counted, and jumps to a low level when the off value is counted, until the next switching cycle is restarted after 4096 is counted. Therefore, when on is not equal to 0, it can be delayed. When on is equal to 0, the value of off value / 4096 is the duty cycle of PWM.

[0116] Therefore, step S21 includes:

[0117] S211: Setting T ni =2ms, calculate the PWM count value Count of a switching cycle:

[0118] Count = T ni / T×4096=410;

[0119] S212: Calculate the number of PWM counts required for each rotation of 1 degree according to different servo types E = Count / γ max ; Among them, γ max The maximum angle that different servo types can rotate to; servo types include γ max =90°,γ max =180°,γ max =270° or γ max =Any one or more of 360°;

[0120] S213: Rotate according to target angle γ ni , calculate the total PWM count value required to achieve it, which is the end time t of the high-level pulse width in a switching cycle off,ni :t off,ni =γ ni ×E+t on,ni ; T off,ni =(4096-T on,ni )×20; when the rotation angle corresponding to the initial on value is 0 degrees, t on,ni=102.4; T on,ni =[(γ ni ×E) / 4096]×20;

[0121] S214: Then obtain the corresponding target angle γ within a switching cycle ni The off value t off,ni =T on,ni +t on,ni ;t on,ni is the target angle γ corresponding to one switching cycle ni The on value is the moment when the binary PWM signal controls the start of the i-th servo; the off value is t off,ni The binary PWM signal controls the moment when the i-th servo is turned off, that is, the off value t off,ni That is, the time t when the PWM signal controls the i-th servo to start (the corresponding transistor path of the corresponding L198N module is turned on) on,ni Start and continue T on,ni After a certain time, at the off value t off,ni At time t, the binary PWM signal controls the i-th servo to turn off; off,ni At the moment, the transistor path of the L198N module corresponding to the servo is closed, and the output is low level until the next time the transistor path of the L298N module corresponding to the servo is turned on; at T on,ni During the time period, the binary PWM signal controls the L298N module to always output a high level; t on,ni is the target angle γ corresponding to one switching cycle ni The on value of .

[0122] When the servo type is γ max =90°, E=410 / 90=4.56; when the servo type is γ max =180°, E=410 / 180=2.28; the servo type is γ max =270°, E=410 / 270=1.52; the servo type is γ max =360°, E=410 / 90=1.14. Based on the binary PWM signal model and duty cycle calculation formula within the control cycle, the servo can accurately reach the target rotation angle, and the control error is significantly reduced.

[0123] As another preferred embodiment of the present invention, step S3 includes:

[0124] S31: Calculate the high level voltage V output by the nth L298N module to control the first servo n1 (t), the nth L298N module controls the high level voltage V output by the second servo n2 (t):

[0125]

[0126]

[0127] in, is the kth harmonic switching angle of the ith servo controlled by the nth L298N module; V d Provide power supply voltage for the nth L298N module with external power supply; is the a-order Bessel coefficient for adjusting the amplitude of the high-level voltage output by the i-th servo. When a=0, is the 0th-order Bessel coefficient;

[0128]

[0129] In the above constructed V n1 (t) and V n2 In the calculation formula of (t), the switching angle of the k-th order harmonic is fully considered. And the influence of a switching cycle in a PWM signal regulation cycle and b positive and negative high-level voltages in a switching cycle on the overall output cycle of the voltage Vd applied to both ends of the nth L298N module. In addition, the Bessel coefficient is used for a switching cycle and By adjusting the amplitude distribution of sine and cosine signals, the harmonic components in the modulated signal can be accurately described. Figure 4 As shown in the figure, when i=1, the Bessel coefficients of the first servo in the switching cycle of a=0~10 are shown. It can be seen that the amplitudes of the frequency components adjusted by the Bessel coefficients in different switching cycles are different. By accurately calculating the Bessel coefficients, the amplitude and phase distribution of each frequency component are ensured to be consistent with expectations, so that the output high-level voltage V ni (t) is more accurate. Dynamic changes in Bessel coefficients can adjust the phase of harmonic components The Bessel coefficients and amplitudes provide multi-dimensional freedom for signal generation and adjustment. When the load changes, the Bessel coefficients can be adjusted in real time to adjust the harmonic amplitude and maintain signal stability.

[0130] The fundamental frequency of the PWM signal determines the fundamental frequency of the harmonics. For each of the eight servos controlled by the PCA9685 module, the harmonic frequency is an integer multiple of the fundamental frequency of the PWM control signal output by the PCA9685 module. Although the inductance, resistance, and different target rotation angles (different duty cycles) of the servos will affect the amplitude characteristics of the harmonics, they will not change the harmonic frequency. In the PWM control signal output by the PCA9685 module, because the even harmonics are in the bipolar conduction control of the dual H-bridge of the same L298N module, the symmetrical bipolar PWM waveform generated during the control of the servo by an H-bridge will be suppressed and offset by itself, so there is no need for external control to eliminate them. Therefore, what needs to be eliminated are the odd harmonics (3, 5, 7, ... 2k+1).

[0131] By adjusting the PWM switching angle at the corresponding odd time nodes, the amplitude of the odd harmonic component can be made zero.

[0132] like Figure 5 As shown in the figure, the black rectangular step line diagram is the total harmonics formed by the 3rd, 5th, 7th and 9th order harmonics appearing in one switching cycle. r,ni The harmonic voltage V generated by the output voltage to the i-th servo during the positive and negative cycles of out,ha , V out,ha The third-order, fifth-order, seventh-order and ninth-order odd harmonic component voltage amplitudes v3, v5, v7 and v9 generated by the third-order harmonic switching angle, fifth-order harmonic switching angle, seventh-order harmonic switching angle and ninth-order harmonic switching angle of the i-th servo are composed of Figure 5 The purple rectangular staircase line diagram in the second row is the voltage v9 of the odd harmonic component of the 9th harmonic in the positive half cycle of a switching cycle versus the output voltage V out,ha Contribution V out3 , which is from the 7th harmonic switching angle to the 9th harmonic switching angle and In one switching cycle, v9 shows the voltage value of the odd harmonic component with v7 as the reference; similarly, the green rectangular step line diagram in the third row shows the voltage v7 of the odd harmonic component of the 7th harmonic in the positive half cycle of one switching cycle versus the output voltage V out,ha Contribution V out2 , which is from the 4th order harmonic switching angle to the 6th order harmonic switching angle and In one switching cycle, v7 shows the voltage value of the odd harmonic component with v5 as the reference; the yellow rectangular step line diagram in the fourth row shows the voltage v5 of the odd harmonic component of the 5th order harmonic in one switching cycle versus the output voltage V out,ha Contribution V out1 , which is from the 1st order harmonic switching angle to the 3rd order harmonic switching angle and Generated in one switching cycle, v3 shows the voltage value of the odd harmonic component with v3 as the reference, and v3 is the voltage amplitude of the qth order odd harmonic component generated by the 3rd harmonic switching angle;

[0133] S32: Construct the first nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components:

[0134]

[0135] in, A nonlinear equation to make the amplitude of the odd harmonic components of the kth harmonic switching angle of the first servo controlled by the nth L298N module zero;

[0136] Where, q=3,5,7,…2k+1; v q for Abbreviation of is the voltage amplitude of the qth-order odd harmonic component generated by the qth-order harmonic switching angle; is the hth harmonic switching angle of the i-th servo controlled by the n-th L298N module; h=1,2,…,k;

[0137] Construct the second nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components:

[0138]

[0139] in, A nonlinear equation to make the amplitude of the odd harmonic components of the kth harmonic switching angle of the second servo controlled by the nth L298N module zero;

[0140] Where p = 3, 5, 7, ... 2k + 1; v p for Abbreviation of is the voltage amplitude of the p-th order odd harmonic component generated by the p-th order harmonic switching angle;

[0141] S33: Through Taylor expansion, the nonlinear equations in the first nonlinear equation group are The nonlinear equation in the second nonlinear system In the corresponding current d-generation solution Expand at

[0142] In the current d-generation solution The expanded form is as follows:

[0143]

[0144] In the current d-generation solution The expanded form is as follows:

[0145]

[0146] Among them, g∈{1,2,…,k}, They are the g-th harmonic switching angle of the first servo controlled by the n-th L298N module and the g-th harmonic switching angle of the second servo controlled by the n-th L298N module; therefore, They are the d-th generation solutions of the g-th order harmonic switching angle of the ith servo controlled by the n-th L298N module;

[0147] S34: Simplified into matrix form:

[0148] is the k×k element Jacobian matrix of the first nonlinear system of equations, J hg,n1 for The gth harmonic switch angle of the first servo controlled by the nth L298N module The first derivative of ; is the nonlinear equation in the first nonlinear equation system The d-th generation solution and its d-1-th generation solution The difference between is the d-th generation solution vector matrix of the first nonlinear equation system,

[0149] is the k×k element Jacobian matrix of the second nonlinear system of equations, J hg,n2 for The gth harmonic switching angle of the second servo controlled by the nth L298N module The first derivative of ; is the nonlinear equation in the second nonlinear equation system The d-th generation solution and its d-1-th generation solution The difference between is the d-th generation solution vector matrix of the second nonlinear equation system,

[0150] S35: According to the matrix form obtained in step S34, further iteratively solve the d+1th generation solution of the first nonlinear equation group and the second nonlinear equation group:

[0151]

[0152] S36: Calculate the total harmonic distortion THD of the first servo controlled by the nth L298N modulen1 Total harmonic distortion THD of the second servo n2 :

[0153]

[0154]

[0155] Determine the total harmonic distortion THD of the first servo n1 Total harmonic distortion TGD of the second servo n2 Are they all less than 0.35? If so, stop the iteration and output the optimal k-th harmonic switching angle of the ith servo controlled by the nth L298N module i=1,2; otherwise, repeat steps S31-S35 until the total harmonic distortion TGD of the first servo is n1 Total harmonic distortion TGD of the second servo n2 When all are less than 0.35, the kth optimal harmonic switching angle of the ith servo controlled by the nth L298N module is output.

[0156] In order to verify the k-th harmonic switching angle of the i-th servo controlled by the n-th L298N module through steps S31-S36 of the present invention, The optimization effect is achieved by using the traditional CNN method to optimize the kth harmonic switching angle of the i-th servo controlled by the n-th L298N module. Optimize. Figure 6 As shown, the different output voltages V of the i-th servo calculated by the traditional CNN method and the method of the present application are shown. out =5V~6V, the kth optimal harmonic switching angle of the i-th servo controlled by the n-th L298N module is further calculated through steps S32-S36. A comparison chart of the changes in Figure 6 (a) is the result of using the traditional method, Figure 6 (b) is the result of using the method of this application.

[0157] like Figure 7 As shown, Figure 7 (a) is the harmonic interference of the output voltage after optimization by the traditional CNN method. Figure 7 (b) is the harmonic interference of the output voltage after optimization by the method of the present invention, Figure 7 (c) for Figure 7 (a) The corresponding Fourier analysis results of the voltage optimized by the traditional CNN method. Figure 7 (d) for Figure 7(b) The corresponding Fourier analysis result of the output voltage after optimization using the method of the present invention.

[0158] Depend on Figure 7 (a) and Figure 7 (b) By comparison, Figure 7 (b) The k-th order harmonic switching angle optimized by the present invention is shown. The final output voltage V for the i-th servo is calculated in step S31 again. out = ±V ni,best (t) Overall relative to Figure 7 The k-th order harmonic switching angle calculation optimized by the traditional CNN method shown in (a) is again brought into step S31 to calculate the final output voltage V for the i-th servo out Smoother, with significantly reduced harmonic noise.

[0159] Depend on Figure 7 (c) and Figure 7 (d) By comparison, it can be seen that the frequency of harmonic interference of the k-th order harmonic switching angle optimized by the present invention is significantly reduced ( Figure 7 (d) The number of dark blue columns is relatively large Figure 7 (c) Less, and Figure 7 The column height of (d) is less than 7(c). In addition, when the fundamental amplitude (50Hz) is 4.5V, Figure 7 (d) Total harmonic distortion THD (16.25%) compared to Figure 7 (c) Total harmonic distortion THD (45.07%). In addition, Figure 8 As shown, with the output voltage V out As the output voltage continues to increase, the total harmonic distortion THD of the output voltage after optimization by the method of the present invention and the traditional CNN method are reduced, but when the output voltage is in the range of 5.0V-6.0V, the total harmonic distortion THD of the output voltage after optimization by the method of the present invention is lower than that of the output voltage after optimization by the traditional method.

[0160] Therefore, after the k-th harmonic switching angle of the ith servo controlled by the n-th L298N module is optimized by the method provided by the present invention and then brought into the S31 step again to solve, the total harmonic distortion of the output voltage obtained can be reduced to one third of the original value compared with the prior art. Therefore, the influence of harmonic interference on the output voltage amplitude of the servo can be effectively reduced, and the servo can be accurately controlled to rotate to the desired angle, thereby avoiding the occurrence of control deviation.

[0161] The method of the present invention comprises steps S31-S36, firstly constructing a structure having Bessel coefficients in step S31 The voltage calculation formula output to the i-th servo is used to dynamically adjust the output voltage amplitude according to the number of switching cycles and the amplitude and accuracy of the output voltage, providing multi-dimensional freedom for signal generation and adjustment. When the load of the i-th servo changes, the Bessel coefficient can be adjusted dynamically in real time to maintain the stability of the output signal and output voltage. Then, through the S32-S36 steps, the harmonic switching angle of the overmodulated signal is used to selectively eliminate specific harmonic components (3rd, 5th, 7th, 9th and other high-order harmonics), significantly reducing the amplitude of low-order harmonics, reducing the transmission of useless harmonic energy, and concentrating more energy on the fundamental frequency, thereby improving the harmonic distortion rate (THD) of the output signal, and finally achieving the precise elimination of specific-order harmonics, improving the quality of the output waveform, and making the signal closer to the ideal sine wave.

[0162] As another preferred embodiment of the present invention, in step S4, by comparing the reference signal voltage u r,n and the internal triangular carrier signal voltage u c,n , and then control the output voltage of the nth L298N module, whether the i-th servo is turned on or off, and whether it rotates forward or reverse to the desired angle γ after being turned on ni The rules are as follows: Figure 3 , Fig.16 As shown, when |u r,n |>|u c,n |, the first IGBT switch and the third IGBT switch of the i-th servo are controlled to be turned on (at this time, the second IGBT switch and the fourth IGBT switch of the i-th servo are controlled to be turned off), and at u r,n In the positive half cycle, the optimal positive high level voltage +V is output ni,best (t), the positive electrode of the i-th servo receives the optimal positive high-level voltage +V ni,best (t) to make the i-th servo rotate forward to the desired angle γ ni ; in u r,n In the negative half cycle, the output low level voltage is 0;

[0163] when|u r,n |<|u c,n |, the second IGBT switch and the fourth IGBT of the i-th servo are controlled to be turned on (at this time, the first IGBT switch and the third IGBT switch of the i-th servo are controlled to be turned off), and at u r,n In the positive half cycle, the output voltage is low level 0; r,n In the negative half cycle, the optimal negative high level voltage -V is output ni,best (t), the cathode of the i-th servo receives the optimal positive high-level voltage +V ni,best (t) to make the i-th servo reverse to the desired angle γ ni .

[0164] Table 1

[0165]

[0166] By utilizing the internal triangular carrier signal u c,n The smoothing characteristics of the reference signal u r,n The synchronous regulation optimizes the harmonic characteristics of the servo while reducing the electromagnetic interference (EMI) caused by high-order harmonics, improving the stability of the system. When switching between positive and negative voltages, the smooth transition of the output voltage reduces the impact on the servo and drive circuit, extending the service life of the equipment. You can adjust u for different servos and load conditions. r,n and u c,n The absolute value of is compared to realize the start or stop, and the forward and reverse rotation during the start process reaches the desired angle γ ni , achieving higher control flexibility, suitable for servo control under complex working conditions, such as robots, industrial automation and precision instruments. r,n positive half cycle or negative half cycle, when |u r,n |<|u c,n |, it switches to a low level voltage of 0, effectively protecting the servo from being stopped, avoiding damage to the equipment due to overload or misoperation, and ensuring that the servo operates only under valid control signal conditions, thereby improving safety.

[0167] The present invention also provides a steering gear control system based on the PCA9685 module for executing the above method, such as Fig. 9 As shown, the system includes a main control module, multiple PCA9685 modules and several L298N modules; multiple PCA9685 modules are cascaded with the main control module, and each PCA9685 module is connected to four L298N modules; the main control module is an Arduino Uno module;

[0168] The main control module also includes a duty cycle calculation module corresponding to the desired angle of the steering gear, a binary PWM signal calculation module, a sinusoidal reference wave signal r(t) generation module, and a harmonic suppression module;

[0169] The main control module is used to 2 C pin with multiple PCA9685 modules 2 The C interface performs serial address configuration to realize cascade connection, receive control instructions or upload real-time monitoring data;

[0170] The duty cycle calculation module corresponding to the desired angle of the servo is used to execute steps S21-S22, and calculate the duty cycle of the PWM signal for controlling the servo according to the target rotation angle of each servo;

[0171] The binary PWM signal calculation module is used to construct a binary PWM signal calculation model for modulating the i-th servo by the n-th L298N module connected to each PCA9865 module, and write it into the register of the PCA9685 module, and adjust the program to update the binary PWM signal;

[0172] The sinusoidal reference wave signal r(t) generation module is used to generate the sinusoidal reference signal r(t) and write it into the PCA9685 module register;

[0173] The harmonic suppression module is used to calculate the duty cycle D of each servo according to the duty cycle calculation module corresponding to the desired angle of the servo. ni Calculate the high level voltage V of the nth L298N module connected to each PCA9865 module to the i-th servo ni (t), optimize the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo

[0174] The PCA9685 module includes an internal triangular carrier signal c(t) generation module, a comparator module (step S4), and a PWM modulation signal output module; the internal triangular carrier signal c(t) generation module is used to generate a triangular carrier signal c(t);

[0175] The PWM modulation signal output module is used to compare the level u of the sine wave reference signal r(t) generated by the sine wave reference signal r(t) generation module according to the comparator module. r,n The level u of the triangular carrier signal c(t) generated by the triangular carrier signal c(t) generation module c,n The size of the reference signal r(t) for comparing the sinusoidal reference wave signal r(t) is written into the PCA9685 module register by the generation module to control the voltage u of the reference signal r(t) for the nth L298N module. r,n And the voltage u of the triangular carrier signal c(t) generated by the internal triangular carrier signal controlled by the nth L298N module set in the PCA9685 module c,n , by comparing the reference signal voltage u r,n and the internal triangular carrier signal voltage u c,n , and then control the nth L298N module to output the kth order optimal harmonic switching angle obtained by the harmonic suppression module optimization The optimal positive and negative high-level voltage ±V ni,best (t), whether the i-th servo is turned on or not, and after it is turned on, the duty cycle D of the i-th servo is calculated by executing steps S21-S22 according to the duty cycle calculation module corresponding to the desired angle of the servo ni The nth L298N module modulates the i-th servo with a binary PWM signal bPWM,ni (t), forward or reverse to the desired angle γ ni .

[0176] The main control module is 2 C interface communicates with the PCA9685 module, and the duty cycle calculation module corresponding to the desired angle of the servo executes steps S211-S214 to configure the no value and off value of each of the 16 channels of the PCA9685 module. The internal hardware timer of the PCA9685 module generates a PWM signal with a fixed frequency of 50Hz according to the configuration, that is, each switch switching period is 20ms.

[0177] like Fig.10 As shown, the Arduino Uno module provided by the present invention as a main control module includes a DC plug, an AMS1117-5.0 voltage regulator, a USB interface and a reset button which are arranged from left to right in sequence on the upper side of the vertical view. The DC plug supports power supply through an external power supply and is suitable for 7-12V DC input; the AMS1117-5.0 voltage regulator is used to step down the 12V voltage input from the outside connected to the Vin pin on the left to the +5V voltage required for the internal logic operation, the USB interface can be used for an external +5V power supply or input of a control command signal, and the reset button is used to reset the internal logic to an initial state.

[0178] The Arduino Uno module also includes a 16MHz crystal oscillator, a USB-to-serial chip, a serial communication indicator, a D13 pin signal indicator, an ATmega328P microcontroller, an ICSP pin, a power indicator, an IOREF pin on the left (provides a logic level reference voltage (usually 5V) for external expansion board detection and adaptation), a RESET pin (for receiving external reset control instructions), a pin that outputs +3.3V voltage, a +5V pin that outputs +5V voltage, two ground GND pins, a Vin pin, and A0-A5 pins, which are input pins for an external DC power supply. When the user uses an external power supply (such as a battery or power adapter) to power the development board, this pin should be connected to the positive pole of the power supply. When there is voltage input to the Vin pin, it will override the power provided by the USB or other pins to power the development board. The Vin pin can be connected to an external +5V power supply or +6V, +9V or +12V power supply; a 16MHz crystal oscillator is used to provide a clock signal for the microcontroller; the AREF (Analog Reference) pin can provide a reference voltage for the Arduino ADC (Analog-to-Digital Converter) to improve the measurement accuracy of analog input or adapt to specific measurement requirements. The ICSP pin allows the user to directly program or debug the microcontroller on the development board without removing the microcontroller from the development board; the ATmega328P microcontroller is the core processor, responsible for processing programs and controlling peripherals. The duty cycle calculation module corresponding to the desired angle of the servo, the binary PWM signal calculation module, the sinusoidal reference wave signal r(t) generation module, and the harmonic suppression module in the system claimed by the present invention are all set in the microcontroller.

[0179] The six pins A0-A5 are used to read external analog signals. An analog signal is a continuously changing signal that can represent a variety of physical quantities such as temperature, pressure, light intensity, etc. Arduino reads these analog signals through these pins and then converts them into digital values ​​for use by the program.

[0180] The Arduino Uno module also includes 14 digital I / O pins located on the right side of the board in a vertical perspective, and SDA pins and SCL pins located on the 14 digital I / O pins, which can be used to receive external digital signals and clock signals respectively; the 14 digital I / O pins can be used as input pins to read the logic state (high level or low level) of external devices, and can also be used as output pins to control the switch state of external devices.

[0181] Among them, pin 13 is connected to an onboard LED indicator. Users can control the state of this pin through programming, thereby controlling the on and off of the LED light, which can help users understand the execution status of the code.

[0182] Pins 3, 5, 6, 9, and 10 are all PWM pins, which support PWM (pulse width modulation) function. Users can control the voltage of these pins through programming to achieve more precise control, such as adjusting the speed of the motor or the brightness of the LED. Of course, they can also be used as digital input / output pins. In addition, pins 0, 1, 2, 7, 8, and 12 only have digital input / output functions and do not have PWM pulse width modulation functions. Among them, pin 1 is marked with TX (transmit) and pin 0 is marked with RX (receive). These two pins are used to send and receive signals during serial communication. In Arduino programming, users can use these two pins to exchange data with computers or other devices.

[0183] like Fig.11 As shown, it is a horizontal schematic diagram of the PCA9685 module provided by the present invention, including the Vin pin and the GND pin on the green terminal row located in the center of the upper part of the board. The Vin pin is used to introduce an external power supply with a voltage of +5V to +12V, and the GND pin is used for grounding. If multiple servos (more than five servos) or high-torque servos are used, the positive and negative electrodes of the external power supply need to be connected respectively through the Vin pin and the GND pin; it also includes the GND pin, the OE enable port, the SCL pin, and the SDA pin arranged in sequence from top to bottom on the left side thereof. , VCC pin and V+ pin. The above six pins are also set correspondingly on the right side of the board. There are 16 PWM output pins arranged from left to right on the lower side of the board, namely channels 0-15. Each channel consists of a yellow pin (for the output of binary PWM signals), a red VCC pin and a black GND pin arranged from top to bottom. When the two controlled servos do not require an additional L298N module for intermittent on and off control, the yellow pin, red pin and black pin of each servo can be connected to one of the 16 channels. The OE enable port is low-level enabled. When connected to a low level (GND), the PWM output is valid; when it is a high level, all PWM outputs are turned off (high impedance). The SCL pin and SDA pin are the clock signal pin and data signal pin of the I2C bus, respectively. The VCC pin is I 2 The power pin of the C communication part is usually connected to the 5V or 3.3V pin of the Arduino to power the logic circuit of the module.

[0184] The PCA9685 module also includes address configuration pins located on its upper right side: A0, A1, A2, A3, A4, and A5, which are used to set the I 2 The PCA9685 module also includes a PWM central core chip located below the green terminal row, which is located in the center of the board. 2The C communication receives the command output by the main control module Arduino Uno and outputs the corresponding binary PWM signal for controlling the steering gear. The triangular carrier signal c(t) generation module, the comparator module (step S4), and the PWM modulation signal output module in the system provided by the present invention are all arranged therein.

[0185] like Fig.12 As shown in the figure, it is the circuit diagram of PCA9685 module. U1 in the middle is the PCA9685 module board. The VDD pin on the upper right is the chip power input pin connected to 5V power supply. The SDA pin and SCL pin are connected to Fig.11 The corresponding I 2 C bus data line and clock line, OE pin is Fig.11 The corresponding OE enable pin outputs the enable signal. When OE is pulled low, the PWM signal output is valid. Fig.11 The green terminal block in the figure corresponds to the GND pin, and the A0-A5 pins on the lower right side correspond to the Fig.11 The corresponding A0-A5 pins are Fig.12 It can be seen that it is connected to the VCC pin of the main control module through the solder joint configuration interface W1-W6 in turn, and then further connected to the laser diode D1 as the LED0 indicator and then connected to the ground with the R3 current limiting resistor. The LED0 indicator is used to indicate the working status of the module, and the R3 current limiting resistor is used to protect the LED0 indicator. In the process of connecting the A0-A5 pins to the solder joint configuration interface W1-W6, the lead wires are pulled down by the pull-down resistors R1A, R1B, R1C, R1D, R2A, and R2B respectively to ensure that the pins will not float when the jumper is not connected. The PWM0-PWM15 on the right side of the U1 board corresponds to Fig.11 Channels 0-15 in the output are connected to the PWM signal receiving yellow pins of the servo through current limiting resistors R4A, R4B, R4C, R4D, R8A, R8B, R8C, R8D, R9A, R9B, R9C, R9D, R10A, R10B, R10C, and R10D. The output connectors HeaderP0 to HeaderP12 are 12-bit PWM controllers. P17 in the lower left corner is the external device power supply connection Header and P18 are corresponding Fig.11The external power supply of the PCA9685 module on the right side of the middle board is connected to the Header. Through the connection of P17 and P18, the PCA9685 module can output 5V power for the external devices connected to it to operate the external devices. When the PCA9685 module powers the external devices, it provides a stable current through the MOSFET circuit, which includes a P-channel MOSFET tube (for controlling the distribution of external power supply), a pull-up resistor R10D (for stabilizing the gate voltage of the MOSFET circuit) and a 2.2μF C2 capacitor for power decoupling and stabilization.

[0186] like Fig.13 As shown, it is a forward top view of the L298N module used in the system of the present invention, including an onboard heat sink located at the top, a fifth diode D5, a first diode D1, a second diode D2 and a sixth diode D6 from top to bottom on the upper left side, and an eighth diode D8, a fourth diode D4, a third diode D3 and a seventh diode D7 opposite to them on the right side; it also includes a first blue output module for controlling the first servo (Motor A) located below the four diodes on the left and a second blue output module for controlling the second servo (Motor B) located below the four diodes on the right, the first blue output module includes an OUT1 pin and an OUT2 pin, the second blue output module includes an OUT3 pin and an OUT4 pin, two capacitors (220μF, 35V specification) located between the first blue output module and the second blue output module, a MOS tube (user-controlled H-bridge switch control) and an onboard 5V enable (jumper cap), and the two capacitors are used to filter and stabilize the power supply voltage to reduce the unstable power supply voltage caused by power supply signal noise. The onboard 5V enable is connected by default. The internal voltage regulator of the module will convert +12V to 5V for use by the logic circuit and output it through the +5V pin. If an external 5V power supply is used, this jumper should be removed to avoid power supply conflicts. The L298N module also includes a blue power supply terminal at the bottom, which includes a +12V pin, a GND pin and a +5V pin. The ENA enable pin, IN1 pin, IN2 pin, IN3 pin, IN4 pin and ENB enable pin are also set on the left side of the blue power supply terminal. The ENA enable pin and the ENB enable pin are used to receive binary PWM signals, thereby respectively controlling the duty cycle adjustment of the first servo and the second servo. IN1-IN2 is used to control the high and low level combination of the voltage accessed by the two coils of the first servo, and IN3-IN4 is used to control the high and low level combination of the voltage accessed by the two coils of the second servo, thereby respectively controlling the forward and reverse rotation or stop of the two motors.

[0187] like Fig.14As shown, it is a circuit diagram of the L298N module. The largest yellow module in the center of the figure is the L298N module PCB board, wherein IN1, IN2, IN3 and IN4 (pin numbers 1, 2, 3 and 4 respectively) are connected to the control terminal P1, and are used to control the states of OUT1-OUT4 respectively. The states of OUT1 (pin number 9) and OUT2 (pin number 10) reflect the direction of the first servo (MotorA) connected to the L298N module, the states of OUT3 (pin number 11) and OUT4 (pin number 12) reflect the direction of the second servo (MotorB) connected to the L298N module, ENA (pin number 5) and ENB (pin number 6) are respectively connected to the P1 control terminal. The present application is in Fig.17 , Fig.18 The ENA and ENB terminals are connected to the Arduino Uno module to receive the binary PWM signal output by the Arduino Uno module and adjust the first and second servos to receive the signal that can rotate them to the desired angle γ. ni The high level voltage causes the motor to rotate. Fig.14 The VSS pin (pin number 7) in the MCU is connected to the +5V external power supply to power the internal logic operation, the VS pin (pin number 8) is used to power the two servos, and the GND pin (pin number 13) provides the ground reference.

[0188] OUT1 is connected to the first diode D1 and the sixth diode D6, and then further connected to the first servo ( Fig.14 OUT2 is connected to the cathode of I1 in the figure; after OUT2 is connected to the second diode D2 and the fifth diode D5, it is further connected to the anode of the first servo through the A+ lead; after OUT3 is connected to the third diode D3 and the eighth diode D8, it is further connected to the anode of the second servo through the B+ lead; after OUT4 is connected to the fourth diode D4 and the seventh diode D7, it is further connected to the cathode of the second servo through the B- lead.

[0189] A first light-emitting diode L1 and a second light-emitting diode L2 are also connected in parallel between the A- lead and the A+ lead connected to OUT1, OUT2 and the positive and negative electrodes of the first servo, and serve as indicator lights to indicate the forward and reverse working status of the first servo. When the first servo rotates forward, only the first light-emitting diode L1 emits light, and when the first servo rotates reversely, only the second light-emitting diode L2 emits light.

[0190] A third light-emitting diode L3 and a fourth light-emitting diode L4 are also connected in parallel between OUT3, OUT4 and the B+ lead and B- lead connected to the positive and negative poles of the second servo, and serve as indicator lights to indicate the forward and reverse working status of the second servo. When the second servo rotates forward, only the third light-emitting diode L3 emits light, and when the second servo rotates reversely, only the fourth light-emitting diode L4 emits light.

[0191] like Fig.15 As shown, the specific double H-bridge drive circuit diagram of the largest yellow module in the center of the L298N module ( Fig.14 The largest yellow module in the image is rotated 90 degrees to the left and Fig.15 The driving circuit diagram shown in FIG.

[0192] In the present invention, the left SDA pin and SCL pin of the first PCA9685M module among the multiple PCA9685 modules connected to the Arduino Uno module are connected to the A4 pin and the A5 pin of the Arduino Uno module, the 5V pin of the Arduino Uno module and the left VCC pin of the first PCA9685 module among the multiple PCA9685 modules cascaded with it output the +5V voltage power supply required for the internal logic operation of the multiple PCA9685 modules, and the GND pin of the Arduino Uno module and the left GND pins of the multiple PCA9685 modules and the negative electrode of the external power supply are grounded together; the right GND pin, the right OE pin, the right SCL pin, the right SDA pin, the right VCC pin and the right V+ pin of the first PCA9685 module are respectively connected to the Arduino Uno module and the left VCC pin of the first PCA9685M module and the negative electrode of the external power supply are grounded together; the right GND pin, the right OE pin, the right SCL pin, the right SDA pin, the right VCC pin and the right V+ pin of the first PCA9685 module are respectively connected to the Arduino Uno module and the left VCC pin of the first PCA9685M module and the negative electrode of the external power supply are grounded together. The left GND pin, left OE pin, left SCL pin, left SDA pin, left VCC pin and left V+ pin of the second PCA9685 module in the Uno module cascade are connected through the black lead, sky blue lead, light yellow lead, dark green lead, dark red lead and peach pink lead respectively, and then the cascade of the second PCA9685 module to the last PCA9685 module and the Arduino Uno module is completed according to this pin connection rule.

[0193] Further, channels 0-15 of each PCA9685 module are connected to four L298N modules; wherein, channels 0-3 of each PCA9685 module are connected to the first L298N module, channels 4-7 are connected to the second L298N module, channels 8-11 are connected to the third L298N module, and channels 12-16 are connected to the fourth L298N module;

[0194] The +5V pin of each L298N is connected to the red VCC pins of the four corresponding channels of the PCA9685 connected to it, so as to receive the +5V voltage power supply required for its internal logic operation; the GND pin of each L298N module is connected to the negative pole of the external power supply, and the +12V pin is connected to the positive pole of the external power supply, and the IN1 pin, IN2 pin, IN3 pin and IN4 pin of each L298N module are respectively connected to the corresponding four channels, so as to receive the calculated k-th optimal harmonic switching angle of the n-th L298N module connected to each PCA9685 module after optimization and written into the register of the PCA9685 module by the Arduino Uno module. The corresponding high level voltage V for the i-th servo ni,best (t); The ENA enable pin and the ENB enable pin of each L298N module are connected to the digital pin 11 and the digital pin 3 of the Arduino Uno module respectively, so as to receive the intermittent start control instruction of the i-th servo related to the binary PWM signal written into the corresponding PCA9865 module and the voltage comparison result of the reference signal r(t) output by the PWM modulation signal output module in the PCA9685 module and the carrier signal c(t);

[0195] Each L298N module is connected to two servos: the first servo and the second servo; the OUT1 pin and OUT2 pin of each L298N module are respectively connected to the two ends of the first coil and the two ends of the second coil of the first servo, and the OUT3 pin and OUT4 pin of each L298N module are respectively connected to the two ends of the first coil and the two ends of the second coil of the second servo.

[0196] like Fig.18As shown in the figure, the main control module Arduino Uno module, PCA9685 module, L298N module and each L298N module are connected to the positive and negative electrodes of the external power supply, specifically the Vin pin of the Arduino Uno module, the +12V voltage pin of the L298N module, and the red VCC pins of the two servos that each L298N controls to be turned on intermittently are respectively connected to the positive electrode of the external power supply through dark red wires, and the power for the internal logic operation of each module and the power for the two servos controlled by each L298N module to perform forward and reverse movements are introduced. In addition, the 5V output pin of the Arduino Uno module is also connected to the left VCC pin of the PCA9585 module through a dark red wire. Then, when the external power supply inputs +12V voltage to the Vin pin of the Arduino Uno module, the Arduino The Uno module uses the internal AMS1117-5.0 regulator to step down the voltage to a +5V voltage suitable for the power required for the internal logic operation of the PCA9685 module and the L298N module connected to it. At the same time, the GND pin of the Arduino Uno module, the GND pin on the left side of the PCA9685 module, and the GND pin of each L298N module are all connected to the ground through black wires, and the two servos controlled by each L298N module are also connected to the ground. In this case, there are fewer PCA9685 modules suitable for cascading Arduino Uno modules, and the voltage required for the forward and reverse movement of the servos is +5V. At this time, the total number of servos controlled by the main control module Arduino Uno module is small, and the +5V voltage of the external power supply is sufficient to meet the power requirements of the forward and reverse movement of all connected servos. At the same time, the red VCC pins of channels 0-3 of each PCA9685 module are connected to the +5V pins of the L298N modules corresponding to channels 0-3 to power the internal logic operation of the L298N modules, and the black pins of channels 0-3 are also grounded; the red VCC pins of channels 4-7 of the PCA9685 module are connected to the +5V pins of the second L298N module connected to the PCA9685 module to power the internal logic operation of the second L298N module, and so on, the red VCC pins of channels 8-11 and channels 12-15 of the PCA9685 module are respectively connected to the +5V pins of the third L298N module and the +5V pins of the fourth L298N module connected to the PCA9685 module to power them respectively. The lead colors and connection methods of the ENA enable pin, ENB enable pin, IN1-IN4 enable pin of the second L298N module to the fourth L298N module, the PCA9685 module and the Arduino Uno module are the same as those of the first L298N module.

[0197] At this point, the A4 pin of the Arduino Uno module is connected to the SDA data pin of the PCA9685 module through a dark green wire to achieve I2C with the PCA9685 module. 2 C communication transmission, through the above pin connection, the Arduino Uno module can obtain the A0-A5 pin jumper configuration status recognition result located on the upper right of each PCA9685 module connected to it, and then implement steps S11-S13 to complete the Arduino Uno module according to the calculated I 2 C hexadecimal address transmits corresponding control instructions to each PCA9685 module;

[0198] The A5 pin of the Arduino Uno module is connected to the SCL clock pin of the PCA9685 module through a light yellow lead, which is used to write the sinusoidal reference signal r(t) generated by the sinusoidal reference wave signal r(t) generation module into the PCA9685 module, thereby providing the comparator module in the PCA9685 module with an object for comparison with the triangular wave signal c(t) generated by the internal triangular carrier signal c(t) generation module set inside it, thereby realizing the generation of intermittent start control instructions for the i-th servo connected to the n-th L298N module.

[0199] Pin 3 of the Arduino Uno module is connected to the ENA enable pin of the nth L298N module through a light pink lead, and pin 11 of the Arduino Uno module is connected to the ENB enable pin of the nth L298N module through a light green lead, thereby realizing duty cycle modulation of the nth L298N module. The duty cycle calculation module corresponding to the desired angle of the servo in the Arduino Uno module executes steps S21-S22, and specifically executes S211-S14 to calculate the duty cycle of the PWM signal for controlling the servo according to the target rotation angle of each servo and the corresponding on value and off value in a switching cycle, and then further transmits them to the binary PWM signal calculation module, and then the binary PWM signal calculation module executes step S23 to calculate the binary PWM signal modulated by the nth L298N module for the i-th servo; the modulation is respectively adjusted to the angle γ that the servo is expected to rotate to. ni The binary PWM signal is written into the nth L298N module indirectly connected to it through the ENA enable terminal and the ENB enable terminal, and further waits for the comparison result control instruction of the comparator module of the PCA9685 module. In the process of intermittent opening of IN1-IN4 controlled by the control instruction, the high-level voltage output by the servo in the positive and negative cycles of r(t) when the i-th servo is turned on meets the duty cycle required by the desired angle and meets the k-th optimal harmonic switching angle after the harmonic suppression module suppresses the harmonics. Output voltage value |V ni,best (t)|;

[0200] The 5th, 6th, 9th and 10th pins of the Arduino Uno module are connected to the yellow pins of the PCA9685 module channels 0-3 through the brown lead, the rose-red lead, the light blue lead and the purple lead, respectively. At the same time, the yellow pins of the PCA9685 module channels 0-3 are further connected to the IN1 pin, IN2 pin, IN3 pin and IN4 pin of the nth L298N module through the brown lead, the rose-red lead, the light blue lead and the purple lead, respectively. Then, the Arduino Uno module performs the S31-S36 steps to calculate the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module after optimization to control the i-th servo. The corresponding high level voltage V for the i-th servo ni,best (t) is written into the PCA9685 module, and the 5th, 6th, 9th and 10th pins of the Arduino Uno module write the binary PWM signal calculated by the binary PWM signal calculation module into the PCA9685 module. According to the comparison result of the comparator module of the PCA9685 module, the yellow pins of channels 0-3 of the PCA9685 module control the instruction according to the comparison result of the comparator module. In the positive and negative half-cycles of the r(t) signal, the desired angle γ of the duty cycle that meets the desired angle is adjusted according to the ENA and ENB enable terminals. ni , control the PWM modulation signal output module to output the duty cycle D of the ith servo calculated by the duty cycle calculation module executing steps S21-S22 to the IN1-IN4 pins of the L298N module with the desired angle of the servo ni The nth L298N module modulates the i-th servo with a binary PWM signal b PWM,ni (t), and then rotate forward or reverse to the desired angle γ ni .

[0201] The OUT2 and OUT1 pins of each L298N module are connected to the positive and negative poles of the first servo through the dark blue and orange wires respectively according to the binary PWM signals received by the IN1 and IN2 pins; the OUT3 and OUT4 pins of each L298N module are connected to the positive and negative poles of the second servo through the dark blue and orange wires respectively according to the binary PWM signals received by the IN3 and IN4 pins;

[0202] like Fig.14 , Fig.15As shown, the OUT1 pin of the L298N module is connected to the first IGBT switch IGBT that controls the opening and closing of the first servo. 1,1 and the second IGBT switch IGBT 2,1 Connect the OUT2 pin to the third IGBT switch IGBT that controls the first servo on and off. 3,1 and the fourth IGBT switch IGBT 4,1 Connect the OUT3 pin to the first IGBT switch IGBT that controls the opening and closing of the second servo 1,2 and the second IGBT switch IGBT 2,2 Connect the OUT4 pin to the third IGBT switch IGBT that controls the opening and closing of the second servo. 3,2 and the fourth IGBT switch IGBT 4,2 connect

[0203] Recombination Fig.13 , Fig.14 As shown, the first IGBT switch IGBT that controls the opening and closing of the first servo 1,1 , the second IGBT switch IGBT 2,1 、The third IGBT switch IGBT 3,1 and the fourth IGBT switch IGBT 4,1 The first IGBT switch IGBT for controlling the on and off of the second servo is used to connect and turn on or off the first diode D1, the second diode D2, the fifth diode D5 and the sixth diode D6. 1,2 , the second IGBT switch IGBT 2,2 、The third IGBT switch IGBT 3,2 and the fourth IGBT switch IGBT 4,2 The third diode D3, the fourth diode D4, the seventh diode D7 and the eighth diode D8 are respectively used to connect and turn on or off. The first diode D1 to the sixth diode D6 are all connected to the first servo, and the second diode D2 to the eighth diode D8 are connected to the second servo. The voltage comparison results of the reference signal r(t) in the positive half cycle and the negative half cycle with the carrier signal c(t), the conduction conditions of each IGBT switch, each diode (also used as a freewheeling tube), and the positive and negative output voltage conditions of the two servos connected to OUT1-OUT4 are shown in the figure. Fig.16 shown.

[0204] like Fig.19 As shown in the second power supply method, when a main control module Arduino Uno module is cascaded with multiple PCA9685 modules, the power supply required by multiple servos is only as follows Fig.18When the external power supply shown is not enough to supply 5V voltage to multiple servos at the same time, or when multiple servos require an external power supply voltage of +12V, +9V or +6V, a second external power supply connection is used at the Vin+ pin on the upper part of each PCA9685 module connected to the Arduino Uno module, such as Fig.19 As shown, at this time, the positive and negative poles of the external power supply are connected to the V+ pin and GND pin on the upper part of the PCA9685 module through the second dark red lead and the second black lead respectively, and the second dark red lead is connected to the +12V pin of the L298N module, thereby providing the power supply voltage required for the rotation of the two servos connected to the nth L298N module; and the second black lead of the second external power supply is also connected to the GND pin of the L298N module and then grounded. The remaining pin connection methods are the same as the first power supply method mentioned above. When the second power supply method with two external power supplies is adopted, the positive and negative poles of the second external power supply can also be directly connected to the +12V pin and GND pin of the L298N module respectively, thereby directly powering the L298N module and the two servos connected thereto. In this case, the internal logic power supply of each PCA9685 module is completely supplied by the 5V output pin of the Arduino Uno module connected to its left VCC pin. Each PCA9685 module needs several second external power supplies for each L298N module connected thereto, thereby ensuring the external +12V voltage power supply required for the forward and reverse rotation of the two servos controlled by each L298N module, and avoiding the situation where a second external power supply is connected to the V+ pin of the PCA9685 module and is insufficient to supply the power required for the forward and reverse operation of the four L298N modules and eight servos connected to the PCA9685 module at the same time. Fig.18 and Fig.19 The L298N module in the Fig.13 Schematic diagram of connecting to other modules after rotating 180 degrees based on its own center point.

[0205] Although the present invention has been described with reference to preferred embodiments, various modifications may be made thereto and the technical features thereof may be replaced with equivalents without departing from the scope of the present invention. The present invention is not limited to the specific embodiments disclosed herein, but includes all technical solutions falling within the scope of the claims.

Claims

1. A steering gear control method based on a PCA9685 module, wherein the method controls multiple steering gears uniformly through the PCA9685 module, and controls the switching time and duty cycle of each steering gear based on a program written into the register of the PCA9685 module by a main control module, thereby achieving the effect of regulating different steering gears to start or stop moving when needed, characterized in that: The following steps are involved: S1: I of the main control module 2 C pin with multiple PCA9685 modules 2 The C interface performs serial address configuration to realize cascade connection, receive control instructions or upload real-time monitoring data; S2: Calculate the duty cycle of the PWM signal for controlling each servo according to the target rotation angle of each servo, construct a binary PWM signal calculation model for the nth L298N module connected to each PCA9865 module to modulate the i-th servo, write it into the register of the PCA9685 module, and adjust the program to update the binary PWM signal; S3: Further calculate the duty cycle D of each servo according to step S2 ni Calculate the high level voltage V of the nth L298N module connected to each PCA9865 module to the i-th servo ni (t), optimize the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo S4: Compare the voltage u of the reference signal r(t) for controlling the nth L298N module written by the main control module into the PCA9685 module register r,n And the internal carrier signal c(t) voltage u set in the PCA9685 module to control the nth L298N module c,n , by comparing the voltage u of the reference signal r(t) r,n and the voltage u of the internal carrier signal c(t) c,n , and then control whether the i-th servo connected to the n-th L298N module is turned on or off, and rotates forward or reverse to the desired angle γ after it is turned on ni , and when it is turned on, the output has the kth order optimal harmonic switching angle The optimal positive and negative high-level voltage ±V ni,best (t), and the output voltage value is 0 at the turn-off time.

2. The steering gear control method based on the PCA9685 module according to claim 1 is characterized in that: In the S1 step, multiple PCA9685 modules are connected through I 2 C interface and the main control module's I 2 C pin cascade connection, including: S11: Obtain the I of the A0-A5 pins of the nth PCA9685 module by identifying the A0-A5 pin jumper configuration status of each PCA9685 module 2 C binary address set A n ={add A0,n ,add A1,n ,add A2,n ,add A3,n ,add A4,n ,add A5,n }; among them, add A1,n 、add A2,,n 、add A3,n 、add A4,n and add A5,n The I pins of A0, A1, A2, A3, A4 and A5 of the nth PCA9685 module are 2 C binary value; add A1,n 、add A2,n 、add A3,n 、add A4,n and add A5,n The values ​​of are all 0 or 1; S12: According to the obtained A0-A5 pin I of the nth PCA9685 module 2 C binary value, the main control module calculates the I configured to the nth PCA9685 module 2 C hexadecimal address ADD n =0x40+(add A5,n ×2 5 )+(add A4,n ×2 4 )+(add A3,n ×2 3 )+(add A2,n ×2 2 )=(add A1,n ×2 1 )+(add A0,n ×2 0 ); where 0x40 represents the hexadecimal number 40; S13: The main control module calculates the I 2 C hexadecimal address to transmit the corresponding control instructions to each PCA9685 module.

3. The steering gear control method based on the PCA9685 module according to claim 1 is characterized in that: The S2 step includes the following steps: S21: Determine the rotation angle γ that each servo needs to reach ni , according to which the high-level pulse width T in the PWM control cycle is calculated on,ni ; γ ni The target rotation angle of the ith servo controlled by the nth L298N module connected to each PCA9865 module; S22: Further calculation of the rotation angle to be achieved is γ ni The duty cycle of the PWM control cycle is D ni : Among them, T on,ni , T off,ni are respectively the high level pulse width and low level pulse width in a switching cycle, T on,ni +T off,ni =T ni , T ni The switching pulse width of a switch of the i-th servo controlled by the n-th L298N module; where i = 1 or 2, n = 1, 2, ... N; N is the total number of L298N modules connected to each PCA9685 module; S23: Duty cycle D obtained according to step S22 ni , construct the binary PWM signal calculation model for each PCA9865 module connected to the nth L298N module to modulate the i-th servo: Where a is the ath switching cycle, a=1,2,…; θ c,ni is the initial phase angle of the ith servo controlled by the nth L298N module, θ c,n1 =0,θ c,n2 = -π; f m is the control frequency of the PWM signal, f m =50Hz; the total pulse width T of a PWM signal control cycle is 20ms; let D n1 =D n , then D n2 =1-D n , D n The duty cycle of the first servo controlled by the nth L298N module in a switching cycle.

4. The steering gear control method based on the PCA9685 module according to claim 3 is characterized in that: The step S21 includes: S211: Setting T ni =2ms, calculate the PWM count value Count of a switching cycle: Count=T ni / T×4096=410; S212: Calculate the number of PWM counts required for each rotation of 1 degree according to different servo types E = Count / γ max ; Among them, γ max The maximum angle that different servo types can rotate to; servo types include γ max =90°,γ max =180°,γ max =270° or γ max =Any one or more of 360°; S213: Rotate according to target angle γ ni , calculate the total PWM count value required to achieve it, which is the end time t of the high-level pulse width in a switching cycle off,ni :t off,ni =γ ni ×E+t on,ni ; T off,ni =(4096-T on,ni )×20; when the rotation angle corresponding to the initial on value is 0 degrees, t on,ni =102.4; T on,ni =[(γ ni ×E) / 4096]×20; S214: Then obtain the corresponding target angle γ within a switching cycle ni The off value t off,ni , t off,ni =T on,ni +t on,ni ;t on,ni is the target angle γ corresponding to one switching cycle ni The on value is the moment when the binary PWM signal controls the start of the i-th servo; the off value is t off,ni The binary PWM signal controls the moment when the i-th servo is turned off.

5. The steering gear control method based on the PCA9685 module according to claim 3 is characterized in that: The S3 step includes: S31: Calculate the high level voltage V output by the nth L298N module to control the first servo n1 (t), the nth L298N module controls the high level voltage V output by the second servo n2 (t): in, is the kth harmonic switching angle of the ith servo controlled by the nth L298N module; b is the total number of high-level voltage outputs in one switching cycle; V d Provide power supply voltage for the nth L298N module with external power supply; is the a-order Bessel coefficient for adjusting the amplitude of the high-level voltage output by the i-th servo. When a=0, is the 0th-order Bessel coefficient; S32: Construct the first nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components: in, A nonlinear equation to make the amplitude of the odd harmonic components of the kth harmonic switching angle of the first servo controlled by the nth L298N module zero; Where, q=3,5,7,…2k+1; v q for Abbreviation of is the voltage amplitude of the qth-order odd harmonic component generated by the qth-order harmonic switching angle; is the hth harmonic switching angle of the i-th servo controlled by the n-th L298N module; h=1,2,…,k; Construct the second nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components: in, A nonlinear equation to make the amplitude of the odd harmonic components of the kth harmonic switching angle of the second servo controlled by the nth L298N module zero; Where p = 3, 5, 7, ... 2k + 1; v p for Abbreviation of is the voltage amplitude of the p-th order odd harmonic component generated by the p-th order harmonic switching angle; S33: Through Taylor expansion, the nonlinear equations in the first nonlinear equation group are The nonlinear equation in the second nonlinear system In the corresponding current d-generation solution Expand at: Among them, g∈{1,2,…,k}, They are the g-th harmonic switching angle of the first servo controlled by the n-th L298N module and the g-th harmonic switching angle of the second servo controlled by the n-th L298N module; They are the d-th generation solutions of the g-th order harmonic switching angle of the ith servo controlled by the n-th L298N module; S34: Simplified into matrix form: is the k×k element Jacobian matrix of the first nonlinear system of equations; is the nonlinear equation in the first nonlinear equation system The d-th generation solution and its d-1-th generation solution The difference between is the d-th generation solution vector matrix of the first nonlinear equation system, is the k×k element Jacobian matrix of the second nonlinear system of equations; is the nonlinear equation in the second nonlinear equation system The d-th generation solution and its d-1-th generation solution The difference between is the d-th generation solution vector matrix of the second nonlinear equation system, S35: According to the matrix form obtained in step S34, further iteratively solve the d+1th generation solution of the first nonlinear equation group and the second nonlinear equation group: S36: Calculate the total harmonic distortion THD of the first servo controlled by the nth L298N module n1 Total harmonic distortion THD of the second servo n2 : Determine the total harmonic distortion THD of the first servo n1 Total harmonic distortion THD of the second servo n2 Are they all less than 0.35? If so, stop the iteration and output the optimal k-th harmonic switching angle of the ith servo controlled by the nth L298N module i=1,2; otherwise, repeat the steps S31-S35 until the total harmonic distortion THD of the first servo is n1 Total harmonic distortion THD of the second servo n2 When all are less than 0.35, the kth optimal harmonic switching angle of the ith servo controlled by the nth L298N module is output.

6. The steering gear control method based on the PCA9685 module according to claim 1 is characterized in that: In step S4, by comparing the reference signal voltage u r,n and the internal triangular carrier signal voltage u c,n , and then control the output voltage of the nth L298N module, whether the i-th servo is turned on or off, and whether it rotates forward or reverse to the desired angle γ after being turned on ni The rule is: when |u r,n |>|u c,n |, the first IGBT switch and the third IGBT switch of the i-th servo are turned on. r,n In the positive half cycle, the optimal positive high level voltage +V is output ni,best (t), make the i-th servo rotate forward to the desired angle γ ni ; in u r,n In the negative half cycle, the output low level voltage is 0; when|u r,n |<|u c,n |, the second IGBT switch and the fourth IGBT of the i-th servo are controlled to turn on. r,n In the positive half cycle, the output voltage is low level 0; r,n In the negative half cycle, the optimal negative high level voltage -V is output ni,best (t), the i-th servo is reversed to the desired angle γ ni。 7. A steering gear control system based on a PCA9685 module that implements the method as claimed in any one of claims 1 to 6, characterized in that: A main control module, multiple PCA9685 modules and several L298N modules; multiple PCA9685 modules are cascaded with the main control module, and each PCA9685 module is connected to four L298N modules; the main control module is an Arduino Uno module; The main control module also includes a duty cycle calculation module corresponding to the desired angle of the steering gear, a binary PWM signal calculation module, a sinusoidal reference wave signal r(t) generation module, and a harmonic suppression module; The main control module is used to 2 C pin with multiple PCA9685 modules 2 The C interface performs serial address configuration to realize cascade connection, receive control instructions or upload real-time monitoring data; The duty cycle calculation module corresponding to the desired angle of the servo is used to calculate the duty cycle of the PWM signal for controlling the servo according to the target rotation angle of each servo; The binary PWM signal calculation module is used to construct a binary PWM signal calculation model for modulating the i-th servo by the n-th L298N module connected to each PCA9865 module, and write it into the register of the PCA9685 module to adjust the program to update the binary PWM signal; The sinusoidal reference wave signal r(t) generating module is used to generate a sinusoidal reference signal r(t) and write it into the PCA9685 module register; The harmonic suppression module is used to calculate the duty cycle D of each servo according to the duty cycle calculation module corresponding to the desired angle of the servo. ni Calculate the high level voltage V of the nth L298N module connected to each PCA9865 module to the i-th servo ni (t), optimize the kth optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo The PCA9685 module includes an internal triangular carrier signal c(t) generation module, a comparator module, and a PWM modulation signal output module; the internal triangular carrier signal c(t) generation module is used to generate a triangular carrier signal c(t); The PWM modulation signal output module is used to compare the voltage u of the sine wave reference signal r(t) generated by the sine wave reference signal r(t) generation module according to the comparator module. r,n The voltage u of the triangular carrier signal c(t) generated by the triangular carrier signal c(t) generating module c,n The size of the harmonic suppression module is optimized to control the output of the nth L298N module to have the kth optimal harmonic switching angle The optimal positive and negative high-level voltage ±V ni,best (t), whether the i-th servo is turned on or not, and after it is turned on, the duty cycle D of the i-th servo calculated by the duty cycle calculation module corresponding to the desired angle of the servo ni The nth L298N module modulates the i-th servo with a binary PWM signal b PWM,ni (t), forward or reverse to the desired angle γ ni .

8. The steering gear control system based on the PCA9685 module according to claim 7 is characterized in that: The left SDA pin and SCL pin of the first PCA9685M module among the multiple PCA9685 modules connected to the Arduino Uno module are connected to the A4 pin and the A5 pin of the Arduino Uno module, the 5V pin of the Arduino Uno module and the left VCC pin of the first PCA9685 module among the multiple PCA9685 modules cascaded with it output the +5V voltage power supply required for the internal logic operation of the multiple PCA9685 modules, and the GND pin of the Arduino Uno module and the left GND pins of the multiple PCA9685 modules and the negative electrode of the external power supply are grounded together; the right GND pin, the right OE pin, the right SCL pin, the right SDA pin, the right VCC pin and the right V+ pin of the first PCA9685 module are respectively connected to the Arduino Uno module and the left VCC pin of the first PCA9685M module and the negative electrode of the external power supply are grounded together. The left GND pin, left OE pin, left SCL pin, left SDA pin, left VCC pin and left V+ pin of the second PCA9685 module in the Uno module cascade are connected through different leads respectively, and then the cascade of the second PCA9685 module to the last PCA9685 module and the Arduino Uno module is completed according to this pin connection rule.

9. The steering gear control system based on the PCA9685 module according to claim 8 is characterized in that: Channels 0-15 of each PCA9685 module are connected to four L298N modules; among them, channels 0-3 of each PCA9685 module are connected to the first L298N module, channels 4-7 are connected to the second L298N module, channels 8-11 are connected to the third L298N module, and channels 12-16 are connected to the fourth L298N module; The +5V pin of each L298N is connected to the red VCC pins of the four corresponding channels of the PCA9685 connected to it, so as to receive the +5V voltage power supply required for its internal logic operation; the GND pin of each L298N module is connected to the negative pole of the external power supply, and the +12V pin is connected to the positive pole of the external power supply, and the IN1 pin, IN2 pin, IN3 pin and IN4 pin of each L298N module are respectively connected to the corresponding four channels, so as to receive the calculated k-th optimal harmonic switching angle of the n-th L298N module connected to each PCA9685 module after optimization and written into the register of the PCA9685 module by the Arduino Uno module. The corresponding high level voltage V for the i-th servo ni,best (t); The ENA enable pin and the ENB enable pin of each L298N module are respectively connected to the digital pin 11 and the digital pin 3 of the Arduino Uno module, so as to receive the intermittent start control instruction of the i-th servo related to the binary PWM signal written into the corresponding PCA9865 module and the voltage comparison result of the reference signal r(t) output by the PWM modulation signal output module in the PCA9685 module and the carrier signal c(t); Each L298N module is connected to two servos: the first servo and the second servo; the OUT1 pin and OUT2 pin of each L298N module are respectively connected to the two ends of the first coil and the two ends of the second coil of the first servo, and the OUT3 pin and OUT4 pin of each L298N module are respectively connected to the two ends of the first coil and the two ends of the second coil of the second servo.

Citation Information

Patent Citations

  • Steering engine driving device based on single chip microcomputer

    CN106200498A

  • Steering gear control system and method based on fuzzy neural PID control and absolute encoder

    CN108196442A

  • Steering engine control method

    CN112650112A

  • Non-inductive intelligent control circuit for driving motor of electric vehicle

    CN114389506A

  • Steering engine control method and system based on key frame action

    CN114911178A