1 Introduction

Medium-thick plate welding plays a vital role in various industries, including transportation, shipbuilding, energy, chemical industry, and heavy machinery [1-6]. Key components such as marine engineering equipment [7], nuclear power unit rotors [8], and shield machine blades [9] are often welded using medium-thick plates. Multi-layer welding is one of the most common methods for medium-thick plate welding. The root pass welding, as the first process of multi-layer welding, directly affects the workpiece qualification rate [10-13]. In the automatic welding process, the welding torch should not only track the weld seam, but also align the center of the weld seam in order to ensure the quality of the weld [14].

However, under actual conditions, the weld gap not only exists but also fluctuates randomly due to processing errors, installation errors, and heat input during welding [15, 16]. Hence, it is essential to track the weld seam of the root pass welding with variable gap [17].

The sensors utilized for weld seam track are generally based on arc sensing and optical sensing. Although other types of sensors, such as infrared sensors and ultrasound sensors, have their own methods of characteristic feature extraction, they have not yet been widely utilized in industrial settings [18]. The vision sensors have the advantages of rich information, no contact with the workpiece, high accuracy, and good sensitivity. However, strong noise interference such as arc splash and smoke brings great challenges to image processing. Additionally, the process of visual calibration for welding systems is complicated and time-consuming. Overcoming these challenges and achieving quick, stable, and accurate calibration remains a significant challenge [19]. The advanced detection error of vision sensors also limits its application scene, especially not suitable for the scene where the weld gap changes in real time.

Arc sensing technology has been widely used in the field of robotic arc welding since the 1980s. Due to its high sensitivity and noise resistance, it has been widely used to monitor the instabilities of the welding process [20]. As the demand for tracking accuracy has increased, research on arc sensors has shifted from mechanical oscillation to magnetically controlled arc oscillation. Baek et al. [21] developed a special measurement device for the arc voltage to enhance the reliability of the seam tracking sensor. Park et al. [22] proposed a moving average algorithm for seam tracking, which was proven to be suitable for the root pass, filling pass, and cap pass. However, arc sensing is limited by low waving frequency and high dependence on workpiece assembly accuracy. Kodama et al. [23] developed a high-frequency oscillation arc sensor for the simultaneous detection of torch aiming deviation and gap width. However, this method is not suitable for GTAW (Gas Tungstern Arc Welding) where arc and wire feeding are separated. Kang et al. [24, 25] introduced a mathematical model of the magnetic arc deflection for theoretical prediction. They studied the arc and bead characteristics in narrow groove GMAW (Gas Metal Arc Welding) using electromagnetic arc oscillation and established the mathematical model of the arc sensor. Hong et al. [26, 27] extracted the deviation information of the actual weld groove using the effective integral twice-removed extreme contrast method. And they proposed a signal extraction and analytical method of the system based on the Hilbert Huang transform and Cohen nuclear magnetic-control arc seam tracking sensor. Hong et al. [28] proposed a method for deviation acquisition based on magnetic-control arc sensing for multi-pass welding by using Matlab/Simulink to analyze the transformation discipline of welding currents. Belous et al. [29] offered a system for automatic regulation of the position of the tungsten electrode in the groove in narrow-gap magnetically controlled arc TIG (Tungstern Inter Gas) welding of titanium. The movement of the welding arc under the effect of the external controlling magnetic field is used to monitor the electrode displacement from the weld center. Sun et al. [30] investigated the effects of magnetic field on arc image and weld formation and developed a magnetic arc oscillation system for TIG narrow gap welding to prevent insufficient sidewall fusion and improve efficiency and quality for thick component welding.

Previous studies have turned to the influence of external magnetic field on the arc, molten pool, and welding process after briefly involving the weld seam tracking of magnetic arc oscillation. In fact, the application of magnetically controlled arc oscillation to weld seam tracking is very promising. The magnetically controlled arc oscillation has several advantages over mechanical oscillation, such as simple structure, no noise or vibration, and no mechanical wear. Additionally, the magnetic field not only increases the arc oscillation frequency and improves the accuracy of weld tracking but also has a positive effect on the weld shape [31]. However, previous studies on magnetic arc oscillation in weld seam tracking have mostly focused on simple working conditions and weld types, but nothing can be done for tracking of root pass weld with a variable gap. The main difficulties in root pass weld tracking with variable gap are as follows:

  1. a.

    In situations where the arc oscillates to the position of the weld gap, the arc length undergoes an abrupt change, rendering the arc signal unusable. As shown in Fig. 1a, a steady change in the arc signal is observed during the scanning process when there is no weld gap. However, during actual welding, the weld gap may vary randomly, causing the arc signal to fluctuate abruptly and randomly, as shown in Fig. 1b. Consequently, processing the signal becomes more challenging.

  2. b.

    Interference of welding wire and droplet transition on the arc signal. Obstruction of the arc by the welding wire and droplets will lead to a decrease in the peak value of the arc signal, as shown in Fig. 2b. Since the droplet transition is a dynamic process, its interference with the arc signal is also dynamically changing. This interference can reduce the accuracy of weld tracking and lead to off-set welding.

Fig. 1
figure 1

The arc signal aquired by the arc sensor: a without weld gap, b with weld gap

Fig. 2
figure 2

The arc signal aquired by the arc sensor: a without droplets, b with droplets

