High-precision clock synchronization method and device based on EtherCAT network, electronic equipment and storage medium

Through the combination of Kalman filter and fuzzy logic controller, PID control parameters are dynamically adjusted, which solves the problem of insufficient EtherCAT clock synchronization accuracy and clock drift, achieves high-precision and flexible clock synchronization, and adapts to the needs of industrial automation systems.

CN118573318APending Publication Date: 2024-08-30SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN +3
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202410690728.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing EtherCAT clock synchronization methods have shortcomings in improving synchronization accuracy and reducing clock drift, and cannot meet the needs of high-precision and highly dynamic environments, especially when network conditions change. Performance and accuracy may be affected.

Method used

The Kalman filter is used to dynamically predict and estimate the clock offset and drift of the slave station equipment, and the PID control parameters are adjusted through the fuzzy logic controller to optimize the clock synchronization strategy in real time to ensure clock synchronization between the slave station and the master station.

Benefits of technology

Significantly improving synchronization accuracy and system response speed, it can identify and adapt to small changes and occasional deviations in clock frequency, maintain efficient and precise synchronization, and is suitable for various industrial environments and application needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118573318A
    Figure CN118573318A
Patent Text Reader

Abstract

The invention belongs to the technical field of industrial control, and particularly relates to a high-precision clock synchronization method and device based on an EtherCAT network, electronic equipment and a storage medium. The method comprises the following steps: selecting a slave station as a reference clock slave station, and acquiring local clock skews between other slave stations and the reference clock slave station and local clock drifts of other slave stations; acquiring initial state vectors and initial error covariances of other slave stations according to the local clock offset and the local clock drift, inputting the initial state vectors and the initial error covariances into a Kalman filter, calculating state estimation values and error covariance estimation values of the other slave stations at the current moment, and inputting the two estimation values into a fuzzy logic controller; obtaining a fuzzy reasoning result of the adjustment value of the PID control parameter, and defuzzifying to obtain a target adjustment value; and inputting the target adjustment value into the PID controller to enable the PID controller to output a control signal, and adjusting local clocks of other slave stations based on the control signal to realize clock synchronization of the slave stations and the master station, so that the synchronization precision is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of industrial control, and more specifically, relates to a high-precision clock synchronization method, device, electronic equipment and storage medium based on an EtherCAT network. Background Art

[0002] The EtherCAT fieldbus has become a hot topic in the current industrial control field due to its advantages such as cost-effectiveness, good real-time performance, and good synchronization. With the development of industrial automation and intelligent manufacturing, the requirements for synchronous control performance in the industrial control field are constantly increasing. Especially in real-time control systems, accurate clock synchronization between slaves becomes particularly critical. EtherCAT strives to achieve accurate synchronization between slaves by adopting distributed clock technology. However, in practical applications, the crystal oscillator of the slave will cause slight differences in the timing cycle between slaves. The transmission process of data frames between different sites will also cause delays. These clock synchronization delay errors will affect the performance of real-time systems.

[0003] Although a variety of EtherCAT clock synchronization solutions have been made public, there are still technical difficulties in improving synchronization accuracy and reducing clock drift, and they often cannot meet the needs of high-precision and high-dynamic environments.

[0004] Chinese patent document CN111181681A discloses a master-slave station clock synchronization method based on EtherCAT real-time Ethernet, including: A. The master station broadcasts a data frame to obtain the number of slave stations, the slave station topology structure and the time when data arrives at each slave station; B. All slave station states are set to pre-operation; C. Any slave station that supports distributed clocks is selected as a reference clock slave station, and according to the slave station topology structure obtained in step A and the time when data arrives at each slave station, the data transmission delay between each non-reference clock slave station and the reference clock slave station and the clock initial offset between each non-reference clock slave station and the reference clock slave station are calculated, and the initial offset is sent to the non-reference clock slave station, etc. Although this method solves the problem of unstable communication between the master and slave stations caused by poor master-slave station synchronization performance, it cannot meet the requirements of high precision and high dynamic environment.

[0005] Chinese patent document CN117411579A discloses a method for realizing clock synchronization of a master-slave system based on EtherCAT, including: compensating the clock offset between the master station and each slave station from three angles: initial clock offset, transmission delay and clock drift. Compared with the traditional clock synchronization algorithm, the advantage of the clock synchronization algorithm of the present invention is to measure the transmission delay between the master station and the reference slave station, and use the transmission delay to compensate the initial clock offset of each slave station. Although this method improves the clock synchronization accuracy between the master station and the slave station, and although this method realizes the processing of clock drift through a dynamic compensation mechanism, its performance and accuracy may be affected in an environment where network conditions change frequently.

[0006] In summary, traditional clock synchronization methods mostly rely on static adjustment parameters and cannot effectively cope with changes in network delays and slight deviations in the device's own clock frequency, resulting in insufficient synchronization accuracy and slow response speed. In order to meet the demand for improved synchronization control performance, an EtherCAT clock synchronization method that can effectively improve synchronization accuracy and reduce clock drift is urgently needed to meet the requirements of high-precision and dynamically changing environments. Summary of the invention

[0007] The present invention aims to overcome at least one defect of the above-mentioned prior art and provide a high-precision clock synchronization method based on EtherCAT network, which can dynamically predict and accurately estimate the clock offset and drift of each slave device, and adjust PID control parameters in real time, thereby significantly improving the synchronization accuracy and system response speed.

[0008] The invention also discloses a device loaded with a high-precision clock synchronization method based on an EtherCAT network.

[0009] The detailed technical scheme of the present invention is as follows:

[0010] A high-precision clock synchronization method based on an EtherCAT network is applied to an EtherCAT system, wherein the EtherCAT system includes a master station and a plurality of slave stations that communicate with the master station and support a distributed clock function. The method includes:

[0011] S1. According to the time when the data frame sent by the master station arrives at each slave station, the transmission delay generated when the data frame is transmitted between the slave stations is obtained, and the first slave station connected to the master station is selected as the reference clock slave station, and the local clock offset of each remaining slave station is calculated according to the time when the reference clock slave station and each remaining slave station receive the data frame, and the transmission delay, and the local clock drift of each remaining slave station is calculated according to the local clock offset and the transmission delay;

[0012] S2. Obtain the initial state vector and initial error covariance of each remaining slave station according to the local clock offset and the local clock drift, input the initial state vector and initial error covariance into a Kalman filter, and calculate the state estimation value and error covariance estimation value of each remaining slave station at the current moment by using the state equation and observation equation of the Kalman filter;

[0013] S3, inputting the state estimation value and error covariance estimation value of each remaining slave station at the current moment into the fuzzy logic controller, the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter, and defuzzifies the fuzzy reasoning result by using the centroid method to obtain the target adjustment value for dynamically adjusting the PID control parameter;

[0014] S4. Update the PID control parameters using the target adjustment value, and input the updated PID control parameters into the PID controller, the PID controller outputs a control signal for adjusting the local clocks of the remaining slave stations, and uses the control signal to adjust the local clocks of the remaining slave stations so that the remaining slave stations maintain clock synchronization with the master station.

[0015] Preferably, according to the present invention, in step S1, the transmission delay generated when the data frame is transmitted between the slave stations is:

[0016]

[0017] In formula (1): t delay (n) indicates the transmission delay; T1 indicates the time when the data frame first arrives at the reference clock slave station; T2(n) indicates the time when the data frame first arrives at the nth slave station; T3(n) indicates the time when the data frame arrives at the nth slave station again during the loopback process; T4 indicates the time when the data frame arrives at the reference clock slave station again during the loopback process.

[0018] Preferably, according to the present invention, in step S1, the local clock offset of each of the remaining slave stations is:

[0019] t offset (n) = T2(n) - T1 - t delay (n) (2);

[0020] In formula (2): t offset (n) represents the local clock offset of each of the remaining slave stations, abbreviated as Δw; T1 represents the time when the data frame first arrives at the reference clock slave station; T2(n) represents the time when the data frame first arrives at the nth slave station; t delay (n) represents the transmission delay.

[0021] Preferably, according to the present invention, in step S1, the local clock drift of each of the remaining slave stations is:

[0022] Δt=t local (n)-t offset (n)-t sys_ref -t delay (n) (3);

[0023] In formula (3), Δt represents the local clock drift of each of the remaining slave stations; t local (n) represents the slave clock of each of the remaining slave stations; t offset (n) represents the local clock offset of each remaining slave station; t sys_ref Indicates the reference clock of the reference clock slave station, t delay (n) represents the transmission delay.

[0024] Preferably, according to the present invention, in step S2, the state equation and observation equation of the Kalman filter are used to calculate the state estimation value and error covariance estimation value of each remaining slave station at the current moment, specifically including:

[0025] S21, using the state equation to calculate the state prediction value and error covariance prediction value of each remaining slave station at the current moment, and using the observation equation to calculate the observation vector of each remaining slave station at the current moment;

[0026] S22. Introduce the Kalman gain, and update the state prediction value of the corresponding slave station at the current moment in combination with the observation vector of each other slave station at the current moment, so as to obtain the state estimation value and error covariance estimation value of each other slave station at the current moment.

[0027] Preferably, according to the present invention, in step S21, the state prediction value of each of the remaining slave stations at the current moment is:

[0028]

[0029] In formula (4): represents the predicted value of the state from the clock at time k; F k is the state transfer matrix; represents the state vector of the slave clock at time k-1;

[0030] The error covariance prediction value corresponding to the state prediction value is:

[0031]

[0032] In formula (5): represents the prediction error covariance of the slave clock at time k; F k is the state transfer matrix; F k T is the transpose of the state transfer matrix; Pk-1 represents the error covariance of the slave clock at time k-1; Q K is the process covariance matrix;

[0033] The observation vector of each remaining slave station at the current moment is:

[0034]

[0035] In formula (6): Z k represents the observation vector from the clock at time k; H k is the observation matrix; V represents the state prediction value from the clock at time k; k represents the observation noise.

[0036] Preferably, according to the present invention, in step S22, the Kalman gain is:

[0037]

[0038] In formula (7): K k represents the Kalman gain; represents the prediction error covariance of the slave clock at time k; H k is the observation matrix; is the transpose of the observation matrix; R k is the observation noise covariance matrix;

[0039] The estimated state value of each of the remaining slaves at the current moment is:

[0040]

[0041] In formula (8): represents the updated estimated state value of the slave clock at time k; represents the predicted value of the state from the clock at time k; K k represents the Kalman gain; Z k represents the observation vector from the clock at time k; H k is the observation matrix;

[0042] The error covariance estimate corresponding to the state estimate is:

[0043]

[0044] In formula (9): P k represents the error covariance estimate of the updated slave clock at time k; I is the unit matrix; K k represents the Kalman gain; H k is the observation matrix; represents the prediction error covariance of the slave clock at time k.

[0045] In another aspect of the present invention, a device for implementing a high-precision clock synchronization method based on an EtherCAT network is provided, the device comprising:

