Servo control method and system based on PCA9685 module
Through the coordinated work of the PCA9685 module and the L298N module, the harmonic switching angle and duty cycle adjustment are optimized, which solves the problems of poor synchronization and limited expansion in servo control, and realizes efficient and precise control of multiple servo machines. It is suitable for robotic arms, automated transportation and logistics sorting and other fields.
Patent Information
- Application Number
- CN202510012719.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-01-06
AI Technical Summary
In the prior art, servo control has problems such as poor synchronization, large signal interference, high control complexity, slow response speed and limited scalability. It is especially difficult to achieve efficient direction switching and dynamic adjustment when multiple servo drives work together.
Through the collaborative work of 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-server synchronization control solution, optimize the harmonic switching angle and duty cycle adjustment, and achieve unified control of multiple servoes.
It improves the accuracy and efficiency of servo control, meets the needs of coordinated control of multiple servo in complex scenarios, realizes synchronous control of multiple servo and high-precision forward and reverse adjustment, reduces hardware cost and design difficulty, and has low energy consumption, low interference and high robustness.
Smart Images

Figure CN119748453B_ABST
Abstract
Description
Technical Field
[0001] The present 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 particularly 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 in applications such as robotic arms, automated transportation, and logistics sorting. Prior art servo control methods or systems, such as those disclosed in publications CN111376245A and CN109696910A, typically use GPIO pins on a single-chip microcomputer or an independent PWM generator to generate signals. This approach suffers from poor synchronization, significant signal interference, and high control complexity when multiple servos work together. Furthermore, traditional PWM signal generation relies on hardware circuits or software simulation, resulting in slow response and an inability to 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 to solve the above-mentioned problems and provides a steering gear control method and system based on PCA9685 module. 2 The multi-device cascading capabilities of the C-bus and the high-resolution PWM signal generation capabilities of the PCA9685 module enable the creation of a modular, multi-servo synchronization control solution. By optimizing harmonic switching angles and duty cycle regulation, this solution overcomes existing issues such as poor synchronization, slow response, and limited scalability of multiple servos. This significantly improves control accuracy and efficiency, meeting the demands for coordinated multi-servo control in complex scenarios.
[0005] The present invention provides the following technical solution: a steering gear control method based on the 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 PCA9685 module register by a main control module, thereby achieving the effect of regulating different steering gears to start or stop movement when needed, including the following steps:
[0006] S1: I of the main control module 2 C pin and multiple PCA9685 modules 2The C interface is used to configure the serial address to realize cascade connection, receive control instructions or upload real-time monitoring data;
[0007] S2: Calculate the duty cycle of the PWM signal that controls each servo based on the target rotation angle of that 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 the model 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 order 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 moment.
[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 I2C values 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 I2C pins A0, A1, A2, A3, A4 and A5 of the nth PCA9685 module 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 pins 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 , based on which the high-level pulse width T in the PWM control cycle is calculated on,ni ; γ ni The target rotation angle of the i-th servo controlled by the n-th L298N module connected to each PCA9865 module;
[0016] S22: Further calculation of the rotation angle to be achieved is γ ni The duty cycle D of the PWM control cycle 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 the i-th servo controlled by the n-th L298N module; where i = 1 or 2, n = 1, 2, ... N; and N is the total number of L298N modules connected to each PCA9685 module.
[0018] S23: Duty cycle D obtained according to step S22 ni , build a 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 i-th servo controlled by the n-th 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 within a switching cycle.
[0021] Furthermore, the step S21 includes:
[0022] S211: Set 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 degree of rotation based on different servo types: E = Count / γ max ; Among them, γ max The maximum angle that can be achieved by different servo types; 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 initial on value corresponds to a rotation angle of 0 degrees, t on,ni =102.4; T on,ni =[(γ ni ×E) / 4096]×20;
[0026] S214: Obtaining 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 i-th servo controlled by the n-th L298N module; b is the total number of high-level voltage outputs in one switching cycle; V d Provides power voltage to the nth L298N module through 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 The 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 The 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-th 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; are the dth generation solutions of the gth order harmonic switching angle of the i-th servo controlled by the nth L298N module;
[0044] S34: Simplified to 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 and the 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 i-th servo controlled by the n-th L298N module. i=1,2; otherwise, repeat the steps S31-S35 until the total harmonic distortion THD of the first servo is n1 and the total harmonic distortion THD of the second servo n2 When all values are less than 0.35, the kth-order optimal harmonic switching angle of the i-th servo controlled by the n-th 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 output is the optimal positive high level voltage +V 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 is a low level voltage of 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; in u r,n During the negative half cycle, the optimal negative high level voltage -V is output. ni,best (t), make the i-th servo reverse 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, multiple PCA9685 modules and several L298N modules; the 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;
[0056] The main control module also includes a duty cycle calculation module for the desired steering gear angle, 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 and multiple PCA9685 modules 2The C interface is used to configure the serial address 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, write the model into the register of the PCA9685 module, and adjust the program to update the binary PWM signal;
[0060] The sinusoidal reference wave signal r(t) generation 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 order 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 is c,n The size of the harmonic suppression module is optimized to control the output of the nth L298N module to obtain 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 binary PWM signal b of the i-th servo 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 in common; 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 multiple PCA9685 modules. Connect 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 through different wires. Then, follow this pin connection rule to complete the cascade connection between the second PCA9685 module and the last PCA9685 module and the Arduino Uno module.
[0065] Furthermore, 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 channels corresponding to the PCA9685 connected to it, which is used 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. The IN1 pin, IN2 pin, IN3 pin and IN4 pin of each L298N module are respectively connected to the corresponding four channels to receive the calculated k-th optimal harmonic switching angle of the n-th L298N module connected to each PCA9685 module to control the i-th servo after optimization, which is written into the PCA9685 module register 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, thereby receiving 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 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 for the output to the i-th servo is used. The output voltage amplitude is dynamically adjusted according to the number of switching cycles and the changes in 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 dynamically adjusted in real time to maintain the stability of the output signal and output voltage. The harmonic switching angle of the overmodulated signal is then passed through steps S32-S36 to selectively eliminate specific harmonic components (3rd, 5th, 7th, 9th order, and other high-order harmonics), significantly reducing the amplitude of low-order harmonics and reducing the transmission of useless harmonic energy. More energy is concentrated on the fundamental frequency, thereby improving the harmonic distortion (THD) of the output signal. Ultimately, the precise elimination of specific-order harmonics is achieved, improving the quality of the output waveform and making the signal closer to an 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 combining the adjustment of the optimal positive and negative voltages, significantly improving the efficiency, stability and flexibility of the servo system. At the same time, it 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, it can control the servo to output a low-level voltage of 0 when it is stopped, effectively reducing the energy consumption in standby mode. By 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, extends the service life of the driver 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 the servo control method based on the PCA9685 module provided by the present invention;
[0074] Figure 2 Schematic diagram of the soldering 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 Bessel coefficient variation over time for the first servo in a switching cycle of a=0-10 according to an embodiment of the present invention;
[0077] Figure 5 Schematic diagram showing the effect of the method of the present invention on odd harmonics within the 9th order harmonic and the switching angle on the rectangular fundamental waveform;
[0078] Figure 6 Schematic diagram of the change of the optimal harmonic switching angle with the output voltage after optimization using the method of the present invention and the traditional CNN method;
[0079] Figure 7Schematic diagram of the output voltage change over time after optimization using the method of the present invention and the traditional CNN method, as well as the Fourier analysis results;
[0080] Figure 8 The THD of 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 varies with the output voltage V out Schematic diagram of the changes;
[0081] Figure 9 This is a schematic diagram of the structure of the steering gear control system based on the PCA9685 module provided by the present invention;
[0082] Figure 10 Schematic diagram of the Arduino Uno module structure in an embodiment of the present invention;
[0083] Figure 11 Schematic diagram of the PCA9685 module structure in an embodiment of the present invention;
[0084] Figure 12 Schematic diagram of the PCA9685 module circuit in an embodiment of the present invention;
[0085] Figure 13 Schematic diagram of the L298N module structure in an embodiment of the present invention;
[0086] Figure 14 Schematic diagram of the L298N module circuit in an embodiment of the present invention;
[0087] Figure 15 Schematic diagram of a dual H-bridge circuit including eight IGBT switches in an L298N module according to an embodiment of the present invention;
[0088] Figure 16 is the voltage u of the reference signal in the embodiment of the present invention r,n During the positive and negative half cycles, the L298N module receives the on / off status of the first and second servos connected to it, as well as the forward and reverse output high-level voltage;
[0089] Figure 17 This is a pin connection diagram of an Arduino Uno module and multiple PCA9685 modules cascaded in an embodiment of the present invention;
[0090] Figure 18 This is a pin connection diagram for using an Arduino Uno master PCA9685 module connected to an L298N module to control the motion of two servos under the first power supply mode in an embodiment of the present invention;
[0091] Figure 19This is a pin connection diagram for using an Arduino Uno master 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 clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. 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 making creative efforts are within the scope of protection of the present invention.
[0093] like Figure 1 FIG. 1 is a flow chart of a servo control method based on a PCA9685 module provided by the present invention. The method of the present invention uses the PCA9685 module to uniformly control multiple servos, and controls the switching time and duty cycle of each servo based on a program written into the PCA9685 module register by the main control module, thereby achieving the effect of regulating different servos to start or stop movement when needed. The method includes the following steps:
[0094] S1: I of the main control module 2 C pin and multiple PCA9685 modules 2 The C interface is used to configure the serial address to realize cascade connection, receive control instructions or upload real-time monitoring data;
[0095] S2: Calculate the duty cycle of the PWM signal that controls each servo based on the target rotation angle of that 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 the model 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 order 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 moment.
[0098] The present invention uses the main control module and the PCA9685 module I 2 The cascade connection is achieved through a C interface, which uniformly generates PWM signals, ensuring the synchronous control of multiple servos and reducing signal transmission delays and errors. This enables precise and synchronous control of the movements of multiple servos, thereby overcoming the existing problem of multiple servo control relying on independent signal generators or single-chip microcontroller GPIO pins, which often suffers from poor synchronization and significant signal interference. Furthermore, the present invention utilizes the duty cycle calculation model of the built-in registers of the PCA9685 module to quickly generate accurate PWM signals, avoiding the reliance on independent hardware circuits or software simulations for PWM signal duty cycle adjustment, which can lead to slow response and high computational complexity. This significantly improves the precision and response speed of servo control.
[0099] The present invention connects a main control module to multiple PCA9685 modules. Each PCA9685 module is connected to an L298N module for every four channels. Consequently, one PCA9685 module can be connected to four L298N modules. 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. This solves the problem of insufficient flexibility caused by limited expansion in traditional control schemes. By combining positive and negative high-level outputs with optimal harmonic switching angles through each L298N module, the present invention significantly optimizes the forward and reverse control effect of the servo, ensuring the reliability and stability of the control.
[0100] In order to realize the transmission of control instructions and PWM signals between 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 I2C values 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 I2C pins A0, A1, A2, A3, A4 and A5 of the nth PCA9685 module 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 pins 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, which represents the initial default state of the PCA9685 module's A0-A5 pin jumpers, which are not soldered together;
[0104] S13: The main control module calculates the I 2 C hexadecimal address to transmit the corresponding control instructions to each PCA9685 module.
[0105] Default is the default I of PCA9685 2 The address configuration mode of C address is 0x40 (hexadecimal). The available address range is 0x40. The address configuration of the serial PCA9685 modules is set at the hardware module level by connecting jumpers with solder. Figure 2 As shown, for each Figure 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 wire 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 all physically disconnected and the jumper wire 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 , based on which the high-level pulse width T in the PWM control cycle is calculated on,ni ; γ ni The target rotation angle of the i-th servo controlled by the n-th L298N module connected to each PCA9865 module;
[0109] S22: Further calculation of the rotation angle to be achieved is γ ni The duty cycle D of the PWM control cycle ni :
[0110]
[0111] Among them, such as 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 The switching pulse width of the i-th servo controlled by the n-th L298N module is: where i = 1 or 2, and 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 MOSFET path controlling each servo is complementary, that is, the duty cycle of transistor paths 1 and 4 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 , build a 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 i-th servo controlled by the n-th 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. Within the total pulse width of a PWM signal control cycle, there will be a switching cycle, that is, within a PWM signal control cycle T (20ms), there are a switching pulse width T ni . D ni Let D be the duty cycle of the PWM signal of the i-th servo controlled by the n-th L298N module. 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 within a switching cycle.
[0115] The pins on the PCA9685 module that control the servo's rotation angle, and thus the duty cycle, are PWM output pins 0 to 15. The PCA9685 modifies the angle within each switching cycle by dividing the switching cycle into 4096 parts. The "on" value is the PWM rising count value, which ranges from 0 to 4096. The "off" value is the PWM falling count value, which also ranges from 0 to 4096. The pin counts from 0 to 1, transitioning high when it reaches the "on" value and low when it reaches the "off" value, until the count reaches 4096 and the next switching cycle begins. Therefore, when the "on" value is not 0, a delay can be applied. When "on" is 0, the "off" value / 4096 is the PWM duty cycle.
[0116] Therefore, step S21 includes:
[0117] S211: Set 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 degree of rotation based on different servo types: E = Count / γ max ; Among them, γ max The maximum angle that can be achieved by different servo types; 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 initial on value corresponds to a rotation angle of 0 degrees, t on,ni=102.4; T on,ni =[(γ ni ×E) / 4096]×20;
[0121] S214: Obtaining 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 The binary PWM signal at time t controls the ith servo to be turned off; off,ni At this 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. on,ni During the time duration, 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 achieve 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, V is the kth harmonic switching angle of the i-th servo controlled by the n-th L298N module; d Provides power voltage to the nth L298N module through 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 The calculation formula of (t) fully considers the switching angle of the k-order harmonic And the impact of a switching cycle and b positive and negative high-level voltages on the output cycle of the voltage Vd applied to both ends of the nth L298N module in a PWM signal adjustment cycle. 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 the 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 harmonic amplitudes can be adjusted in real time to maintain signal stability when the load changes.
[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 frequencies are integer multiples of the fundamental frequency of the PWM control signal output by the PCA9685 module. Although the servo's inductance, resistance, and different target rotation angles (duty cycles) affect the amplitude characteristics of the harmonics, they do not change the harmonic frequency. In the PWM control signal output by the PCA9685 module, even harmonics are self-suppressed and canceled in the symmetrical bipolar PWM waveform generated by the dual H-bridge bipolar conduction control of the same L298N module. Therefore, external control is not required to eliminate them. Therefore, it is the odd harmonics (3, 5, 7, ... 2k+1) that need to be eliminated.
[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, 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 the third-order, fifth-order, seventh-order and ninth-order odd harmonic component voltage amplitudes v3, v5, v7 and v9, respectively. Figure 5 The purple rectangular staircase line diagram in the second row is the voltage v9 of the odd harmonic component of the 9th order 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 order harmonic switching angle to the 9th order harmonic switching angle and Generated 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 order harmonic in the positive half cycle of one switching cycle relative to 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 Generated 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 relative to 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 third 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 The 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 The 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-th 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}, 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; therefore, are the dth generation solutions of the gth order harmonic switching angle of the i-th servo controlled by the nth L298N module;
[0147] S34: Simplified to matrix form:
[0148] is the k×k element Jacobian matrix of the first nonlinear system of equations, J hg,n1 for The gth harmonic switching 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: Based on 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 and the total harmonic distortion THD of the second servo n2 :
[0153]
[0154]
[0155] Determine the total harmonic distortion THD of the first servo n1 and the 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 i-th servo controlled by the n-th L298N module. i=1,2; otherwise, repeat steps S31-S35 until the total harmonic distortion TGD of the first servo is n1 and the total harmonic distortion TGD of the second servo n2 When all values are less than 0.35, the kth-order optimal harmonic switching angle of the i-th servo controlled by the n-th L298N module is output.
[0156] In order to verify the method of the present invention through steps S31-S36, the k-th harmonic switching angle of the i-th servo controlled by the n-th L298N module is The optimization effect of the traditional CNN method is to calculate the kth harmonic switching angle of the i-th servo controlled by the n-th L298N module. Optimize. Figure 6 As shown, the output voltage V of the i-th servo is calculated by the traditional CNN method and the method of this application. out =5V~6V, the kth order 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) shows 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 Fourier analysis results of the corresponding output voltage optimized by the traditional CNN method, Figure 7 (d) for Figure 7(b) The corresponding Fourier analysis results 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) shows the k-th order harmonic switching angle obtained by the optimization of the present invention. Return to step S31 to calculate the final output voltage V for the i-th servo. 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 and 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, as Figure 8 As shown, with the output voltage V out As the output voltage continues to rise, the total harmonic distortion THD of the output voltage after optimization by the method of the present invention and the traditional CNN method are both reduced. However, 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 after optimization by the traditional method.
[0160] Therefore, after optimizing the k-th harmonic switching angle of the i-th servo controlled by the n-th L298N module using the method provided by the present invention and then bringing it into step S31 to solve the problem, the total harmonic distortion of the output voltage can be reduced to less than 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, thereby accurately controlling the servo to rotate to the desired angle and avoiding the occurrence of control deviation.
[0161] The method of the present invention comprises steps S31-S36, firstly constructing a Bessel coefficient in step S31. The voltage calculation formula for the output to the i-th servo is used. The output voltage amplitude is dynamically adjusted according to the number of switching cycles and the changes in 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 dynamically adjusted in real time to maintain the stability of the output signal and output voltage. The harmonic switching angle of the overmodulated signal is then passed through steps S32-S36 to selectively eliminate specific harmonic components (3rd, 5th, 7th, 9th order, and other high-order harmonics), significantly reducing the amplitude of low-order harmonics and reducing the transmission of useless harmonic energy. More energy is concentrated on the fundamental frequency, thereby improving the harmonic distortion (THD) of the output signal. Ultimately, the precise elimination of specific-order harmonics is achieved, improving the quality of the output waveform and making the signal closer to an 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 、 Figure 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 (the second IGBT switch and the fourth IGBT switch of the i-th servo are controlled to be turned off at this time), and at u r,n In the positive half cycle, the output is the optimal positive high level voltage +V 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 is a low level voltage of 0;
[0163] when|u r,n |<|u c,n |, the second IGBT switch and the fourth IGBT switch 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). r,n In the positive half cycle, the output voltage is low level 0; in u r,n During 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 Synchronous regulation optimizes the harmonic characteristics of the servo while reducing electromagnetic interference (EMI) caused by higher harmonics, improving system stability. 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. Different servos and load conditions can be adjusted by adjusting u r,n and u c,n The absolute value of is compared to realize opening or stopping, and the forward and reverse rotation during the opening process reaches the desired angle γ ni , achieving higher control flexibility, suitable for servo control in 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 |, switches to a low-level voltage of 0, effectively protecting the servo in a stopped state, 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 Figure 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 for the desired steering angle, a binary PWM signal calculation module, a sinusoidal reference wave signal r(t) generation module, and a harmonic suppression module;
[0169] Main control module, used to 2 C pin and multiple PCA9685 modules 2 The C interface is used to configure the serial address to realize cascade connection, receive control instructions or upload real-time monitoring data;
[0170] The duty cycle calculation module corresponding to the desired servo angle is used to execute steps S21-S22 to calculate the duty cycle of the PWM signal for controlling each servo according to the target rotation angle of each servo;
[0171] The binary PWM signal calculation module is used to build a binary PWM signal calculation model for the nth L298N module connected to each PCA9865 module to modulate the i-th servo, write the model into the register of the PCA9685 module, and adjust the program to update the binary PWM signal;
[0172] The sine wave reference signal r(t) generation module is used to generate the sine wave 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 servo angle. 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 order 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 the 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 the nth L298N module is used to compare the sinusoidal reference wave signal r(t) generated by the module and written into the PCA9685 module register. 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 servo angle. ni The nth L298N module modulates the binary PWM signal b of the i-th servoPWM,ni (t), forward or reverse to the desired angle γ ni .
[0176] The main control module is controlled by I 2 The C interface communicates with the PCA9685 module. The duty cycle calculation module, which corresponds to the desired servo angle, executes steps S211-S214 to configure the on and off values for each of the PCA9685's 16 channels. The PCA9685's internal hardware timer generates a PWM signal with a fixed frequency of 50Hz based on the configuration, meaning each switching period is 20ms.
[0177] like Figure 10 As shown, the Arduino Uno module provided by the present invention as the 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 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 through the Vin pin on the left to the +5V voltage required for internal logic operation. The USB interface can be used to connect an external +5V power supply or input a control command signal. The reset button is used to reset the internal logic to the initial state.
[0178] The Arduino Uno module also includes a 16MHz crystal oscillator, a USB-to-serial converter chip, a serial communication indicator, a D13 pin signal indicator, an ATmega328P microcontroller, an ICSP pin, a power indicator, and, on the left side, the IOREF pin (which provides a logic-level reference voltage (typically 5V) for external expansion board detection and adaptation), a RESET pin (for receiving external reset control commands), a +3.3V output pin, a +5V output pin, two GND pins, a Vin pin, and pins A0-A5, which are the input pins for an external DC power supply. When using an external power source (such as a battery or power adapter) to power the development board, this pin should be connected to the positive terminal of the power supply. When the Vin pin receives voltage, it overrides the power provided by the USB or other pins and powers the development board. The Vin pin can be connected to an external +5V power supply or a +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's ADC (Analog-to-Digital Converter) to improve the measurement accuracy of analog inputs or meet specific measurement requirements. The ICSP pin allows users to program or debug the microcontroller directly 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 servo desired angle corresponding duty cycle calculation module, binary PWM signal calculation module, sinusoidal reference wave signal r(t) generation module, and harmonic suppression module in the system claimed by the present invention are all located within this microcontroller.
[0179] Pins A0-A5 are used to read external analog signals. Analog signals are continuously changing signals that can represent a variety of physical quantities, such as temperature, pressure, and light intensity. The Arduino reads these analog signals through these pins and converts them into digital values for use in 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, as well as the SDA pin and SCL pin 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 or low) of external devices, or as output pins to control the on / off state of external devices.
[0181] Pin 13 is connected to an onboard LED indicator. Users can programmatically control the state of this pin, thereby turning the LED on and off, helping users understand the execution status of the code.
[0182] Pins 3, 5, 6, 9, and 10 are all PWM pins, supporting PWM (pulse-width modulation) functionality. Users can programmatically control the voltages on these pins for finer control, such as adjusting the speed of a motor or the brightness of an LED. They can also function as digital input / output pins. Pins 0, 1, 2, 7, 8, and 12 only have digital input / output functionality and lack PWM. Pin 1 is labeled TX (transmit) and pin 0 is labeled RX (receive). These two pins are used to send and receive signals during serial communication. In Arduino programming, users can use these pins to exchange data with a computer or other device.
[0183] like Figure 11 As shown, it is a horizontal schematic diagram of the PCA9685 module provided by the present invention, including the Vin pin and GND pin on the green terminal block 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 poles of the external power supply need to be connected through the Vin pin and the GND pin respectively; it also includes the GND pin, OE enable port, SCL pin, and SDA pin arranged from top to bottom on its left side. , VCC pin and V+ pin. The above six pins are also correspondingly set on the right side of the board. There are 16 PWM output pins arranged from left to right on the bottom 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 state). The SCL pin and SDA pin are the clock signal pin and data signal pin of the I2C bus respectively, and 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 address pads of the C address are connected by soldering to configure the address of the module. The PCA9685 module also includes a PWM central core chip located below the green terminal block, which is located in the center of the board. 2The C communication module receives commands from the main control module, the Arduino Uno, and outputs corresponding binary PWM signals for controlling the servo. 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 located within it.
[0185] like Figure 12 The following figure shows the circuit diagram of the PCA9685 module. The U1 in the middle is the PCA9685 module board. The VDD pin on the upper right is the chip power input pin connected to the 5V power supply. The SDA pin and SCL pin are connected to the Figure 11 The corresponding I 2 C bus data line and clock line, OE pin is Figure 11 The corresponding OE enable pin outputs the enable signal. When OE is pulled low, the PWM signal output is valid. Figure 11 The green terminal block in the figure corresponds to the GND pin, and the A0-A5 pins on the lower right are Figure 11 The corresponding A0-A5 pins are Figure 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 R3 current limiting resistor to ground. 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 Figure 11 Channels 0-15 in the circuit 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 Figure 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 Figure 13 The figure shows a top view of the L298N module used in the system of the present invention, including an onboard heat sink at the top, the fifth diode D5, the first diode D1, the second diode D2, and the sixth diode D6 from top to bottom on the upper left side, and the eighth diode D8, the fourth diode D4, the third diode D3, and the seventh diode D7 on the right side. The figure 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 pins OUT1 and OUT2, and the second blue output module includes pins OUT3 and OUT4. Two capacitors (220μF, 35V specification) are located between the first and second blue output modules, a MOS tube (for user-controlled H-bridge switch control), and an onboard 5V enable (jumper cap). The two capacitors are used to filter and stabilize the power supply voltage to reduce power supply voltage instability caused by power supply signal noise. The onboard 5V enable is connected by default. The module's internal voltage regulator converts +12V to 5V for the logic circuitry and outputs it through the +5V pin. If using an external 5V power supply, remove this jumper to avoid power conflicts. The L298N module also includes a blue power terminal at the bottom, which includes a +12V pin, a GND pin, and a +5V pin. To the left of the blue power terminal are the ENA enable pin, IN1, IN2, IN3, IN4, and ENB enable pins. The ENA and ENB enable pins receive binary PWM signals, which control the duty cycle of the first and second servos, respectively. IN1-IN2 control the high and low voltage combinations of the two coils of the first servo, while IN3-IN4 control the high and low voltage combinations of the two coils of the second servo, respectively controlling the forward, reverse, and stop of the two motors.
[0187] like Figure 14As shown in the figure, 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, where IN1, IN2, IN3 and IN4 (pin numbers 1, 2, 3 and 4 respectively) are connected to the control terminal P1, which are used to control the status of OUT1-OUT4 respectively. The status of OUT1 (pin number 9) and OUT2 (pin number 10) reflects the direction of the first servo (Motor A) connected to the L298N module, and the status of OUT3 (pin number 11) and OUT4 (pin number 12) reflects the direction of the second servo (Motor B) connected to the L298N module. ENA (pin number 5) and ENB (pin number 6) are respectively connected to the P1 control terminal. This application is in Figure 17 、 Figure 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 rotate to the desired angle γ. ni The high level voltage causes the motor to rotate. Figure 14 The VSS pin (pin number 7) in the MCU is connected to a +5V external power supply to power the internal logic operation, the VS pin (pin number 8) powers 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 is further connected to the first servo ( Figure 14 OUT2 is connected to the cathode of the second servo motor through the A+ lead after connecting the second diode D2 and the fifth diode D5; OUT3 is connected to the anode of the second servo motor through the B+ lead after connecting the third diode D3 and the eighth diode D8; OUT4 is connected to the cathode of the second servo motor through the B- lead after connecting the fourth diode D4 and the seventh diode D7.
[0189] A first light-emitting diode L1 and a second light-emitting diode L2 are also connected in parallel between OUT1 and OUT2 and the A- lead and A+ lead connected to the positive and negative poles of the first servo. They 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 lights up. When the first servo rotates reversely, only the second light-emitting diode L2 lights up.
[0190] A third light-emitting diode L3 and a fourth light-emitting diode L4 are also connected in parallel between OUT3 and OUT4 and the B+ lead and B- lead connected to the positive and negative poles of the second servo. They 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 lights up. When the second servo rotates reversely, only the fourth light-emitting diode L4 lights up.
[0191] like Figure 15 As shown, the specific double H-bridge drive circuit diagram of the largest yellow module in the center of the L298N module ( Figure 14 The largest yellow module in the image is rotated 90 degrees to the left and Figure 15 (corresponding to the driving circuit diagram shown in the figure).
[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 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. Connect 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 through the black wire, sky blue wire, light yellow wire, dark green wire, dark red wire, and peach pink wire respectively. Then, follow this pin connection rule to complete the cascade connection between the second PCA9685 module and the last PCA9685 module and the Arduino Uno module.
[0193] Furthermore, 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 channels corresponding to the PCA9685 connected to it, which is used 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. The IN1 pin, IN2 pin, IN3 pin and IN4 pin of each L298N module are respectively connected to the corresponding four channels to receive the calculated k-th optimal harmonic switching angle of the n-th L298N module connected to each PCA9685 module to control the i-th servo after optimization, which is written into the PCA9685 module register by the Arduino Uno module. The corresponding high-level voltage V for the i-th servo ni,best (t); The ENA enable pin and ENB enable pin of each L298N module are connected to the digital pin 11 and digital pin 3 of the Arduino Uno module respectively, thereby receiving the intermittent start control command 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 and OUT2 pins of each L298N module are connected to the first and second coils of the first servo, respectively. The OUT3 and OUT4 pins of each L298N module are connected to the first and second coils of the second servo, respectively.
[0196] like Figure 18As shown, the main control module Arduino Uno module, PCA9685 module, L298N module and each L298N module are connected to the positive and negative poles 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 intermittently are respectively connected to the positive pole of the external power supply through dark red wires, introducing power for the internal logic operations of each module and ultimately for the forward and reverse movement of the two servos controlled by each L298N module. 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 it through the Vin pin of the Arduino Uno module, the Arduino The Uno module uses an internal AMS1117-5.0 voltage regulator to step down the voltage to a +5V voltage suitable for the power required for the internal logic operation of itself and the PCA9685 and L298N modules 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 ground via black wires. At the same time, the two servos controlled by each L298N module are also connected to ground. In this case, the number of PCA9685 modules suitable for cascading Arduino Uno modules is small, and the voltage required for the forward and reverse movement of the servos is +5V. In this case, the total number of servos controlled by the main control module Arduino Uno module is small, so the +5V voltage of the external power supply is sufficient to power 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. Similarly, 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 wire colors and connection method for the ENA enable pin, ENB enable pin, IN1-IN4 enable pin, PCA9685 module, and Arduino Uno module from the second to fourth L298N modules are the same as those for 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 communication 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 of each PCA9685 module connected to it, and then implement steps S11-S13 to complete the Arduino Uno module based on 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 via a light yellow wire. This wire is used to write the sinusoidal reference signal r(t) generated by the sinusoidal reference signal r(t) generation module into the PCA9685 module. This provides the comparator module within 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. This allows the intermittent start control command for the i-th servo connected to the n-th L298N module to be generated.
[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 within 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. During the intermittent opening process 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 is controlled to meet the duty cycle required by the desired angle and meet the k-th optimal harmonic switching angle after the harmonic suppression module suppresses the harmonics. Output voltage value |V ni,best (t)|;
[0200] Pins 5, 6, 9, and 10 of the Arduino Uno module are connected to the yellow pins of channels 0-3 of the PCA9685 module through brown leads, rose-red leads, light blue leads, and purple leads, respectively. At the same time, the yellow pins of channels 0-3 of the PCA9685 module are further connected to the IN1 pin, IN2 pin, IN3 pin, and IN4 pin of the nth L298N module through brown leads, rose-red leads, light blue leads, and purple leads, respectively. Then, the Arduino Uno module executes the S31-S36 steps calculated by the harmonic suppression module set therein to obtain 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. The binary PWM signal calculated by the binary PWM signal calculation module is also written into the PCA9685 module by pins 5, 6, 9, and 10 of the Arduino Uno module. Based on the comparison results of the comparator module of the PCA9685 module, the yellow pins of channels 0-3 of the PCA9685 module control the instructions according to the comparison results of the comparator module. In the positive and negative half-cycles of the r(t) signal, the duty cycle of the desired angle is adjusted according to the ENA and ENB enable terminals to meet the desired angle. 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 servo angle. ni The nth L298N module modulates the binary PWM signal b of the i-th servo 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 Figure 14 、 Figure 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 opening and closing of the first servo. 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 Figure 13 、 Figure 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 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 respectively. 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 connected and turned on or off respectively. 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) during the positive and negative half-cycles with the carrier signal c(t), as well as the conduction conditions of each IGBT switch and each diode (also used as a freewheeling tube) and the positive and negative output voltages of the two servos connected to OUT1-OUT4 are shown as follows: Figure 16 shown.
[0204] like Figure 19 The second power supply method is shown in the figure. 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: Figure 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 is connected to the Vin+ pin on the upper part of each PCA9685 module connected to the Arduino Uno module, as shown in the figure. Figure 19 As shown, the positive and negative poles of the external power supply are connected to the V+ and GND pins on the top of the PCA9685 module via the second dark red lead and the second black lead, respectively. The second dark red lead is connected to the +12V pin of the L298N module, thereby providing the power supply voltage required for the two servos connected to the nth L298N module. 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 connections are the same as in the first power supply method above. When using the second power supply method with two external power supplies, 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 to it. 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 requires as many second external power supplies as there are L298N modules connected to it, thereby ensuring the external +12V voltage supply required for the forward and reverse operation of the two servos controlled by each L298N module, and avoiding the situation where a second external power supply connected to the V+ pin of the PCA9685 module is insufficient to simultaneously supply the power required for the forward and reverse operation of the four L298N modules and eight servos connected to the PCA9685 module. Figure 18 and Figure 19 The L298N module in the Figure 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 equivalents may be substituted for the technical features herein 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 servo control method based on the PCA9685 module. The method uses the PCA9685 module to uniformly control multiple servos. The method controls the on / off time and duty cycle of each servo based on a program written into the PCA9685 module register by a main control module, thereby achieving the effect of regulating different servos to start or stop movement when needed. The method is characterized by: The following steps are involved: S1: I of the main control module 2 C pin and multiple PCA9685 modules 2 The C interface is used to configure the serial address to realize cascade connection, receive control instructions or upload real-time monitoring data; S2: Calculate the duty cycle of the PWM signal that controls each servo based on the target rotation angle of that 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 the model into the register of the PCA9685 module and adjust the program to update the binary PWM signal. S3: The duty cycle of each servo obtained according to step S2 Calculate the high level voltage of the nth L298N module connected to each PCA9865 module to the i-th servo , optimize the kth order optimal harmonic switching angle of the nth L298N module connected to each PCA9865 module to control the i-th servo ; S4: Compare the reference signal for controlling the nth L298N module written into the PCA9685 module register by the main control module Voltage And the internal carrier signal set in the PCA9685 module to control the nth L298N module Voltage , by comparing the reference signal Voltage and internal carrier signal Voltage , 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 turning on , and when it is turned on, the output has the kth order optimal harmonic switching angle Optimal positive and negative high-level voltage , and the output voltage value is 0 at the closing time; The S3 step includes: S31: Calculate the high level voltage output by the nth L298N module to control the first servo The nth L298N module controls the high level voltage output by the second servo ; S32: constructing a first nonlinear equation group of k zero-amplitude odd-harmonic components of harmonic switching angles, and constructing a second nonlinear equation group of k zero-amplitude odd-harmonic components of harmonic switching angles; S33: Expand the nonlinear equations in the first nonlinear equation group and the nonlinear equations in the second nonlinear equation group at the corresponding current solutions; S34: simplifying the nonlinear equations in the first nonlinear equation group and the nonlinear equations in the second nonlinear equation group into matrix forms respectively; S35: further iteratively solving the next generation of solutions of the first nonlinear equation group and the second nonlinear equation group according to the matrix form obtained in step S34; S36: Calculate the total harmonic distortion of the first servo controlled by the nth L298N module and the total harmonic distortion of the second servo , judge the total harmonic distortion of the first servo and the total harmonic distortion of the second servo Are they all less than 0.35? If so, stop the iteration and output the optimal k-th harmonic switching angle of the i-th servo controlled by the n-th L298N module. ;i=1,2.
2. The steering gear control method based on the PCA9685 module according to claim 1, characterized in that: In the S1 step, multiple PCA9685 modules are connected via I 2 C interface and the main control module's I 2 C pin cascade connection, including: S11: Obtain the I2C values 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 ;in, 、 、 、 、 and I2C pins A0, A1, A2, A3, A4 and A5 of the nth PCA9685 module 2 C binary value; 、 、 、 、 and The values of are all 0 or 1; S12: According to the obtained A0-A5 pins 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 ; Among them, 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, characterized in that: The S2 step includes the following steps: S21: Determine the rotation angle that each servo needs to reach , based on which the high-level pulse width within the PWM control cycle is calculated ; The target rotation angle of the i-th servo controlled by the n-th L298N module connected to each PCA9865 module; S22: Further calculate the rotation angle to be achieved The duty cycle of the PWM control cycle : ; in, 、 They are respectively the high level pulse width and low level pulse width in one switching cycle. , The switching pulse width of the i-th servo controlled by the n-th L298N module; where i = 1 or 2, n = 1, 2, ... N; and N is the total number of L298N modules connected to each PCA9685 module. S23: Duty cycle obtained according to step S22 , build a 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,…; is the initial phase angle of the i-th servo controlled by the n-th L298N module, , ; is the control frequency of the PWM signal, =50Hz; the total pulse width T of a PWM signal control cycle is 20ms; ,but , The duty cycle of the first servo controlled by the nth L298N module within 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: Settings =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 degree of rotation based on different servo types: E = Count / γ max ; Among them, γ max The maximum angle that can be achieved by different servo types; servo types include γ max =90°, γ max =180°, γ max = 270° or γ max = any one or more of 360°; S213: Rotate according to target angle , calculate the total PWM count value required to achieve it, which is the end time of the high-level pulse width in a switching cycle : ; ; When the rotation angle corresponding to the initial on value is 0 degrees, =102.4; ; S214: Obtaining the corresponding target angle within a switching cycle Off value , ; is the target angle corresponding to one switching cycle The on value is the moment when the binary PWM signal controls the start of the i-th servo; the off value is 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: In the step S31, the high level voltage output by the nth L298N module to control the first servo is calculated respectively. The nth L298N module controls the high level voltage output by the second servo The formula is as follows: ; ; in, is the kth harmonic switching angle of the i-th servo controlled by the n-th L298N module; b is the total number of high-level voltage outputs in one switching cycle; Provides power voltage to the nth L298N module through 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; ; The first nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components constructed in step S32 is as follows: ; 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; for The 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; The second nonlinear equation group of zero amplitude of k harmonic switching angle odd harmonic components constructed in step S32 is as follows: ; 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; for The abbreviation of is the voltage amplitude of the p-th order odd harmonic component generated by the p-th order harmonic switching angle; In the step S33, the nonlinear equations in the first nonlinear equation group are expanded by Taylor. , the nonlinear equation in the second nonlinear equation group In the corresponding current d-th generation solution The following is expanded: ; ; in, , 、 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-1th and dth generation solutions of the gth order harmonic switching angle of the ith servo controlled by the nth L298N module; The S34 step is simplified into matrix form as follows: ; 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, ; In step S35, the matrix form obtained in step S34 is further iterated to solve the first nonlinear equation group and the second nonlinear equation group to obtain the d+1th generation solution: ; ; In the step S36, the total harmonic distortion of the first servo controlled by the nth L298N module is calculated respectively. and the total harmonic distortion of the second servo The formula is as follows: ; ; If the result of the judgment in step S36 is that the total harmonic distortion of the first servo is and the total harmonic distortion of the second servo If the total harmonic distortion of the first servo is less than 0.35, repeat the steps S31-S35 until the total harmonic distortion of the first servo is less than 0.
35. and the total harmonic distortion of the second servo When all values are less than 0.35, the kth-order optimal harmonic switching angle of the i-th servo controlled by the n-th L298N module is output. .
6. The steering gear control method based on the PCA9685 module according to claim 1, characterized in that: In step S4, the reference signal voltage is compared and the internal triangular carrier signal voltage , 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 it is turned on The rule is: when When the first IGBT switch and the third IGBT switch of the i-th servo are turned on, In the positive half cycle, the optimal positive high level voltage is output , so that the i-th servo rotates forward to the desired angle ;exist In the negative half cycle, the output is a low level voltage of 0; when When the second IGBT switch and the fourth IGBT of the i-th servo are turned on, In the positive half cycle, the output voltage is low level 0; In the negative half cycle, the optimal negative high level voltage is output , so that the i-th servo is reversed to the desired angle .
7. A steering gear control system based on a PCA9685 module that executes the method according to 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 sine reference wave signal Generation module, harmonic suppression module; The main control module is used to 2 C pin and multiple PCA9685 modules 2 The C interface is used to configure the serial address to realize cascade connection, receive control instructions or upload real-time monitoring data; 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; 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, write the model into the register of the PCA9685 module, and adjust the program to update the binary PWM signal; The sinusoidal reference wave signal Generation module for generating sine wave reference signals , and write it into the PCA9685 module register; The harmonic suppression module is used to calculate the duty cycle of each servo according to the duty cycle calculation module corresponding to the desired angle of the servo. Calculate the high level voltage of the nth L298N module connected to each PCA9865 module to the i-th servo , optimize the kth order 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 Generation module, comparator module, PWM modulation signal output module; the internal triangular carrier signal Generation module for generating triangular carrier signals ; The PWM modulation signal output module is used to compare the sine reference wave signal with the comparator module. Generate a sine wave reference signal generated by the module Voltage With the triangular carrier signal The triangular carrier signal generated by the generation module Voltage The size of the harmonic suppression module is optimized to control the output of the nth L298N module to obtain the kth optimal harmonic switching angle. Optimal positive and negative high-level voltage , whether the i-th servo is turned on or not, and after it is turned on, the duty cycle of the i-th servo calculated by the duty cycle calculation module corresponding to the desired angle of the servo The nth L298N module modulates the binary PWM signal of the i-th servo , forward or reverse to the desired angle .
8. The steering gear control system based on the PCA9685 module according to claim 7, 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 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 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 pole of the external power supply are grounded in common; 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. Connect 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 through different wires. Then, follow this pin connection rule to complete the cascade connection between the second PCA9685 module and the last PCA9685 module and the Arduino Uno module.
9. The steering gear control system based on the PCA9685 module according to claim 8, 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 channels corresponding to the PCA9685 connected to it, which is used 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. The IN1 pin, IN2 pin, IN3 pin and IN4 pin of each L298N module are respectively connected to the corresponding four channels to receive the calculated k-th optimal harmonic switching angle of the n-th L298N module connected to each PCA9685 module to control the i-th servo after optimization, which is written into the PCA9685 module register by the Arduino Uno module. The corresponding high-level voltage for the i-th servo The ENA enable pin and ENB enable pin of each L298N module are connected to the digital pin 11 and digital pin 3 of the Arduino Uno module respectively, thereby receiving the intermittent start control command 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) and the carrier signal c(t) output by the PWM modulation signal output module in the PCA9685 module; 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 servo.
Citation Information
Patent Citations
Steering engine motion control method and device, and computer-readable storage medium
CN109696910A
Method and system for controlling steering engine and robot
CN111376245A
Steering gear control system and method based on fuzzy neural PID control and absolute encoder
CN108196442A
Steering engine control method
CN112650112A