In response to the above problems, we propose a novel method for tracking root pass weld with a variable gap, based on a magnetically controlled arc sensor. This method is applicable to different types of root pass weld seams, including fillet, butt, and lap, and allows for real-time tracking of weld gap variation. The main contributions of this paper can be summarized as follows: (1) an arc sensor based on coded magnetic control is designed to acquire the arc signal. The sensor uses the coding sequence of the excitation current as the arc positioning information and can measure the weld gap width while tracking the weld seam. (2) An arc signal compensation method of selectively taking the average based on the Ransac algorithm is proposed. This method can handle signal loss and mutations in signal segments. (3) We develop an optimized weld deviation detection method by combining the mathematical model of magnetically controlled arc oscillation and the mathematical model of droplet transition size and frequency under the action of an alternating magnetic field, which ensures accurate detection of weld seam deviation.

2 Arc sensor design

2.1 The structure and working principle of the sensor

The arc sensor is a crucial component of the weld seam tracking system, as it directly affects the accuracy of the tracking. To sense the weld seam based on arc signals, we designed a magnetically controlled arc sensor, as shown in Fig. 3.

Fig. 3
figure 3

Structure of the sensor

The sensor consists of a top cap, magnetic conductive studs, excitation coils, a center cylinder, a bottom cap, magnetic conductive heads, and fixed parts. Two magnetic conductive studs, wound with excitation coils, are symmetrically placed on either side of the central cylinder and secured in place by the top and bottom caps. The sensor is attached to the welding torch via the central cylinder and the fixed parts. In the sensing process, the arc is deflected by the magnetic force. Under the action of an alternating magnetic field, the arc oscillates on the normal plane of the welding direction to obtain information on the weld seam. The calculation of weld deviation is done by comparing voltage changes during scanning.

2.2 Parameters design

The relationship between the voltage and the magnetic flux can be expressed as Eq. (1):

$$\mathrm{U}=\mathrm{N}\frac{\mathrm{d\varphi }}{\mathrm{dt}}$$
(1)

The variation of the magnetic flux can be expressed as Eq. (2):

$$\mathrm{\Delta \varnothing }=\frac{1}{\mathrm{N}}{\int }_{0}^{{\mathrm{t}}_{\mathrm{on}}}\mathrm{Udt}$$
(2)

In order to prevent magnetic saturation of the magnetic core, the maximum allowable magnetic flux change is shown in Eq. (3):

$${\mathrm{\Delta \varnothing }}_{\mathrm{max}}=\left[{\mathrm{B}}_{\mathrm{max}}-(-{\mathrm{B}}_{\mathrm{max}})\right]\cdot \mathrm{S}=2{\mathrm{B}}_{\mathrm{max}}\mathrm{S}$$
(3)

Let \(\Delta \mathrm{\varnothing }=\Delta {\mathrm{\varnothing }}_{\mathrm{max}}\) in the time of \({\mathrm{t}}_{\mathrm{on}}\), Eq. (4) is obtained:

$${\mathrm{N}}_{\mathrm{min}}=\frac{\mathrm{U}\cdot {\mathrm{t}}_{\mathrm{on}}}{2{\mathrm{B}}_{\mathrm{max}}\bullet \mathrm{S}}\bullet {10}^{2}$$
(4)

where \(\mathrm{U}\) is the coil winding voltage; \(\mathrm{N}\) is the number of turns of the coil winding; \(\Delta \mathrm{\varnothing }\) is the variation of the magnetic flux; \({\mathrm{t}}_{\mathrm{on}}\) is the duration of the rectangular pulse voltage on the coil; \({\mathrm{B}}_{\mathrm{max}}\) is the maximum working magnetic flux density; \(\mathrm{S}\) is the effective cross-sectional area of the magnetic core.

Verify by calculating Eqs. (1)–(4), the specific parameters are shown in Table 1.

Table 1 Parameters of the arc sensor

2.3 Excitation current coding

During the arc oscillation process, the equal time interval results in no positioning information of the sampling signal, which poses a challenge in identifying the weld seam deviation.

Therefore, this paper proposes an excitation current coding method that is compatible with the magnetically controlled arc sensor. The computer sends out a coded signal to control the excitation power supply to produce the excitation current, and a coded magnetic field is generated through the excitation coil. This field controls the arc to achieve different amplitudes of oscillation during the signal acquisition cycle, enabling positioning signal acquisition by scanning the weld for information. The excitation current sequence and arc oscillation position are shown in Fig. 4.

Fig. 4
figure 4

The excitation current sequence and arc oscillation position

The excitation current could be calculated by Eq. (5):