[0046] A data acquisition module, used to obtain the transmission delay generated when the data frame sent by the master station arrives at each slave station, and select the first slave station connected to the master station as the reference clock slave station, calculate the local clock offset of each remaining slave station according to the time when the reference clock slave station and each remaining slave station receive the data frame, and the transmission delay, and calculate the local clock drift of each remaining slave station according to the local clock offset and the transmission delay;

[0047] A data prediction module, used for obtaining the initial state vector and the initial error covariance of each remaining slave station according to the local clock offset and the local clock drift, inputting the initial state vector and the initial error covariance into a Kalman filter, and calculating the state estimation value and the error covariance estimation value of each remaining slave station at the current moment by using the state equation and observation equation of the Kalman filter;

[0048] A parameter adjustment value acquisition module is used to input the state estimation value and error covariance estimation value of each remaining slave station at the current moment into the fuzzy logic controller, the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter, and defuzzifies the fuzzy reasoning result by using the centroid method to obtain the target adjustment value for dynamically adjusting the PID control parameter;

[0049] A clock synchronization module is used to update the PID control parameters using the target adjustment value, and input the updated PID control parameters into the PID controller, the PID controller outputs a control signal for adjusting the local clocks of the remaining slave stations, and the local clocks of the remaining slave stations are adjusted using the control signal to keep the clocks of the remaining slave stations synchronized with the master station.

[0050] In another aspect of the present invention, there is also provided an electronic device, comprising:

[0051] at least one processor; and

[0052] A memory storing instructions, which, when executed by the at least one processor, enables the at least one processor to execute the high-precision clock synchronization method based on the EtherCAT network as described above.

[0053] In another aspect of the present invention, a machine-readable storage medium is provided, which stores executable instructions. When the instructions are executed, the machine executes the high-precision clock synchronization method based on the EtherCAT network as described above.

[0054] Compared with the prior art, the present invention has the following beneficial effects:

[0055] (1) The present invention provides a high-precision clock synchronization method based on an EtherCAT network, which uses a Kalman filter to dynamically predict and accurately estimate clock offset and drift. This method continuously optimizes the clock state in a statistical manner based on minimizing the variance of the estimation error. Compared with traditional static synchronization methods, the present invention can identify and adapt to slight changes and occasional deviations in clock frequency. By fine-tuning the filter parameters, the present invention can adapt to various industrial environments and application requirements, thereby achieving extremely high synchronization accuracy and stability during continuous operation.

[0056] (2) The present invention dynamically adjusts PID control parameters based on clock state predictions provided by the Kalman filter by integrating a fuzzy logic controller. This adjustment is not only based on the current network status and internal system status, but also predicts possible future changes and optimizes the synchronization strategy in real time. The flexibility and responsiveness of this strategy enable the present invention to maintain efficient and accurate synchronization when network conditions change rapidly.

[0057] (3) The present invention is designed as a universal solution, compatible with all devices supporting the EtherCAT protocol, without the need to design or modify specific hardware. This high degree of versatility and compatibility allows the present invention to be easily integrated into existing industrial automation systems, supporting a wide range of applications from small robots to large production lines. All control parameter adjustments are implemented through software, which greatly reduces the need for physical intervention and simplifies the system maintenance and upgrade process. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 It is a framework diagram of the present invention.

[0059] Figure 2 It is a flow chart of the fuzzy logic controller in the present invention. DETAILED DESCRIPTION

[0060] The present disclosure is further described below in conjunction with the accompanying drawings and embodiments.

[0061] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.

[0062] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0063] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.

[0064] In view of the deficiencies in the prior art, the present invention provides a high-precision clock synchronization method based on an EtherCAT network. The method utilizes a Kalman filter to dynamically predict and estimate the clock offset and drift of each slave device, and utilizes a fuzzy logic controller to nonlinearly adjust PID control parameters according to the prediction deviation obtained from the Kalman filter. The PID controller generates accurate control signals in real time according to the PID control parameters adjusted by the fuzzy logic controller. These control signals are used to directly adjust the clock of the slave device to ensure its accurate synchronization with the master clock, thereby achieving dynamic compensation for clock offset and drift and significantly improving synchronization accuracy.

[0065] The high-precision clock synchronization method and device based on the EtherCAT network of the present invention are further described below in conjunction with specific embodiments.

[0066] Embodiment 1,

[0067] This embodiment provides a high-precision clock synchronization method based on an EtherCAT network, which is applied to an EtherCAT system, wherein the EtherCAT system includes a master station and multiple slave stations that communicate with the master station and support the distributed clock function. In this embodiment, the master station first scans all slave station devices of the EtherCAT network, and reads the characteristic information registers 0x0008 to 0x0009 of all slave stations, and determines all slave stations that can support the distributed clock function according to the value of bit2 in the register, where 0 indicates not supported and 1 indicates supported; then the master station reads the data link status registers 0x0110 to 0x0111 of all slave stations, obtains the port communication status of each slave station, thereby knowing the connection relationship of the slave station devices, and obtaining the network topology structure accordingly.

[0068] Specific reference Figure 1 , the method comprising:

[0069] S1. According to the time when the data frame sent by the master station arrives at each slave station, the transmission delay generated when the data frame is transmitted between the slave stations is obtained, and the first slave station with a distributed clock function connected to the master station is selected as the reference clock slave station, and the local clock offset of each remaining slave station is calculated according to the time when the reference clock slave station and each remaining slave station receive the data frame, and the transmission delay, and the local clock drift of each remaining slave station is calculated according to the local clock offset and the transmission delay.

[0070] When the EtherCAT system is initialized, the master triggers the propagation delay measurement by sending a broadcast write command (BWR) datagram to send data frames to all slave devices in the EtherCAT network. Then, based on the time it takes for the data frame sent by the master to arrive at each slave, the transmission delay generated when the data frame is transmitted between the slaves is obtained.

[0071] The transmission delay mentioned above refers to the delay that occurs when data frames are transmitted between slave stations, including internal device and physical connection delays. Therefore, when synchronizing slave station clocks, the transmission delay of data frames between slave stations should be considered.

[0072] In this embodiment, it is assumed that there are N slaves in the EtherCAT network, and the data frame sent by the master arrives at the reference clock slave at time T1, arrives at the nth slave at time T2(n), and returns through the port loopback after arriving at the last (Nth) slave device, arrives at the nth slave again at time T3(n), and finally returns to the reference clock slave again at time T4. Assuming that the delay per unit length of the network cable is the same and each slave has the same time to parse and forward the data frame, the master can calculate the transmission delay t generated when the data frame is transmitted between the slaves according to the following formula: delay (n) is:

[0073]

[0074] In formula (1), t delay (n) represents the transmission delay, T1 represents the time when the data frame first arrives at the reference clock slave station, T2(n) represents the time when the data frame first arrives at the nth slave station, T3(n) represents the time when the data frame arrives at the nth slave station again during the loopback process, and T4 represents the time when the data frame arrives at the reference clock slave station again during the loopback process.

[0075] The reference clock is the clock of the first slave station with distributed clock function connected to the master station as specified in the EtherCAT protocol as the reference clock. The clocks of other slave stations are called slave clocks or local clocks. The reference clock is used to synchronize other slave clocks with the master station clock. The first slave station in the EtherCAT network will be used as the reference clock slave station.

[0076] The local clock offset is the difference between the slave clocks of the remaining slave stations and the reference clock of the reference clock slave station. When the system starts, the difference between the slave clocks of the remaining slave stations and the reference clock of the reference clock slave station is called the initial clock offset.

[0077] When the distributed clock is initialized, the master station measures the transmission delay between the reference clock and other slave clocks, calculates the offset between the slave clock and the reference clock, and writes the transmission delay and offset to each slave station.

[0078] In this embodiment, the master station can calculate the local clock offset t of each of the remaining slave stations according to the following formula: offset (n) is:

[0079] t offset (n) = T2(n) - T1 - t delay (n) (2);

[0080] In formula (2), t offset (n) represents the local clock offset of each of the remaining slave stations, abbreviated as Δw, T1 represents the time when the data frame first arrives at the reference clock slave station, T2(n) represents the time when the data frame first arrives at the nth slave station, t delay (n) represents the transmission delay.

[0081] The clock drift is the frequency change caused by the physical property difference of each slave clock crystal (such as the influence of temperature and life). As the running time increases, even the originally synchronized slave clocks will gradually deviate. This deviation needs to be controlled through continuous monitoring and dynamic compensation.

[0082] In this embodiment, the local clock offset and transmission delay calculated above are used to calculate the local clock drift Δt of each remaining slave station, that is:

[0083] Δt=t local (n)-t offset (n)-t sys_ref -t delay (n) (3);

[0084] In formula (3), Δt represents the local clock drift of each of the remaining slave stations, t local (n) represents the slave clock of each other slave station, t offset (n) represents the local clock offset of each of the remaining slave stations, t sys_ref Indicates the reference clock of the reference clock slave station, t delay (n) represents the transmission delay.

[0085] The master station uses the ARMW or FRMW (read / multiple write) command to send a data message and read the current system time from the reference clock slave station, which is the reference clock t of the reference clock slave station. sys_ref , and then the data is written to each slave station when it arrives at the subsequent slave station. Each slave station has its own local time and local clock offset, respectively t local (n) and t offset (n) indicates.

[0086] It should be understood that the timing time of the EtherCAT system master is the master clock. During the initialization process, the master follows the format of the system time and directly sends the master clock to the reference clock slave, so that the entire system is timed according to the master clock standard. After clock synchronization, the master clock will be synchronized by the reference clock as a slave clock.

[0087] Based on the above process, the local clock offset Δw and local clock drift Δt of the remaining slave stations are finally obtained. This data will be used as the initial state parameters of the EtherCAT system and input into the Kalman filter. The Kalman filter uses these initial data for further dynamic adjustment and optimization, and accurately estimates and corrects the actual deviation and drift of the slave station clock through continuous state updates to ensure high-precision clock synchronization of the entire system.

[0088] S2. Obtain the initial state vector and initial error covariance of each remaining slave station according to the local clock offset and the local clock drift, input the initial state vector and initial error covariance into the Kalman filter, and use the state equation and observation equation of the Kalman filter to calculate the state estimate and error covariance estimate of each remaining slave station at the current moment.

[0089] Specifically, when the master station sends a data frame to each slave station for the first time and generates timestamp data, the local clock offset Δw and the local clock drift Δt of the remaining slave stations except the reference clock slave station are calculated based on the timestamp data, and the initial state vector x0 and the initial error covariance P0 of each remaining slave station are obtained according to the calculated local clock offset Δw and local clock drift Δt, where x0 = [Δw, Δt] T , And in the initial error covariance P0, the elements on the diagonal

[0090] They represent the variance of the initial estimate of the corresponding state variable, and their size depends on the previous understanding of the system behavior and the measurement accuracy of the system. A larger value means that the initial state estimate has a higher uncertainty and needs to be accurately adjusted through observation data in the subsequent filtering process.

[0091] Then the initial state vector x0 and its initial error covariance P0 are input into the Kalman filter to initialize it, that is, the initial state vector x0 and its initial error covariance P0 will be used as initial data of the Kalman filter to perform subsequent calculations.