$${\mathrm{I}}_{\mathrm{i}}=\left\{\begin{array}{c}\begin{array}{cc}\frac{{\mathrm{I}}_{\mathrm{max}}\mathrm{i}}{\mathrm{n}}& \mathrm{i}=\text{0,1,}\cdots ,\mathrm{n}-\text{1,}\mathrm{n}\dots \dots \dots \dots .\dots .\\ \frac{{\mathrm{I}}_{\mathrm{max}}\left(2\mathrm{n}-\mathrm{i}\right)}{\mathrm{n}}& \mathrm{i}=\mathrm{n}+1,\cdots ,2\mathrm{n}-\mathrm{1,2n}\dots .\dots \dots .\end{array}\\ \begin{array}{cc}\frac{{\mathrm{I}}_{\mathrm{max}}(\mathrm{i}-2\mathrm{n})}{\mathrm{n}}& \mathrm{i}=2\mathrm{n}+\mathrm{1,2n}+2,\cdots ,3\mathrm{n}-\text{1,3}\mathrm{n}\\ \frac{{\mathrm{I}}_{\mathrm{max}}(4\mathrm{n}-\mathrm{i})}{\mathrm{n}}& \mathrm{i}=3\mathrm{n}+\mathrm{1,3n}+2,\cdots ,4\mathrm{n}-\mathrm{1,4n}\end{array}\end{array}\right.$$
(5)

where \(\mathrm{i}\) is the coding serial number of excitation current; \({\mathrm{I}}_{\text{max}}\) is the maximum excitation current; \({\mathrm{I}}_{\mathrm{i}}\) is the excitation current at the \(\#\mathrm{i}\) coded position; \(\mathrm{n}\) is the excitation current gradient number.

The duration of the excitation current at each coded position could be calculated by Eq. (6):

$${\mathrm{t}}_{\mathrm{i}}=\frac{1}{4\mathrm{fn}}$$
(6)

where \({\mathrm{t}}_{\mathrm{i}}\) is the duration of the excitation current; \(\mathrm{f}\) is the arc oscillation frequency.

3 Arc signal processing and weld deviation identification

3.1 Arc signal processing

Arc signal processing is the basis for weld deviation identification. This study divides arc signal processing into the following steps:

3.1.1 Establishing a simplified model of arc scanning welds

The arc signal acquired by the sensor contains multiple pieces of information. The weld seam information is what we need. But there is also interference from the droplets, which can complicate the arc signal from being directly usable. In order to identify the interference information, we use the Ransac algorithm to preprocess the arc signal and obtain a smooth curve. The slope discrimination method is then applied to determine whether there is a gap in the weld and, if so, the coded sequence in which the gap is located.

A simplified model of arc scanning welds is established. The model simplifies the complex positional relationship between the welding torch and the weld seam into a bar graph and does the same for the welding torch and the weld gap, as shown in Fig. 5. This simplified model allows us to intuitively determine the weld deviation by comparing the sum of the areas on both sides of the #n sequence.

Fig. 5
figure 5

Positional relationship between the welding torch and the weld seam and the welding torch. a Under the condition of no gap, the relative position between the welding torch and weld seam changes from centering to left deviation. b Under the condition of the gap, the relative position between the welding torch and weld seam changes from centering to left deviation

3.1.2 Method of arc signal compensation

With the help of the simplified model of arc-scanning welds, it can be seen that since the welding wire is always aligned with the welding torch, the center of the welding wire is always at the position of \(\#\mathrm{kn}[\mathrm{k}=\mathrm{1,3},5,\dots ,2\mathrm{x}-1]\) in the coded sequence. Thus, in the weld seam without a gap, weld deviation calculation can be performed directly after eliminating the influence sequence of the droplet. However, in the weld seam with a gap, the arc signal at the gap is not available for calculation. When there is an intersection between the weld gap interference position and the droplet interference position, the influence sequence of the droplet cannot be simply eliminated, which will reduce the accuracy of weld tracking. To address this, we need to compensate for the coded sequences affected by the droplets.

As can be seen from the simplified model of arc-scanning welds, the relative position of the coded sequence affected by the weld gap and the coded sequence affected by the droplet is divided into the following four main categories: irrelevant; adjacent; intersecting, and overlapping. The flow of arc signal compensation is shown in Fig. 6.

Fig. 6
figure 6

Flow of arc signal compensation

For the “irrelevant” situation, the average value of \({\mathrm{V}}_{\mathrm{p}}\) and \({\mathrm{V}}_{\mathrm{f}}\) can be simply taken as the compensation value \({\mathrm{V}}_{\mathrm{d}}\).

For the “adjacent” situation, since one of the adjacent front or rear sections is affected by the weld gap, the affected one cannot be used to obtain the average value. \({\mathrm{V}}_{\mathrm{pp}}\) or \({\mathrm{V}}_{\mathrm{ff}}\) can be directly taken as the compensation value \({\mathrm{V}}_{\mathrm{d}}\).

For the “intersection” situation, only the non-overlapping part needs to be compensated. We predict the compensation value of the non-overlapping part by using the extension line of the fitting curve.

For the “coincidence” situation, the average of \({\mathrm{V}}_{\mathrm{p}}\) and \({\mathrm{V}}_{\mathrm{f}}\) can be simply taken as the compensation value \({\mathrm{V}}_{\mathrm{d}}\).

To describe this complete process, the following terms are defined:

\(\mathrm{polyU}[\mathrm{i}]\) the arc signal in the \(\#\mathrm{i}\) arc scanning period after the Ransac fitting

\({\mathrm{V}}_{\mathrm{left}}\) the sum of voltage on the left oscillation.

\({\mathrm{V}}_{\mathrm{right}}\) the sum of voltage on the right oscillation.

\(\mathrm{V}[\mathrm{i}]\) the voltage corresponding to the sequence number.

\(\mathrm{offset}\) the weld deviation

\({\mathrm{V}}_{\mathrm{p}}\) the arc voltage value of the adjacent equal volume coding sequence segment before the sequence segment that is disturbed by the droplet.

\({\mathrm{V}}_{\mathrm{f}}\) the arc voltage value of the adjacent equal volume coding sequence segment after the sequence segment that is disturbed by the droplet.

\({\mathrm{V}}_{\mathrm{a}}\) the preset threshold voltage.

\({\mathrm{V}}_{\mathrm{pp}}\) the arc voltage value of the adjacent equal volume coding sequence segment before the sequence segment that is disturbed by the weld gap.

\({\mathrm{V}}_{\mathrm{ff}}\) the arc voltage value of the adjacent equal volume coding sequence segment after the sequence segment that is disturbed by the weld gap.

\({\mathrm{V}}_{\mathrm{d}}\) the compensation value of the disturbed sequence voltage.

\({\mathrm{n}}_{\mathrm{sf}}\) the starting sequence number of the coded sequence segment occupied by the weld gap in the first half cycle

\({\mathrm{n}}_{\mathrm{mf}}\) the middle sequence number of the coded sequence segment occupied by the weld gap in the first half cycle

\({\mathrm{n}}_{\mathrm{ef}}\) the ending sequence number of the coded sequence segment occupied by the weld gap in the first half cycle

\({\mathrm{n}}_{\mathrm{ss}}\) the starting sequence number of the coded sequence segment occupied by the weld gap in the second half cycle

\({\mathrm{n}}_{\mathrm{ms}}\) the middle sequence number of the coded sequence segment occupied by the weld gap in the second half cycle

\({\mathrm{n}}_{\mathrm{es}}\) the ending sequence number of the coded sequence segment occupied by the weld gap in the second half cycle

The pseudocode of the algorithm is as follows:

figure a

3.2 Identification of weld seam deviation

The mathematical model of magnetically controlled arc oscillating could be calculated by Eq. (7):

$$\updelta =\frac{{\mathrm{E}}_{\mathrm{z}}-\frac{1}{2\mathrm{nq}}\frac{\mathrm{dp}}{\mathrm{dz}}}{-\upeta \frac{\mathrm{dp}}{\mathrm{dz}}\bullet {\uprho }_{\mathrm{g}}}\bullet {\mathrm{B}}_{\mathrm{x}}\bullet \mathrm{z}$$
(7)

The mathematical model of droplet transition size and frequency under the action of an alternating magnetic field could be calculated by Eqs. (8) and (9):

$$\mathrm{m}\frac{{\mathrm{d}}^{2}{\mathrm{x}}_{\mathrm{e}}}{{\mathrm{dt}}^{2}}+{\mathrm{kx}}_{\mathrm{e}}+\mathrm{c}\frac{{\mathrm{dx}}_{\mathrm{e}}}{\mathrm{dt}}={\mathrm{F}}_{0}$$
(8)
$$\Delta \mathrm{m}={\uplambda }_{\mathrm{B}}\bullet\uplambda {\mathrm{m}}_{\mathrm{c}}{\mathrm{v}}_{\mathrm{c}}$$
(9)

where \({\mathrm{E}}_{\mathrm{z}}\) is the vertical electric field strength; \(\mathrm{q}\) is the electronic charge; \(\mathrm{n}\) is the electron density; \(\mathrm{p}\) is the total pressure; \(\upeta\) is the plasma resistivity; \(\mathrm{z}\) is the arc length; \({\mathrm{B}}_{\mathrm{x}}\) is the magnetic field strength in the forward direction of the welding torch; \({\uprho }_{\mathrm{g}}\) is the protective airflow density; \(\mathrm{m}\) is the droplet mass; \(\mathrm{c}\) is the damping coefficient; \(\mathrm{k}\) is the elastic coefficient; \({\mathrm{F}}_{0}\) is the external force on the droplet; \({\mathrm{m}}_{\mathrm{c}}\) is the critical mass at which the droplet falls; \({\mathrm{v}}_{\mathrm{c}}\) is the critical velocity of the droplet at the end of the wire; \({\mathrm{x}}_{\mathrm{e}}\) is the vertical displacement of the droplet.

Establish the mathematical relationship between the arc length, arc oscillation amplitude, arc oscillation angle, and workpiece bevel angle. A schematic diagram of the mathematical relationship is shown in Fig. 7.

Fig. 7
figure 7

Schematic diagram of the mathematical relationship

The arc oscillation amplitude \(\mathrm{w}\) could be calculated by Eqs. (10) and (11):

$$\uptheta =\mathrm{arctan}\frac{\updelta }{\mathrm{z}}$$
(10)
$$\mathrm{w}=\left\{\begin{array}{cc}2\updelta & \mathrm{\alpha }=\uppi /2\\ \frac{2\mathrm{\delta tan\alpha }}{\mathrm{tan\theta }+\mathrm{tan\alpha }}& 0\ll \mathrm{\alpha }<\uppi /2\end{array}\right.$$
(11)

where \(2\mathrm{\alpha }\) is the workpiece bevel angle; \(\uptheta\) is the angle between the arc and the vertical position when the arc oscillates to the limit position; \(\mathrm{z}\) is the vertical distance between the tip of the tungsten electrode and the workpiece.

For a wire with a diameter of \({\mathrm{d}}_{\mathrm{w}}\), the half of the coded sequence that traverses could be calculated by Eq. (12):

$$\mathrm{x}=\frac{{\mathrm{d}}_{\mathrm{w}}}{\mathrm{w}}\bullet \mathrm{n}$$
(12)

That is, the coded sequence disturbed by the welding wire of diameter \(\mathrm{d}\) is \([\mathrm{kn}-\mathrm{x},\mathrm{kn}+\mathrm{x}],\mathrm{k}=\mathrm{1,3},5,\dots ,2\mathrm{n}-1\).

3.2.1 When there is no gap in the weld seam

When there is no gap in the weld seam, the deviation of the weld seam is calculated once during each oscillation period. After the voltage signal eliminates the interference of the welding wire and the droplet, the left and right deviation of the weld could be calculated by Eqs. (13), (14), and (15):

$${\mathrm{V}}_{1}=\frac{{\sum }_{\mathrm{i}=1}^{\mathrm{n}-\mathrm{x}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}=3\mathrm{n}+\mathrm{x}}^{4\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(13)
$${\mathrm{V}}_{2}=\frac{{\sum }_{\mathrm{i}=\mathrm{n}+\mathrm{x}}^{3\mathrm{n}-\mathrm{x}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(14)
$$\mathrm{D}={\mathrm{V}}_{1}-{\mathrm{V}}_{2}$$
(15)

When a droplet is generated, half of the sequence of the droplet interference with a diameter of \({\mathrm{d}}_{\mathrm{d}}\) could be calculated by Eq. (16):

$$\mathrm{x}=2.5\frac{{\mathrm{d}}_{\mathrm{d}}}{\mathrm{w}}\bullet \mathrm{n}$$
(16)

where \({\mathrm{V}}_{1}\) is the equivalent voltage on the left side of the weld; \({\mathrm{V}}_{2}\) is the equivalent voltage on the right side of the weld; \(|\mathrm{D}|\) is the weld deviation;

If \(\mathrm{D}<0\), the weld deviation is to the left;

If \(\mathrm{D}>0\), the weld deviation is to the right;

If \(\mathrm{D}=0\), there is no weld deviation.

The larger the \(|\mathrm{D}|\), the greater the weld deviation.

Record the initial arc length \({\mathrm{H}}_{\mathrm{s}}\) in the first oscillation cycle at the beginning of Eq. (17):

$$\mathrm{H}=\frac{{\sum }_{\mathrm{i}=1}^{\mathrm{n}-\mathrm{x}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{n}+\mathrm{x}}^{3\mathrm{n}-\mathrm{x}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{3\mathrm{n}+\mathrm{x}}^{4\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{4\mathrm{n}}$$
(17)

In the welding process, the arc length \(\mathrm{H}\) is calculated for every oscillation cycle. The welding torch height deviation \(\mathrm{\Delta H}=\mathrm{H}-{\mathrm{H}}_{\mathrm{S}}\).

If \(\mathrm{\Delta H}>0\), the welding torch is high;

If \(\mathrm{\Delta H}<0\), the welding torch is low;

The greater the \(|\mathrm{\Delta H}|\), the greater the deviation of the height.

3.2.2 When there is a gap in the weld seam

When there is a gap in the weld seam, the coded sequence segment occupied by the gap is determined by the change of the slope after the arc signal is compensated. Mark \({\mathrm{n}}_{\mathrm{sf}}\), \({\mathrm{n}}_{\mathrm{mf}}\), \({\mathrm{n}}_{\mathrm{ef}}\), \({\mathrm{n}}_{\mathrm{ss}}\), \({\mathrm{n}}_{\mathrm{ms}}\), \({\mathrm{n}}_{\mathrm{es},}\) and compare the sizes of \(\mathrm{n}/2\), \(\mathrm{n}\), \(3\mathrm{n}/2\), \({\mathrm{n}}_{\mathrm{sf}}\), \({\mathrm{n}}_{\mathrm{ef}}\), \({\mathrm{n}}_{\mathrm{ss}}\), and \({\mathrm{n}}_{\mathrm{es}}\).

The size relationship is mainly divided into three categories, as shown in Fig. 8:

Fig. 8
figure 8

The size relationship between \(\mathrm{n}/2\), \(\mathrm{n}\), \(3\mathrm{n}/2\), \({\mathrm{n}}_{\mathrm{sf}}\), \({\mathrm{n}}_{\mathrm{ef}}\), \({\mathrm{n}}_{\mathrm{ss}}\), and  \({\mathrm{n}}_{\mathrm{es}}\)

The left and right deviations of the weld seam could be calculated by Eqs. (18), (19), and (24) in case (a); Eq. (20), (21), and (24) in case (b); Eq. (22), (23), and (24) in case (c).

$${\mathrm{V}}_{1}=\frac{{\sum }_{\mathrm{i}=1}^{{\mathrm{i}=\mathrm{n}}_{\mathrm{sf}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{ef}}}^{\mathrm{i}=\frac{\mathrm{n}}{2}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}=1.5\mathrm{n}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{ss}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{es}}}^{\mathrm{i}=2\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(18)
$${\mathrm{V}}_{2}=\frac{{\sum }_{\mathrm{i}=\frac{\mathrm{n}}{2}}^{\mathrm{i}=1.5\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(19)
$${\mathrm{V}}_{1}=\frac{{\sum }_{\mathrm{i}=1}^{{\mathrm{i}=\mathrm{n}}_{\mathrm{sf}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{es}}}^{\mathrm{i}=2\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(20)
$${\mathrm{V}}_{2}=\frac{{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{ef}}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{ss}}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(21)
$${\mathrm{V}}_{1}=\frac{{\sum }_{\mathrm{i}=1}^{\mathrm{i}=\frac{\mathrm{n}}{2}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}=1.5\mathrm{n}}^{\mathrm{i}=2\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(22)
$${\mathrm{V}}_{2}=\frac{{\sum }_{\mathrm{i}=\frac{\mathrm{n}}{2}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{sf}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{ef}}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{ss}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{es}}}^{\mathrm{i}=1.5\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}}{\mathrm{n}}$$
(23)
$$\mathrm{D}={\mathrm{V}}_{1}-{\mathrm{V}}_{2}$$
(24)

Record the initial length of the arc \({\mathrm{H}}_{\mathrm{s}}\) in the first oscillation cycle at the beginning by Eq. (25):

$${\mathrm{H}}_{\mathrm{s}}={\sum }_{\mathrm{i}=1}^{\mathrm{i}=2\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}$$
(25)

In the welding process, the arc length \(\mathrm{H}\) is calculated for every oscillation cycle by Eq. (26):

$$\mathrm{H}={\sum }_{\mathrm{i}=1}^{\mathrm{i}={\mathrm{n}}_{\mathrm{sf}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{ef}}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{ss}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{es}}}^{\mathrm{i}=2\mathrm{n}}{\mathrm{v}}_{\mathrm{i}}$$
(26)

The welding torch height deviation \(\mathrm{\Delta H}=\mathrm{H}-{\mathrm{H}}_{\mathrm{S}}^{\mathrm{^{\prime}}}\). \({\mathrm{H}}_{\mathrm{S}}^{\mathrm{^{\prime}}}\) would be calculated by Eq. (27):

$${\mathrm{H}}_{\mathrm{s}}^{\mathrm{^{\prime}}}={\mathrm{H}}_{\mathrm{S}}-{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{sf}}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{ef}}}{\mathrm{v}}_{\mathrm{i}}+{\sum }_{\mathrm{i}={\mathrm{n}}_{\mathrm{ss}}}^{\mathrm{i}={\mathrm{n}}_{\mathrm{es}}}{\mathrm{v}}_{\mathrm{i}}$$
(27)

If \(\mathrm{\Delta H}>0\), the welding torch is high, if \(\mathrm{\Delta H}<0\), the welding torch is low; The greater the \(|\mathrm{\Delta H}|\), the greater the deviation of the height.

3.3 Fuzzy controller for weld seam tracking

Due to welding deformation, workpiece shaking, and other factors, the weld trajectory will deviate and the weld gap will change in real time. In order to avoid welding defects such as off-set welding, this paper designs a weld seam tracking controller. The PID controller is chosen due to its simple algorithm, good stability, and effectiveness in controlling linear steady-state systems. The expression of the discrete PID is shown in Eqs. (28) and (29):

$$\mathrm{u}(\mathrm{k})={\mathrm{k}}_{\mathrm{p}}(\mathrm{e}(\mathrm{k})+{\mathrm{k}}_{\mathrm{i}}{\sum }_{\mathrm{j}=0}^{\mathrm{k}}\mathrm{e}(\mathrm{j})+{\mathrm{k}}_{\mathrm{d}}(\mathrm{e}(\mathrm{k})-\mathrm{e}(\mathrm{k}-1)))$$
(28)
$$\mathrm{u}(\mathrm{k}-1)={\mathrm{k}}_{\mathrm{p}}(\mathrm{e}(\mathrm{k}-1)+{\mathrm{k}}_{\mathrm{i}}{\sum }_{\mathrm{j}=0}^{\mathrm{k}-1}\mathrm{e}(\mathrm{j})+{\mathrm{k}}_{\mathrm{d}}(\mathrm{e}(\mathrm{k}-1)-\mathrm{e}(\mathrm{k}-2)))$$
(29)

The expression of incremental PID is shown in Eqs. (30) and (31):

$$\mathrm{\Delta u}\left(\mathrm{k}\right)=\mathrm{u}\left(\mathrm{k}\right)-\mathrm{u}\left(\mathrm{k}-1\right)={\mathrm{q}}_{0}\cdot \mathrm{e}\left(\mathrm{k}\right)+{\mathrm{q}}_{1}\cdot \mathrm{e}\left(\mathrm{k}-1\right)+{\mathrm{q}}_{2}\cdot \mathrm{e}\left(\mathrm{k}-2\right)$$
(30)
$$\left\{\begin{array}{c}{\mathrm{q}}_{0}={\mathrm{K}}_{\mathrm{p}}\cdot \left[1+\frac{{\mathrm{T}}_{\mathrm{S}}}{{\mathrm{T}}_{1}}+\frac{{\mathrm{T}}_{\mathrm{D}}}{{\mathrm{T}}_{\mathrm{S}}}\right]\\ {\mathrm{q}}_{1}=-{\mathrm{K}}_{\mathrm{p}}\cdot \left[1+2\cdot \frac{{\mathrm{T}}_{\mathrm{D}}}{{\mathrm{T}}_{\mathrm{S}}}\right]\\ {\mathrm{q}}_{2}={\mathrm{K}}_{\mathrm{p}}\cdot \frac{{\mathrm{T}}_{\mathrm{D}}}{{\mathrm{T}}_{\mathrm{S}}}\end{array}\right.$$
(31)

In the welding process, the workpiece will produce unpredictable thermal deformation or even random shaking, making it imperative for the weld tracking system to be capable of adapting to complex working conditions characterized by time variability and nonlinearity. The traditional PID controller is difficult to adapt to the system control of different weld deviation adjustment in the tracking process of root pass welding with a variable gap. In order to meet the requirements of different weld seam deviation \(\mathrm{e}\) and seam deviation change rate \(\mathrm{ec}\) for the self-tuning of PID parameters, this paper uses two-dimensional fuzzy control rules to tune PID parameters \(\left({\mathrm{K}}_{\mathrm{p}},{\mathrm{K}}_{\mathrm{i}},{\mathrm{K}}_{\mathrm{d}}\right)\) online. The parameters fuzzy self-tuning seam tracking PID controller is designed, as shown in Fig. 9.

Fig. 9
figure 9

The parameters fuzzy self-tuning seam tracking PID controller

On the basis of PID control, the fuzzy controller makes the control parameters \({\mathrm{K}}_{\mathrm{p}}, {\mathrm{K}}_{\mathrm{i}}{,\mathrm{ K}}_{\mathrm{d}}\) become the best values by self-tuning PID parameters through fuzzy rules [32]. First, find out the fuzzy relationship between \({\mathrm{K}}_{\mathrm{p}}, {\mathrm{K}}_{\mathrm{i}}{,\mathrm{ K}}_{\mathrm{d}},\mathrm{ e},\mathrm{ ec}\). Then, in the welding process, the alternating magnetic field controls the arc oscillate to detect \(\mathrm{e}\) in real time. And \(\mathrm{ec}\) will be calculated by Eq. (32):

$$\mathrm{ec}(\mathrm{k})=\mathrm{e}(\mathrm{k})-\mathrm{e}(\mathrm{k}-1)$$
(32)

Fuzzy control rules are used to adjust \({\mathrm{K}}_{\mathrm{p}}, {\mathrm{K}}_{\mathrm{i}}{,\mathrm{ K}}_{\mathrm{d}}\) online. While realizing the online adaptive tuning of PID parameters, it meets the dynamic performance requirements of weld tracking robot control.

The PID parameters \({\mathrm{K}}_{\mathrm{p}}, {\mathrm{K}}_{\mathrm{i}}{,\mathrm{ K}}_{\mathrm{d}}\) are adjusted online according to the fuzzy rules, and the adjustment equations [33] are as follows:

$${\mathrm{K}}_{\mathrm{p}}={\mathrm{k}}_{\mathrm{p}}+\Delta {\mathrm{k}}_{\mathrm{p}}$$
(33)
$${\mathrm{K}}_{\mathrm{i}}={\mathrm{k}}_{\mathrm{i}}+\Delta {\mathrm{k}}_{\mathrm{i}}$$
(34)
$${\mathrm{K}}_{\mathrm{d}}={\mathrm{k}}_{\mathrm{d}}+\Delta {\mathrm{k}}_{\mathrm{d}}$$
(35)

where \({\mathrm{k}}_{\mathrm{p}}, {\mathrm{k}}_{\mathrm{i}},{\mathrm{k}}_{\mathrm{d}}\) are the preset values of the PID control system; \(\Delta {\mathrm{k}}_{\mathrm{p}},\Delta {\mathrm{k}}_{\mathrm{i}},\mathrm{ \Delta }{\mathrm{k}}_{\mathrm{d}}\) are the variable values tuned online by fuzzy rules; \({\mathrm{K}}_{\mathrm{p}}, {\mathrm{K}}_{\mathrm{i}},{\mathrm{K}}_{\mathrm{d}}\) are the optimized parameters for the PID controller.

4 Experiment

4.1 Experiment system

The system used in this study is composed of a computer, robot system, magnetically controlled arc sensor, and welding equipment, as shown in Fig. 10.

Fig. 10
figure 10

The experiment system

The robot system has three degrees of freedom. The X-axis sliding module moves the welding torch along the welding direction. The Y-axis and Z-axis sliding modules align the welding torch with the weld seam. The moving resolution of the welding torch in the X, Y, and Z direction is 50 pulses/mm. Magnetically controlled arc sensor is used to obtain the arc signal containing weld seam information. The computer runs the main program and performs complex calculations. Send the weld deviation to the robot controller, when the calculation is done. The welding equipment consists of a welding power supply, welding torch, water cooling device, wire feeder, and shielding gas. The weld seam tracking process and the respective functions of the components of the experiment system are shown in Fig. 11.

Fig. 11
figure 11

The weld seam tracking process and the respective functions of the components of the experiment system

4.2 Arc oscillation experiment

In order to verify the stability of the arc oscillation controlled by the arc sensor, the arc oscillation test was performed for the GTAW arc in axial lengths of 13 mm, 17 mm, and 21 mm, respectively.

In the welding process, the excitation coil applies a coding current of \({\mathrm{I}}_{\mathrm{max}}\) = 6A, \(\mathrm{n}\) = 100. The two excitation coils apply coding current with an alternating frequency of 10 Hz. When \({\mathrm{I}}_{\mathrm{i}}={\mathrm{I}}_{\mathrm{max}}\), a magnetic field with a maximum value of 2 mT is generated at the tungsten pole. During the implementation of the coding current, various coded gradients are used to generate different excitation currents, which, in turn, create magnetic fields of varying strengths to control the arc oscillation to different positions. To capture the oscillation of the arc during this process, a high-speed camera is employed. As shown in Fig. 12, the arc oscillates significantly and symmetrically, meeting the requirements of weld seam tracking.

Fig. 12
figure 12

Oscillation of the arc of different length: a 13 mm, b 17 mm, and c 21 mm

4.3 Weld seam tracking experiment

4.3.1 Workpiece and welding parameters

In order to verify the performance of the weld seam tracking method, the tracking experiment is carried out on fillet weld, butt weld, and lap weld with variable gap using the experiment system platform shown in Fig. 10. The engineering schematic diagram of the three workpieces is shown in Fig. 13. The welding experiment parameters are shown in Table 2.

Fig. 13
figure 13

Schematic diagram of the workpiece cross-section

Table 2 The welding experiment parameters

4.3.2 Arc signal processing process and results

In the welding process, the maximum excitation current \({\mathrm{I}}_{\mathrm{max}}=6\mathrm{A}\) and the excitation current gradient \(\mathrm{n}=100\). The arc signal is acquired at every coded sequence, and the weld deviation is identified at every oscillation period. However, the sampling signal is often affected by high-frequency interference, droplet interference, and weld gap interference, which can greatly affect the accuracy of weld deviation calculation. To address these issues, the signal processing methods proposed herein mitigate the impact of these interferences on the calculation. The signal processing flow in the welding is shown in Fig. 14.

Fig. 14
figure 14

The signal processing flow

The original signal collected by the arc sensor is shown in Fig. 14a. The signal processed by the Gaussian low-pass filter is shown in the Fig. 14b. Figure 14c shows the arc signal after being fitted by the Ransac algorithm, and the segment of the coded sequence affected by the droplet is determined by the slope. The affected coded sequence segments are circled by the red dotted line. Figure 14d shows the arc signal after compensation, and \({\mathrm{n}}_{\mathrm{sf}}, {\mathrm{n}}_{\mathrm{mf}}, {\mathrm{n}}_{\mathrm{ef}}, {\mathrm{n}}_{\mathrm{ss}}, {\mathrm{n}}_{\mathrm{ms}}, {\mathrm{ n}}_{\mathrm{es}}\) are marked. The welding signal after compensation is used to calculate the weld deviation and track the weld seam.

4.3.3 Weld seam tracking results and analysis

The weld seam tracking results are shown in Fig. 15. From the analysis of the weld surface, there is no obvious off-set welding. Moreover, with the increase of the weld gap, the weld also widens.

Fig. 15
figure 15

Welding effect

In order to verify the tracking accuracy of the weld seam tracking method, the error analysis is carried out. Before welding, track the weld seam by teaching-playback method and record the coordinates \(({\mathrm{X}}_{\mathrm{t},\mathrm{i}},{\mathrm{Y}}_{\mathrm{t},\mathrm{i}},{\mathrm{Z}}_{\mathrm{t},\mathrm{i}})\) of the weld trajectory. Record weld trajectory coordinates \(({\mathrm{X}}_{\mathrm{c},\mathrm{i}},{\mathrm{Y}}_{\mathrm{c},\mathrm{i}},{\mathrm{Z}}_{\mathrm{c},\mathrm{i}})\) during the tracking process and calculate the tracking error by Eq. (36):

$$\left\{\begin{array}{c}{\mathrm{Y}}_{\mathrm{E}}=\left|{\mathrm{Y}}_{\mathrm{c},\mathrm{i}}-{\mathrm{Y}}_{\mathrm{t},\mathrm{i}}\right|\\ {\mathrm{Z}}_{\mathrm{E}}=\left|{\mathrm{Z}}_{\mathrm{c},\mathrm{i}}-{\mathrm{Z}}_{\mathrm{t},\mathrm{i}}\right|\end{array}\right.$$
(36)

The tracking errors of butt weld, lap weld, and fillet weld with variable gaps are shown in Fig. 16. The maximum error (ME) and mean square error (MSE) of tracking could be calculated by Eqs. (37) and (38):

Fig. 16
figure 16

The tracking errors

$$\left\{\begin{array}{c}{\mathrm{Y}}_{\mathrm{MSE}}=\sqrt{\frac{{\sum }_{\mathrm{i}=1}^{\mathrm{n}}({\mathrm{Y}}_{\mathrm{c},\mathrm{i}}-{\mathrm{Y}}_{\mathrm{t},\mathrm{i}}{)}^{2}}{\mathrm{n}}}\\ {\mathrm{Z}}_{\mathrm{MSE}}=\sqrt{\frac{{\sum }_{\mathrm{i}=1}^{\mathrm{n}}({\mathrm{Z}}_{\mathrm{c},\mathrm{i}}-{\mathrm{Z}}_{\mathrm{t},\mathrm{i}}{)}^{2}}{\mathrm{n}}}\end{array}\right.$$
(37)
$$\left\{\begin{array}{c}{\mathrm{Y}}_{\mathrm{ME}}=\underset{\mathrm{i}\in [1,\mathrm{n}]}{\mathrm{MAX}}\left|{\mathrm{Y}}_{\mathrm{c},\mathrm{i}}-{\mathrm{Y}}_{\mathrm{t},\mathrm{i}}\right|\\ {\mathrm{Z}}_{\mathrm{ME}}=\underset{\mathrm{i}\in [1,\mathrm{n}]}{\mathrm{MAX}}\left|{\mathrm{Z}}_{\mathrm{c},\mathrm{i}}-{\mathrm{Z}}_{\mathrm{t},\mathrm{i}}\right|\end{array}\right.$$
(38)

The calculated errors are shown in Table 3. From Table 3, it can be seen that the maximum error of tracking is no more than 0.40 mm, which shows that this method can accurately and stably process the signal of variable gap weld and meet the requirements of real-time tracking of variable gap weld.

Table 3 The calculated errors

5 Conclusion

In this paper, a method of root pass weld seam tracking with variable gap based on a magnetically controlled arc sensor is proposed. It could be well applied to many kinds of welds with a variable gap under complicated working conditions, such as real-time changes in the weld gap and the interference of droplets. The main results of this paper are as follows:

  1. 1

    A coded magnetically controlled arc sensor is designed to achieve precise and stable arc oscillation, which is used to scan the weld seam. The sensor controls the arc to oscillate within a length of 13–17 mm, and the oscillation error is less than 1.6%.

  2. 2

    An arc signal compensation method of selectively taking the average based on the Ransac algorithm is proposed. This method can handle signal loss and mutations in signal segments. Combined with the simplified model of arc scanning welds, it can effectively overcome the interference of the sudden changes in gap width and the interference of droplets.

  3. 3

    Combined with the mathematical model of magnetically controlled arc oscillation and the mathematical model of droplet transition size and frequency under the action of an alternating magnetic field, an optimized weld deviation detection method is proposed. Weld deviation detection is performed using the compensated arc signal combined with the positioning information provided by the coding sequence of the excitation current. This method ensures the accuracy of weld deviation detection.

  4. 4

    The proposed method was tested to evaluate its detection performance under various working conditions, including fillet weld seams, butt weld seams, and lap weld seams with a variable gap. The test results demonstrated that the proposed method is effective in detecting weld deviation under variable gap conditions. Specifically, when testing with weld seams of 300 mm in length and weld gap angles ranging from 0 to 4°, the maximum detection errors in the Y-axis and Z-axis directions were 0.40 mm and 0.23 mm, respectively. These results show that the proposed method satisfies the precision requirements for practical welding applications.

  5. 5

    This method’s simple physical structure and stable recognition of weld deviation make it highly valuable for root pass weld tracking with a variable gap.