[0092] The Kalman filter is used to dynamically predict and estimate the offset and drift of the slave station clock. The Kalman filter combines historical data and real-time observation information, and continuously optimizes the estimate of the slave clock state of each remaining slave station by minimizing the estimated error variance. Finally, the Kalman filter inputs the adjusted state estimate and error covariance into the fuzzy logic controller for further optimization.

[0093] In this embodiment, the state equation is used to accurately model the dynamic behavior of the slave station clock. Based on the standard Kalman filter theory, the state equation is constructed by combining the past state observation data of the slave station and the predicted change of the future state. The observation equation enables the master station to accurately estimate the current state of the slave station based on the timestamp feedback information returned by the slave station.

[0094] By combining the above two equations, the offset and drift of the slave clock can be dynamically estimated, and these estimation results can be used to achieve high-precision clock synchronization.

[0095] Kalman filter plays an important role in state prediction, and can estimate the past and current states of the clock as well as the future states. The basic idea of ​​Kalman filter is: taking the minimum mean square error as the criterion for the best estimation, using the state space model of signal and noise, using the estimated value of the previous moment and the observed value of the current moment to update the estimate of the state variable, and find the estimated value of the current moment, so as to make an estimate of the signal to be processed that satisfies the minimum mean square error according to the established state equation and observation equation.

[0096] Based on this, in step S2, the initial state vector and its initial error covariance are input into the Kalman filter, and the state equation and observation equation of the Kalman filter are used to calculate the state estimation value and error covariance estimation value of each remaining slave station at the current moment, specifically including:

[0097] S21. Calculate the state prediction value and error covariance prediction value of each remaining slave station at the current moment using the state equation, and calculate the observation vector of each remaining slave station at the current moment using the observation equation.

[0098] The state equation and observation equation are used to calculate the state vector and observation vector of the slave clock at the current time point, respectively.

[0099] Specifically, the state equation is used to characterize the dynamic behavior of the slave clocks of the remaining slave stations in the EtherCAT system, which is the local clock offset and local clock drift. The state equation describes the time evolution of the slave clock state and is used to predict the state vector at the current moment based on the state vector at the previous moment to obtain the deviation state.

[0100] The state equation can be given by the following mathematical model: k =F k x k-1 +B k u k +w k , where x k represents the predicted state vector of the slave clock at time k, including the local clock offset and local clock drift of the slave clock, which can be expressed as x(k)=[Δw(k),Δt(k)] T ;x k-1 represents the state vector of the slave clock at time k-1; F k is the state transfer matrix, which describes the evolution of the slave clock state within the synchronization period and can be expressed as: Δa represents the time interval of the synchronization cycle; B k is the control input matrix. Since there is no input in this embodiment, it can be omitted or set to a zero matrix; k is the input vector. Since no input is provided to the clock state equation in this embodiment, u k =0; w k is the process noise, simulating the uncertainty inside and outside the system. k It is unmeasurable, so it is assumed to have a mean of 0 and a covariance of Q K The normal distribution P(w k )~(0,Q K ), by the process covariance matrix Q K Determine the process noise w k The variance of each component and the covariance between them (i.e. the degree of association between components) are expressed as: They represent the variance of the local clock offset and local clock drift respectively.

[0101] Therefore, in the prediction step, the Kalman filter can predict the slave clock deviation state at the current time k based on the slave clock state at the previous time k-1, that is, at the beginning of each synchronization cycle, the state prediction value of the slave clock of each remaining slave station at the current time k is calculated by the following formula:

[0102]

[0103] In formula (4), represents the predicted value of the state from the clock at time k, F k is the state transfer matrix, Represents the state vector of the slave clock at time k-1.

[0104] Calculate the predicted state value of the slave clock of each remaining slave station at the current time k Then, the corresponding error covariance prediction value is calculated by the following formula:

[0105]

[0106] In formula (5), represents the prediction error covariance of the slave clock at time k, F k is the state transfer matrix, F k T is the transpose of the state transfer matrix, P k-1 represents the error covariance of the slave clock at time k-1, Q K is the process covariance matrix.

[0107] Above It is at time point k based on the state at the previous time point The state prediction, is the predicted error covariance at time point k, indicating the uncertainty of the predicted state.

[0108] The observation equation is used to describe how the master station observes the clock state of the slave station through measurement, and can be given by the following mathematical model:

[0109]

[0110] In formula (6), Z k represents the observation vector of the slave clock at time k, which is composed of the timestamp data of the slave station and the master station collected by the system; H k is the observation matrix, which is the unit matrix in this embodiment; V represents the state prediction value from the clock at time k; k It represents the observation noise, which represents the uncertainty in the measurement. It is assumed to have a mean of 0 and a covariance of R k The normal distribution P(V k )~(0,R k ), the observation noise covariance matrix R k Determine, expressed as They represent the variance of local clock offset and local clock drift, u Δw,Δt represents the covariance between the local clock offset and the local clock drift, R k Depends on the standard uncertainties associated with the offset and drift measurements and their covariance.

[0111] Therefore, the state prediction value and error covariance prediction value, as well as the observation vector of each remaining slave station at the current moment can be calculated respectively by the above formulas (4) to (6).

[0112] S22. Introduce the Kalman gain, and update the state prediction value of the corresponding slave station at the current moment in combination with the observation vector of each other slave station at the current moment, so as to obtain the state estimation value and error covariance estimation value of each other slave station at the current moment.

[0113] That is, in the update step, when the master station sends a data frame to each slave station and generates new timestamp data, the corresponding local clock offset and local clock drift data are calculated according to the new timestamp data. The Kalman filter updates the state estimate based on the calculated local clock offset and local clock drift data and combines the predicted state, and uses the Kalman gain to minimize the estimation error.

[0114] Wherein, the Kalman gain is:

[0115]

[0116] In formula (7), K k represents the Kalman gain, represents the prediction error covariance of the slave clock at time k, H k is the observation matrix, is the transpose of the observation matrix, R k is the observation noise covariance matrix.

[0117] Then the Kalman gain is introduced, and the corresponding state prediction value is updated in combination with the observation vector from the clock as follows:

[0118]

[0119] In formula (8), represents the updated estimated state value of the slave clock at time k, represents the predicted value of the state from the clock at time k, K k represents the Kalman gain, Z k represents the observation vector from the clock at time k, H k is the observation matrix.

[0120] Then update the state estimate using the following formula The corresponding error covariance estimate is:

[0121]

[0122] In formula (9), P krepresents the updated error covariance estimate of the slave clock at time k, I is the unit matrix, K k represents the Kalman gain, H k is the observation matrix, represents the prediction error covariance of the slave clock at time k.

[0123] Updated state estimate and the error covariance estimate P k The latest observational information and its uncertainties are taken into account.

[0124] Finally, the Kalman filter outputs the adjusted state estimate and the error covariance estimate P k To the fuzzy logic controller to further optimize the control parameters and improve the overall synchronization accuracy and efficiency of the system.

[0125] S3. Input the state estimation value and error covariance estimation value of each remaining slave station at the current moment into the fuzzy logic controller, the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter, and defuzzifies the fuzzy reasoning result using the centroid method to obtain the target adjustment value for dynamically adjusting the PID control parameter.

[0126] That is Figure 2 As shown, the state estimate output by the Kalman filter is will be used as the error e, error covariance estimate P k It will be input into the fuzzy logic controller as the error change ec, and the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter according to its input data. Among them, the PID control parameters are the proportional coefficient Kp, the integral constant Ki, and the differential constant Kd, and their corresponding adjustment values ​​are ΔKp, ΔKi and ΔKd respectively.

[0127] Then, the fuzzy inference result of the adjustment value is defuzzified using the center of gravity method and converted into an accurate target adjustment value, and then the obtained target adjustment value is used to adjust the parameters of the PID controller in real time.

[0128] In this embodiment, the fuzzy subsets defining the error e and the error change ec are {NB, NM, NS, ZO, PS, PM, PB}, wherein the linguistic variable values ​​of the error e and the error change ec take seven values, namely, "negative large" (NB), "negative medium" (NM), "negative small" (NS), "zero" (ZO), "positive small" (PS), "positive medium" (PM), and "positive large" (PB).

[0129] The membership functions for the above values ​​are all triangular, and the ranges taken by each value are of equal width.

[0130] According to the relationship between error e and error change ec, the fuzzy control rule table of PID control parameters is formed, which are:

[0131] Table 1 Fuzzy control rules of proportional coefficient Kp

[0132]

[0133] Table 2 Fuzzy control rules of integral constant Ki

[0134]

[0135]

[0136] Table 3 Fuzzy control rules of differential constant Kd

[0137]

[0138] Then, according to the current error e, the error change ec and the fuzzy control rules defined in the above table, fuzzy reasoning is performed to obtain the corresponding fuzzy reasoning results of each parameter adjustment value, for example:

[0139] IF E is NB and EC is NB thenΔKp is PB;

[0140] IF E is NB and EC is NS thenΔKp is PM.

[0141] Furthermore, in this embodiment, the centroid method is used to defuzzify the fuzzy reasoning results of the above-mentioned parameter adjustment values. The centroid method takes the centroid of the area enclosed by the membership function curve and the horizontal coordinate as the final output value of the fuzzy reasoning, which reflects the comprehensive influence of all fuzzy rules and maintains the smoothness and accuracy of the output. Its output expression is:

[0142]

[0143] In formula (10), v0 represents the fuzzy reasoning result v and the membership function μ v (v) Integral of the product and membership function μ v The ratio of the integrals of (v) is the result obtained after defuzzification.

[0144] Substituting the fuzzy reasoning results of the adjustment values ​​ΔKp, ΔKi and ΔKd of the PID control parameters into the above formula (10) respectively, the precise value of each adjustment value can be calculated accordingly, which is the target adjustment value that can be directly used to adjust the PID control parameters.

[0145] S4. Update the PID control parameters using the target adjustment value, and input the updated PID control parameters into the PID controller, the PID controller outputs a control signal for adjusting the local clocks of the remaining slave stations, and uses the control signal to adjust the local clocks of the remaining slave stations so that the remaining slave stations maintain clock synchronization with the master station.

[0146] Specifically, the PID controller receives the target adjustment values ​​obtained above for adjusting the PID control parameters, and uses these target adjustment values ​​to adjust its proportional coefficient Kp, integral constant Ki, differential constant Kd and other parameters accordingly, and obtains updated proportional coefficient Kp', integral constant Ki', differential constant Kd', which are: Kp'=Kp+ΔKp, Ki'=Ki+ΔKi, Kd'=Kd+ΔKd, respectively.

[0147] The PID controller then uses the updated control parameters Kp', Ki', Kd' to calculate the control signal u(t) used to adjust the local clocks of the remaining slaves. The calculation formula is:

[0148]

[0149] In formula (11), u(t) represents the control signal, Kp′, Ki′, Kd′ are the updated PID control parameters, e(t) represents the local clock deviation at the current moment, and t represents the time interval from the start of adjustment to the output of the current control signal.

[0150] Finally, according to the control signal u(t) generated by the PID controller, the remaining slaves adjust their internal clock operating frequencies in real time to synchronize them with the master clock to reduce the synchronization error between the slave clock and the master clock, thereby minimizing the clock deviation in the entire EtherCAT network.

[0151] In summary, the high-precision clock synchronization method based on the EtherCAT network of the present invention uses a Kalman filter to dynamically predict and accurately estimate clock deviation and drift, and dynamically adjusts PID control parameters according to the clock state prediction provided by the Kalman filter through an integrated fuzzy logic controller. This adjustment is not only based on the current network status and internal system status, but also predicts possible future changes and optimizes the synchronization strategy in real time. The flexibility and response speed of this strategy enable the present invention to maintain efficient and accurate synchronization when network conditions change rapidly.

[0152] Embodiment 2,

[0153] This embodiment provides a device for implementing a high-precision clock synchronization method based on an EtherCAT network, the device comprising:

[0154] A data acquisition module, used to obtain the transmission delay generated when the data frame sent by the master station arrives at each slave station, and select the first slave station connected to the master station as the reference clock slave station, calculate the local clock offset of each remaining slave station according to the time when the reference clock slave station and each remaining slave station receive the data frame, and the transmission delay, and calculate the local clock drift of each remaining slave station according to the local clock offset and the transmission delay;

[0155] A data prediction module, used for obtaining the initial state vector and the initial error covariance of each remaining slave station according to the local clock offset and the local clock drift, inputting the initial state vector and the initial error covariance into a Kalman filter, and calculating the state estimation value and the error covariance estimation value of each remaining slave station at the current moment by using the state equation and observation equation of the Kalman filter;

[0156] A parameter adjustment value acquisition module is used to input the state estimation value and error covariance estimation value of each remaining slave station at the current moment into the fuzzy logic controller, the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter, and defuzzifies the fuzzy reasoning result by using the centroid method to obtain the target adjustment value for dynamically adjusting the PID control parameter;

[0157] A clock synchronization module is used to update the PID control parameters using the target adjustment value, and input the updated PID control parameters into the PID controller, the PID controller outputs a control signal for adjusting the local clocks of the remaining slave stations, and the local clocks of the remaining slave stations are adjusted using the control signal to keep the clocks of the remaining slave stations synchronized with the master station.

[0158] Embodiment 3,

[0159] This embodiment also provides an electronic device, including:

[0160] at least one processor; and

[0161] A memory storing instructions, which, when executed by the at least one processor, enables the at least one processor to execute the high-precision clock synchronization method based on the EtherCAT network as described above.

[0162] In this embodiment, the electronic device may include, but is not limited to: personal computers, server computers, workstations, desktop computers, laptop computers, notebook computers, mobile computing devices, smart phones, tablet computers, cellular phones, personal digital assistants (PDAs), handheld devices, messaging devices, wearable computing devices, consumer electronic devices, and the like.

[0163] Embodiment 4,

[0164] This embodiment further provides a machine-readable storage medium storing executable instructions, which, when executed, enable the machine to execute the high-precision clock synchronization method based on the EtherCAT network as described above.

[0165] Specifically, a system or device equipped with a readable storage medium can be provided, on which software program codes that implement the functions of any of the above-mentioned embodiments are stored, and a computer or processor of the system or device can read and execute instructions stored in the readable storage medium.

[0166] In this case, the program code itself read from the machine-readable medium can realize the function of any one of the above embodiments, and thus the machine-readable code and the machine-readable storage medium storing the machine-readable code constitute part of this specification.

[0167] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or a cloud via a communication network.

[0168] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0169] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0170] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0171] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0172] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention shall be included in the protection scope of the claims of the present invention.

Claims

1. A high-precision clock synchronization method based on EtherCAT network, characterized in that: Applied to an EtherCAT system, the EtherCAT system includes a master station and a plurality of slave stations that communicate with the master station and support a distributed clock function, the method includes: S1. According to the time when the data frame sent by the master station arrives at each slave station, the transmission delay generated when the data frame is transmitted between the slave stations is obtained, and the first slave station connected to the master station is selected as the reference clock slave station, and the local clock offset of each remaining slave station is calculated according to the time when the reference clock slave station and each remaining slave station receive the data frame, and the transmission delay, and the local clock drift of each remaining slave station is calculated according to the local clock offset and the transmission delay; S2. Obtain the initial state vector and initial error covariance of each remaining slave station according to the local clock offset and the local clock drift, input the initial state vector and initial error covariance into a Kalman filter, and calculate the state estimation value and error covariance estimation value of each remaining slave station at the current moment by using the state equation and observation equation of the Kalman filter; S3, inputting the state estimation value and error covariance estimation value of each remaining slave station at the current moment into the fuzzy logic controller, the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter, and defuzzifies the fuzzy reasoning result by using the centroid method to obtain the target adjustment value for dynamically adjusting the PID control parameter; S4. Update the PID control parameters using the target adjustment value, and input the updated PID control parameters into the PID controller, the PID controller outputs a control signal for adjusting the local clocks of the remaining slave stations, and uses the control signal to adjust the local clocks of the remaining slave stations so that the remaining slave stations maintain clock synchronization with the master station.

2. The high-precision clock synchronization method based on EtherCAT network according to claim 1, characterized in that: In step S1, the transmission delay generated when the data frame is transmitted between the slave stations is: In formula (1): t delay (n) represents the transmission delay; T1 represents the time when the data frame first arrives at the reference clock slave station; T2(n) represents the time when the data frame first arrives at the nth slave station; T3(n) indicates the time it takes for the data frame to reach the nth slave again during the loopback process; T4 indicates the time it takes for the data frame to reach the reference clock slave again during the loopback process.

3. The high-precision clock synchronization method based on EtherCAT network according to claim 2, characterized in that: In step S1, the local clock offset of each of the remaining slave stations is: t offset (n)=T2(n)-T1-t delay (n) (2); In formula (2): t offset (n) represents the local clock offset of each of the remaining slave stations, abbreviated as Δw; T1 represents the time when the data frame first arrives at the reference clock slave station; T2(n) represents the time when the data frame first arrives at the nth slave station; t delay (n) represents the transmission delay.

4. The high-precision clock synchronization method based on EtherCAT network according to claim 3 is characterized in that: In step S1, the local clock drift of each of the remaining slave stations is: Δt=t local (n)-t offset (n)-t sys_ref -t delay (n) (3); In formula (3): Δt represents the local clock drift of each of the remaining slave stations; t local (n) represents the slave clock of each of the remaining slave stations; t offset (n) represents the local clock offset of each of the remaining slave stations; t sys_ref Indicates the reference clock of the reference clock slave station, t delay (n) represents the transmission delay.

5. The high-precision clock synchronization method based on EtherCAT network according to claim 1, characterized in that: In step S2, the state equation and observation equation of the Kalman filter are used to calculate the state estimation value and error covariance estimation value of each remaining slave station at the current moment, specifically including: S21, using the state equation to calculate the state prediction value and error covariance prediction value of each remaining slave station at the current moment, and using the observation equation to calculate the observation vector of each remaining slave station at the current moment; S22. Introduce the Kalman gain, and update the state prediction value of the corresponding slave station at the current moment in combination with the observation vector of each other slave station at the current moment, so as to obtain the state estimation value and error covariance estimation value of each other slave station at the current moment.

6. The high-precision clock synchronization method based on EtherCAT network according to claim 5, characterized in that: In step S21, the state prediction value of each of the remaining slave stations at the current moment is: In formula (4): represents the predicted value of the state from the clock at time k; F k is the state transfer matrix; represents the state vector of the slave clock at time k-1; The error covariance prediction value corresponding to the state prediction value is: In formula (5): represents the prediction error covariance of the slave clock at time k; F k is the state transfer matrix; is the transpose of the state transfer matrix; P k-1 represents the error covariance of the slave clock at time k-1; Q K is the process covariance matrix; The observation vector of each remaining slave station at the current moment is: In formula (6): Z k represents the observation vector from the clock at time k; H k is the observation matrix; V represents the state prediction value from the clock at time k; k represents the observation noise.

7. The high-precision clock synchronization method based on EtherCAT network according to claim 6, characterized in that: In step S22, the Kalman gain is: In formula (7): K k represents the Kalman gain; represents the prediction error covariance of the slave clock at time k; H k is the observation matrix; is the transpose of the observation matrix; R k is the observation noise covariance matrix; The estimated state value of each of the remaining slaves at the current moment is: In formula (8): represents the updated estimated state value of the slave clock at time k; represents the predicted value of the state from the clock at time k; K k represents the Kalman gain; Z k represents the observation vector from the clock at time k; H k is the observation matrix; The error covariance estimate corresponding to the state estimate is: In formula (9): P k represents the error covariance estimate of the updated slave clock at time k; I is the unit matrix; K k represents the Kalman gain; H k is the observation matrix; represents the prediction error covariance of the slave clock at time k.

8. A device for implementing a high-precision clock synchronization method based on an EtherCAT network, characterized in that: The device comprises: A data acquisition module, used to obtain the transmission delay generated when the data frame sent by the master station arrives at each slave station, and select the first slave station connected to the master station as the reference clock slave station, calculate the local clock offset of each remaining slave station according to the time when the reference clock slave station and each remaining slave station receive the data frame, and the transmission delay, and calculate the local clock drift of each remaining slave station according to the local clock offset and the transmission delay; A data prediction module, used for obtaining the initial state vector and the initial error covariance of each remaining slave station according to the local clock offset and the local clock drift, inputting the initial state vector and the initial error covariance into a Kalman filter, and calculating the state estimation value and the error covariance estimation value of each remaining slave station at the current moment by using the state equation and observation equation of the Kalman filter; A parameter adjustment value acquisition module is used to input the state estimation value and error covariance estimation value of each remaining slave station at the current moment into the fuzzy logic controller, the fuzzy logic controller outputs the fuzzy reasoning result for dynamically adjusting the adjustment value of the PID control parameter, and defuzzifies the fuzzy reasoning result by using the centroid method to obtain the target adjustment value for dynamically adjusting the PID control parameter; A clock synchronization module is used to update the PID control parameters using the target adjustment value, and input the updated PID control parameters into the PID controller, the PID controller outputs a control signal for adjusting the local clocks of the remaining slave stations, and the local clocks of the remaining slave stations are adjusted using the control signal to keep the clocks of the remaining slave stations synchronized with the master station.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and A memory storing instructions, which, when executed by the at least one processor, enable the at least one processor to execute the high-precision clock synchronization method based on the EtherCAT network as claimed in any one of claims 1 to 7.

10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores executable instructions, which, when executed, enable the machine to perform the high-precision clock synchronization method based on the EtherCAT network according to any one of claims 1 to 7.

Citation Information

Cited By

  • Network time synchronization optimization method and system, readable storage medium and computer

    CN118890685A

  • Clock synchronization method of high-credibility triple safety control system

    CN119689965A

  • EtherCAT master station synchronization control method and system based on microkernel operating system

    CN121098662A