Abstract
For magnetically actuated robots driven by external magnetic sources (EMSs), rapid and stable localization of the internal permanent magnet (IPM) is essential for closed-loop control. Existing sensor-array-based localization methods require a fixed model with an offline-calibrated dipole moment to separate the magnetic field generated by the IPM from the measured total field. However, model accuracy varies with the distance to the sensor array, leading to inaccurate separation and unstable localization. Additionally, nonlinear optimization is typically used for localization with sensor arrays, which is computationally inefficient. We propose a sampling-based method that jointly estimates the dipole moments and the IPM position, thereby eliminating the need for magnetic field separation. Given the EMS positions and the measured total field, our particle importance analysis efficiently identifies the sampled particle that most closely approximates the dipole position and concurrently estimates the optimal dipole moments. Adaptive particle sampling enables high-accuracy localization using sparsely sampled particles, thereby improving computational efficiency. We validated the approach experimentally with EMSs actuated by manipulators and electromagnetic systems. With a 72-sensor array and the IPM located 20 cm above the sensor plane, the method achieved an average computation time of 1.2 ms and localization errors of 4.70 mm and 4.17°. Compared with an optimization-based method, our method reduced the maximum localization error by 59% and improved computational efficiency by a factor of 30. The method reliably localized in permanent magnet, electromagnetic, and hybrid magnetic fields. Finally, we applied the method to the simultaneous localization and actuation of a magnetic endoscope, validating its feasibility in a colon phantom.
1. Introduction
Magnetically actuated robotic systems have promising applications in medical examination and minimally invasive surgeries, with research demonstrating their feasibility in magnetic endoscopes (Taddese et al., 2018) and endovascular procedures (Von Arx et al., 2023). Such systems typically use external magnetic sources (EMSs) to actuate robots that contain an internal permanent magnet (IPM). The IPM is localized either by embedded sensors integrated into the robot or by external sensor arrays surrounding the workspace. Compared with embedded sensors, external sensor arrays enable more compact robot designs (Xu et al., 2022), improve scalability (Sun et al., 2025), and reduce on-board power consumption. However, external arrays demand computationally intensive processing, offer a limited effective sensing range, and rely on accurate calibration of the EMSs, which hinders their widespread adoption.
External sensor arrays typically measure the combined magnetic field generated by both the IPM and the EMSs, necessitating the separation of the IPM field for localization. Existing approaches often employ a dipole model with offline-calibrated magnetic moments (Son et al., 2018) to estimate the EMS field for this separation, as illustrated in Figure 1(a). However, since the accuracy of the model varies with distance (Petruska and Abbott, 2012), using a fixed dipole moment leads to inaccurate separation. Due to the substantial size difference between the EMS and the IPM, minor separation inaccuracies lead to significant localization errors. When the IPM is far from the sensor array, the separation error combined with disturbances leads to unstable localization performance. Moreover, with the expansion of sensor arrays and the increase in the number of sensors, commonly used nonlinear-optimization-based localization methods become computationally inefficient. The illustration of internal permanent magnet (IPM) localization under the effect of external magnetic sources (EMSs). (a) EMSs can be generated by permanent magnets (PM) or electromagnets (EM). Most existing methods require offline segmentation of the IPM magnetic field for localization, but inaccuracies in magnetic dipole moment calibration lead to segmentation errors. (b) Our method avoids the prior knowledge of the EMS moments, using particle sampling and importance analysis to simultaneously calibrate the dipole moments of magnets, and estimate the position and heading of the IPM.
We propose a fast sampling-based localization method that does not require prior knowledge of dipole moments, thereby reducing errors caused by inaccurate field separation. As shown in Figure 1(b), using only the measured magnetic field and the EMS positions, our importance analysis effectively identifies the optimal particle for IPM localization while simultaneously estimating the dipole moments of magnets. The main contributions of this article are as follows:
Importance Analysis: To eliminate reliance on prior knowledge of dipole moments during localization, we treat the dipole moments of both the IPM and EMSs as variables. Sampled particles with unknown moments represent the possible magnet positions in the workspace, and the total magnetic field is modeled as the sum of contributions from all particles. An error reduction ratio approach is then used to identify the most significant particle for IPM localization. Subsequently, for fast dipole moment calibration, we neglect insignificant particles in the model and apply orthogonal least squares to estimate the optimal dipole moments.
Adaptive Particle Sampling: The accuracy of sampling-based methods depends on sampling density and range, but dense sampling over large areas reduces computational efficiency. We propose an adaptive sampling method that begins with sparsely sampled particles across a wide area and dynamically adjusts the sampling range to maintain accuracy while improving efficiency. The method adapts by leveraging overall particle importance from the importance analysis to determine both the convergence direction and rate of the sampling range.
We evaluated the localization performance under the influence of EMSs at multiple distances between the IPM and the sensors. Our method achieves an average accuracy of 4.70 mm and 4.17° when the IPM is 20 cm from the sensor board, with an average computation time of only 1.2 ms. Additionally, we tested the method under permanent magnets, electromagnets, and hybrid magnetic fields. Our method can stably localize the IPM under these conditions while simultaneously estimating the dipole moments of the EMSs. Finally, phantom experiments were conducted to evaluate its performance in simultaneous localization and actuation for a soft endoscope.
The remainder of this article is organized as follows: Section 2 introduces the related work on magnetic localization. Section 3 presents our method, including details on importance analysis and adaptive sampling. In Section 4, we validate the method through simulations and experiments and evaluate its performance. Section 5 concludes the article and discusses future work.
2. Related work
2.1. Embedded and external sensor arrays
Embedded sensors and external sensor arrays are two commonly used sensing configurations in magnetic actuation systems. In the embedded sensor scheme, Hall sensors are placed near the internal permanent magnet (IPM) to measure its relative position with respect to external magnetic sources (EMSs) (Ciuti et al., 2011). To prevent the IPM field from dominating the sensor measurements, the sensor layout must be carefully designed. Some studies place compensating magnets near the sensors to offset the IPM’s magnetic field (Yim and Sitti, 2013), while more commonly, multiple single-axis sensors are deployed at specific locations where the internal magnetic field can be considered negligible (Popek et al., 2016). However, due to the concentrated distribution of sensors, embedded configurations often encounter regions with magnetic field singularities, which significantly degrade localization accuracy. To address this issue, Taddese et al. (2018) superimpose a time-varying magnetic field generated by electromagnets onto the static magnetic field to achieve nonsingular localization. In addition, to obtain global orientation information, Huang et al. (2024) employ Helmholtz coils to generate a uniform directional magnetic field that provides a determined heading angle. In scenarios involving multiple magnetic sources, the above methods do not generalize directly. da Veiga et al. (2023) and Pittiglio et al. (2022) employ a Kalman filter to localize the IPM when two permanent magnets actuate it. In navigation systems with multiple electromagnets, Von Arx et al. (2023) add an oscillating magnetic field onto the actuation field, enabling six-DoF localization using only Hall sensors.
Embedded sensors have been extensively studied and widely applied, yet they still require additional magnetic fields to resolve singularities. Moreover, embedded sensors fail to localize the IPM when the EMS field cannot be measured. External sensor arrays naturally provide global IPM localization regardless of EMS measurability. By collecting measurements from multiple points, they also avoid singularity issues. Sensor arrays further offer high scalability, enabling coverage of the entire human body (Xu et al., 2020) or integration into flexible substrates for in-body capsule tracking (Su et al., 2024b, 2024c). Despite these advantages, external sensor arrays have notable limitations. They use Hall sensors (Son et al., 2015) or magneto-inductive sensors (Watson and Morimoto, 2020) to measure the total magnetic field and rely on the IPM field for localization. The IPM field decays rapidly with distance (Su et al., 2017), making localization sensitive to environmental disturbances. Im et al. (2023) use differential measurements from two-layer arrays to mitigate the disturbances, and Shao and Guo (2019) optimize sensor placement based on signal-to-noise ratios. However, such specialized hardware designs reduce generality. Additionally, computational complexity grows as more sensors are involved (Xu et al., 2022). Optimized placement can reduce bulkiness (Song et al., 2017), but the number of sensors remains far higher than in embedded schemes. Zhang et al. (2023a) mount sensor arrays at the ends of external driving coils, allowing a small number of sensors to localize the IPM in large workspaces. However, this approach is unsuitable for permanent magnets due to sensor saturation. We therefore focus on generalizable localization methods for sensor arrays that achieve fast and stable IPM localization across various types of EMSs.
2.2. Magnetic localization algorithms
Gradient-based methods, including the Levenberg–Marquardt algorithm (LMA), are widely used for magnet localization with sensor arrays, where the magnet position is estimated by minimizing the discrepancy between measured and modeled fields (Wang et al., 2006). These methods are straightforward to construct and implement, but their stability depends on the accuracy of the initial guess (Song et al., 2016a, 2016b). Due to the high nonlinearity of the magnetic field model, a poor initial guess leads to local minima and significant localization errors. Inaccurate initialization also increases the number of iterations, causing variable computation times. Compared with gradient-based methods, heuristic optimization approaches such as particle swarm optimization (PSO) and whale optimization have stronger global search capabilities (Hu et al., 2009). However, when applied to sensor arrays, these methods are computationally expensive due to the large number of sensors and the high-dimensional search space. A common compromise is a hybrid strategy in which heuristics perform a global search for initialization, followed by refinement using LMA (Hu et al., 2010; Lv et al., 2021). While this balances global optimality and computation speed, it remains inefficient for large-scale sensor arrays and is sensitive to model errors and disturbances. Sampling-based methods, such as particle filtering, offer strong global search capabilities and robustness to disturbances (Taddese et al., 2018). However, they also struggle with sensor arrays and are better suited to embedded sensor schemes with fewer sensors. Selecting an optimal subset of sensors can reduce computation and improve efficiency (Xu et al., 2022), but this is ineffective when multiple external magnetic sources are present. Overall, existing methods face computational limitations for large sensor arrays, and errors in the magnetic field model lead to separation errors, resulting in unstable localization.
Magnetic field models based on the point-dipole assumption are widely used due to their computational efficiency, but their accuracy varies with sensor distance. Multipole models can significantly improve modeling accuracy, but they increase parameter complexity and require training on specially designed datasets (Charreyron et al., 2021). Analytical models derived from the Biot–Savart Law provide high precision, but the multiple integrals involved make real-time computation difficult (Zhang et al., 2023b). Using the Jacobian matrix of the magnetic field avoids the inaccuracy introduced by the dipole approximation, but the resulting large-scale matrix reduces computational efficiency when applied to sensor arrays (Di Natali et al., 2016). Learning-based methods have also been proposed to address these challenges. For example, backpropagation neural networks can directly map the relationship between the magnetic field and the magnet position. Fu et al. (2024) and Su et al. (2023) use two neural networks for magnet localization and theoretical model correction, while Su et al. (2024a) propose a self-supervised framework that separates the IPM-generated field under unpredictable interference. However, these approaches typically require offline training, making direct transfer to systems with different configurations difficult.
Summary of localization methods in magnetically actuated robots.
aUsing 8 out of the 80 magnetic sensors as a subarray for localization.
3. Method
This section introduces the problem and presents the proposed method, whose algorithmic framework is illustrated in Figure 2.
1
A summary of the principal symbols used in this section is provided in Table 2. The algorithm consists of adaptive sampling and importance analysis. It constructs a state matrix P using the positions of the sampled particles x
i
(Section 3.2). The proposed importance analysis evaluates the particle importance values List of symbols.
3.1. Problem formulation
The considered scenario consists of multiple external magnetic sources (EMSs), an internal permanent magnet (IPM), and an external sensor board, as illustrated in Figure 3. The EMSs generate magnetic fields using either permanent magnets (PMs) or electromagnets (EMs). In PM-based systems, field modulation is achieved through manipulator motion, whereas in EM-based systems it is realized by adjusting the coil current. The magnetization direction of each magnet is aligned with the x-axis of its body frame O
a
. The IPM, defined by the body frame O
c
, moves in response to the magnetic fields generated by the EMSs. A Hall-sensor-based board is placed beneath the IPM workspace to measure the total magnetic field B produced by both the EMSs and the IPM in real time. The coordinate frames of the EMSs, IPM, and sensor board are defined, and the positions and headings of both the IPM and EMS are expressed in the sensor frame Os. The x-axes of the magnets are defined as their heading directions, which align with their respective magnetic dipole moments.
This article assumes that the magnetic fields generated by the IPM and EMSs follow a point-dipole model, which has a form as
The relationship between the body frames of the IPM, EMS, and the sensor frame can be represented using a homogeneous transformation matrix,
The positions of the EMSs, denoted by x
a
, are obtained from the robot forward kinematics, while their dipole moments
3.2. Importance analysis
We propose a localization method that rapidly evaluates the contributions of randomly sampled particles to the measured magnetic field and estimates the IPM position based on their relative importance. We first describe the method for the single-magnet case. Random sampling is performed over the feasible space to generate n candidate dipole positions, and importance analysis is then used to evaluate their contributions to the measured magnetic field.
This process is shown in Figure 4(a), the black, red, and blue points are sampled within circular regions with radii of 5 mm, 10 mm, and 15 mm, respectively, from the actual dipole. Their corresponding importance values are shown in Figure 4(b). The importance of particles decreases as their distance from the actual dipole increases, and conversely, it increases as they move closer. Therefore, we treat the particle with the highest importance as an estimated position of the magnet. Illustration of importance analysis. (a) Random particles and the estimated dipole position obtained through importance analysis. (b) The importance of particles in different ranges of distance from the actual dipole position. Particles farther from the dipole exhibit lower importance.
The relationship between the particles and the magnetic field is formulated as a matrix equation. The vector from the ith candidate position to the jth sensor is denoted by
The magnetic field
For a multi-sensor array, the magnetic field model is expressed by
According to the model (5), the elements in P are calculated by
From the construction of P, each column represents the influence of a sampled particle on the sensor measurements. Particles closer to the true dipole position exert greater influence and thus correspond to more important columns. Consequently, the dipole position can be estimated by identifying the columns with the highest importance.
We define P as being decomposed into the product of an orthogonal matrix
The importance of a column
This metric is also known as the error reduction ratio (ERR) of an orthogonal vector (Billings and Wei, 2005). Columns with higher ERR values contribute more to the measurement, and the corresponding sampled particles provide estimates of the dipole position.
This process is derived as follows. An auxiliary vector
Since W is obtained from the orthogonal decomposition of P, its columns correspond to those of P and are associated with the sampled particles.
Let ω
i
denote the elements of the vector
By combining (10) and (11), a new equation is obtained and expressed as
The left-hand side of the equation is related to the error, while the right-hand side shows that the error decreases with each additional column
Equation (14) can be further simplified to (9) by substituting (11). It can be observed that
To improve computational efficiency, importance analysis is integrated into the orthogonal decomposition, enabling dipole position estimation without completing the full decomposition of P in (8).
Let us define the ith column in P as P
i
. We use the Gram–Schimit method to decomposite the matrix P, and the orthogonal vector in the matrix W has a form as
Each time a new vector P
i
in P is introduced, this formula orthogonalizes the vector with respect to the existing orthogonal vectors
The above method evaluates the importance of the vectors in P. To assess the importance of a given particle, we compute the combined significance of its associated vectors. According to (7), each sampled particle corresponds to three adjacent column vectors in P. Thus, particle k is associated with P3(k−1)+1, P3(k−1)+2, and P3(k−1)+3. Since the orthogonal vectors in (15) are decomposed sequentially, their ERR values can be computed during the decomposition process using (9). For each k ∈ [1, n], we therefore perform orthogonal decomposition on the three corresponding vectors in sequence and sum their ERR values to quantify the importance of particle k. This procedure is applied to all sampled particles, and the particle with the highest importance is selected as the estimated dipole position.
The importance analysis algorithm is presented in Algorithm 1. The inputs include the parameter matrix P, the measurement B
z
, the number of dipoles n
d
, and the number of particles n. The outputs are the index set of important dipoles Ωs and their estimated dipole moments
3.3. Adaptive particle sampling
In importance analysis, the dipole position is selected from sampled particles. Particle density affects localization accuracy, while the sampling range influences global optimality. However, dense sampling significantly increases computational cost. Therefore, instead of uniformly sampling the entire workspace at high density, we dynamically adjust the sampling range to balance accuracy and computational efficiency. The randomly sampled particles x
i
are expressed by
The most straightforward strategy is to begin with a small number of particles sampled over a large range to obtain a coarse estimate. The sampling range is then reduced, and the same number of particles are resampled around the previous estimate, effectively increasing sampling density without increasing computational cost. Importance analysis is repeated to refine the estimate. This process continues until the desired accuracy is achieved. As shown in Figure 5(a), the sampling range progressively contracts while the particle center converges toward the dipole position. Illustration of two particle sampling methods. (a) Performing multiple sampling iterations with the shrinking range in one loop. (b) Real-time iteration of the sampling process with varying ranges. (c) Position errors of two sampling methods. (d) The importance of all particles under different sampling ranges. The value of the highest importance and the variance of particle importance can be used as indicators to adaptively adjust the sampling range.
Another strategy adjusts the sampling range in real time. As illustrated in Figure 5(b), the range is continuously updated rather than waiting for convergence within each sampling period, resulting in a gradual narrowing over time. This real-time iteration concept is also employed in optimization-based control. For example, in nonlinear model predictive control using sequential quadratic programming (SQP), fully converged solutions are computationally expensive. Therefore, real-time iteration performs a single QP update per control cycle and uses the result to initialize the next cycle (Minniti et al., 2019), significantly improving computational efficiency.
The real-time iteration sampling consists of two processes: prediction and update. In the prediction process of the kth step, we estimate the current sampling center
The update process adjusts the sampling range by parameter
Let the n
d
th dipole denote the IPM, and its importance in each iteration is calculated by
As the iterations proceed and the sampling range narrows, particle importance is computed using the importance analysis and (20). In each iteration, 50 particles are used for estimation, and their importance values are shown in Figure 5(d). The maximum importance in each iteration is marked with a star, and the corresponding particle is selected to estimate the IPM position. As the sampling range contracts, the maximum importance accounts for an increasing proportion, while the variance among particle importance values gradually decreases.
We define the importance of the estimated dipole acquired by (20) in step k as
When the sampling range is expanded, if the estimated value deviates significantly from the sampling center in a certain direction, that direction will undergo more aggressive adjustment. Conversely, when the deviation is small, the direction will tend to maintain the original range. When the sampling range is reduced, the trend is reversed.
We compared these two strategies. The first samples over an extensive range in each period and theoretically converge faster. Still, it typically requires three to five iterations to obtain an estimate, resulting in lower computational efficiency. In contrast, real-time iteration converges over multiple periods but is computationally more efficient, and its accuracy is comparable when the magnet motion is continuous and stable. This analysis is confirmed by simulation using the same magnet trajectory. The tracking errors are shown in Figure 5(c). Both methods achieve similar average errors, with real-time iteration achieving an accuracy of 0.2 mm after three iterations.
3.4. Localization under external magnetic sources
To estimate the pose of the IPM under the influence of the EMSs, we need to incorporate the EMS positions into the model formulation.
We define m as the number of sensors, nc as the number of particles for IPM localization, and na as the number of EMSs. Based on the sampled particles and the known EMS position, we can compute two parameter matrices
Note that directly solving the position using model (23) makes it difficult to ensure continuity. When the magnet is far from the sensors, the measurements become weak and highly sensitive to noise. To mitigate this issue, the previous magnet position is incorporated into the importance analysis. The particle positions are denoted by
In these equations,
In these equations,
4. Experiments
This section evaluates the feasibility and performance of PIA through five sets of simulations and experiments. Simulations verify the robustness of PIA to model parameter errors and sensor noise. Experiments demonstrate that, compared with conventional optimization-based methods, PIA achieves faster computation, a longer sensing range, and accurate estimation of the IPM position and heading under different EMS configurations. Finally, PIA is applied to simultaneous localization and actuation in magnetic endoscopy using a colon phantom.
The experimental platform consists of manipulators, electromagnetic systems, a sensor board, and an NDI camera. The EMSs include permanent magnets, electromagnets, and hybrid magnetic sources. Permanent magnets are actuated by manipulators, while electromagnets are controlled by regulating coil currents. A computer running Ubuntu 24.04 on an Intel i7-11850 processor with 32 GB RAM handles manipulator control and magnet localization. The sensor board contains 72 Hall sensors, which are processed by an STM32 microcontroller and transmitted to the computer via serial communication. Both the manipulators and the NDI camera communicate with the computer through EtherCAT. ROS2 is used to publish and subscribe to sensor data, camera measurements, and manipulator joint states.
Experimental parameters.
4.1. Localization under disturbances
Simulations show that the proposed method maintains higher accuracy and better continuity under parameter uncertainties and measurement noise compared with optimization-based methods and particle filtering.
In the simulation, the positions and headings of the IPM and EMSs are predetermined, and the theoretical measurements of the Hall sensors are calculated using a point-dipole model. Our method inversely solves for the IPM position and heading using the generated measurements as inputs. Both the optimization-based method and the particle filter require compensation for the magnetic field generated by the EMSs before estimating the IPM state from the residual field. The optimization-based method estimates the IPM position and moment by minimizing the difference between measured and theoretical magnetic fields. However, when the initial guess is far from the actual state, the optimization may converge to an inaccurate solution or fail to converge within the maximum number of iterations. The particle filter we use is similar to that in Taddese et al. (2018). Both use a random walk model as the process model, but the measurement model is different. Taddese et al. (2018) use an IMU to measure the roll and pitch, while a particle filter estimates its position and yaw. Since we do not use an IMU, we assume a known heading in simulations and apply the particle filter only for position estimation. This design is intended to compare the differences between the particle filter and our method in position estimation. We evaluate these methods under two types of disturbances. The first, parameter disturbance, simulates errors in EMS calibration by using inaccurate moments randomly sampled between 0.9 and 1 times the actual moment. The second, measurement disturbance, simulates sensor noise and external interference by generating measurements randomly sampled between 0.9 and 1.1 times the ideal values. All three methods estimate the IPM state based on these perturbed measurements.
In the first set of simulations, no disturbances are added to the measurements or parameters. The ideal trajectory in the xy-plane is a Lemniscate of Gerono, and the IPM trajectory is expressed by the equation: (a) and (b) are the localization results without disturbances in model parameters and measurements. (c)–(f) show the results when the EMS moment includes a 10% random noise. (a) The 3D localization performance of three approaches—our method, an optimization-based method, and particle filter. (b) The mean absolute localization error. When the model parameters and measurements are perfect, three methods have similar accuracy. (c) The localization performance of the three methods under inaccurate moment. (d) The mean absolute position error when the dipole moment is not accurate. (e) The heading error for the optimization-based method and our method. (f) The EMS moments used in the three algorithms are randomly sampled from 0.9 to 1.0 times the actual EMS moment. Our method does not rely on an accurate EMS moment and can rectify it in real time.
The second simulation adds disturbances to the EMS moment, and the trajectories of IPM and EMS are the same as in previous simulations. The results of localization are shown in Figure 6(c). The errors of position and heading are given in Figures 6(d) and (e). The mean position errors for the three methods are 0.089, 6.785, and 4.234 mm, respectively. The maximum errors reach 0.486, 17.21, and 7.427 mm, respectively. The mean heading errors for our and optimization-based methods are 0.014 and 2.893 degrees. The inaccurate moment is shown in Figure 6(f) by a blue line, and the red line is the rectified dipole moment through our method. When parameter disturbances exist, the accuracy of the optimization-based method decreases significantly. Our method achieves the highest accuracy, followed by the particle filter. Since our method does not require compensation for the magnetic field generated by the EMS, it does not rely on an accurate EMS calibration. Moreover, even though we use the inaccurate EMS moment for initialization, our method can rectify the EMS in real time, maintaining high IPM localization accuracy.
In the third simulation, disturbances are added to the measurements. The trajectories of EMS and IPM are Archimedean spiral. The IPM trajectory is expressed by: Localization results when measurements are inaccurate. (a) The localization performance of the three methods on an Archimedean spiral. (b) The mean absolute localization error. (c) The heading error for the optimization-based method and our method. (d) The average measurements from the sensor array and the disturbed measurements. The disturbances are generated by randomly sampling within ±10% of the current measurements. Our algorithm can achieve good localization accuracy and stability under disturbances.
4.2. Test of computational efficiency
This section tests the performance of our method in tracking fast-moving target and compares it with the optimization-based method.
In this experiment, a cylindrical magnet with a dipole moment of 16.6 Am2 is mounted at the end of the manipulator. Its motion trajectory followed an ellipse with radii of 25 cm and 15 cm, with a height of 18 cm. The manipulator executed this trajectory at five different speeds, with motion periods of 1.5 s, 2 s, 3 s, 5 s, and 10 s, respectively. Our method estimates the magnet position based on the magnetic field measured by the sensor board.
As shown in Figure 8(a), our method maintains an approximate deviation from the desired path when tracking targets at different speeds. When the speed increases to one cycle per 1.5 s, a noticeable deviation appears, but the error quickly converges. We compared our method with the optimization-based method and summarized the position and heading errors at different speeds in Figure 8(b). As the motion speed increases from 10 s per cycle to 1.5 s per cycle, the position MAE of our method increases from 5.30 mm to 17.0 mm, while the optimization-based method increases from 4.8 mm to 25.8 mm. The angular MAE of the two methods increases from 0.87 degrees and 2.18 degrees to 2.67 degrees and 2.69 degrees, respectively. In this process, the maximum error of our method is 34.6 mm and 5.17 degrees, while the optimization-based method has a maximum error of 91.5 mm and 4.33 degrees. It can be observed that as the speed increases, the positioning accuracy of our method degrades more slowly. At higher target speeds, our method therefore achieves superior localization accuracy. This performance difference is primarily due to computational efficiency. As shown in Figure 8(c), when the motion period is 1.5 s, the optimization-based method exhibits noticeable tracking lag in the x and y directions. Solving the optimization problem requires an average of 37.5 ms, whereas our method requires only 1.31 ms on average. When tracking a slower-moving target, there is no significant difference between the two methods. However, as the speed increases, the higher computation time leads to more significant tracking errors. Meanwhile, the localization results of our method are also more densely distributed, allowing it to perceive sudden rapid movements more effectively. For example, in the scenario of magnetically actuated endoscopy, when the endoscope gets stuck in the colon, it may experience rapid slipping under the influence of the magnetic field, moving several centimeters within tens of milliseconds. Our method can quickly localize this process in real time. Tracking trajectory at different moving speeds of the magnet. (a) Desired trajectory and tracking results. (b) Position and heading errors of our method versus the optimization-based method. (c) Tracking results in the x and y directions. The optimization-based method shows a larger phase difference due to its higher time cost.
4.3. Localization at different sensor distances
We verified the stability of the method at different sensor–IPM distances and demonstrated its effectiveness in IPM localization under out-of-plane motion.
In the first experiment, two manipulators moved two magnets above the sensor board along a Lemniscate of Gerono trajectory. One magnet served as the EMS (16.6 Am2), and the other as the IPM (5.2 Am2) to be localized. We assessed the IPM localization performance at four heights: 10 cm, 12 cm, 16 cm, and 20 cm above the sensor board. We compared our method with the optimization-based approach, and the localization results are shown in row i of Figure 9. As the distance between the IPM and the sensors increases, the accuracy of both methods gradually declines. However, our method maintains higher accuracy and produces smoother localization results. The MAEs of both methods are shown in row ii. When the height is below 12 cm, both methods achieve similar accuracy, with MAEs within 2 mm for position and 3 degrees for heading. The maximum errors of our methods stay below 4 mm and 6 degrees, while the optimization-based method remains under 5 mm and 9 degrees. At 16 cm, both methods have a position MAE of 2.4 mm. However, the maximum errors for our method are 6.2 mm and 5.83 degrees, whereas those for the optimization-based method are 9.7 mm and 10.65 degrees. At 20 cm, the position MAEs are 4.70 mm for our method and 5.21 mm for the optimization-based method. The heading MAEs are 4.17 degrees and 4.72 degrees, respectively. Our maximum errors are 11.3 mm and 10.32 degrees, while those of the optimization-based method reach 27.3 mm and 28.7 degrees. Overall, our method maintains reliable localization performance up to an IPM height of 20 cm, with EMS heading estimation errors remaining within 6.3 degrees. (a)–(d) show the localization results of the IPM at different distances from the sensor board under the influence of an indeterminate EMS. Row i presents the actual trajectories of the EMS and IPM, together with the localization results from PIA and an optimization-based method. Row ii shows the mean absolute position and heading errors of both methods. Row iii displays the sensor reading ranges and magnetic field errors. (e) illustrates the result for out-of-plane motion, where the error increases with height and decreases effectively as the height is reduced.
Row iii of Figure 9 shows the estimated dipole moments and the magnetic field errors. The red area indicates the range of the magnetic field measurements. The red and black lines represent the percentage magnetic field errors for our method and the optimization-based method, respectively, defined as the mean absolute magnetic field error relative to the maximum sensor reading. As the IPM height increases, the measured magnetic field decreases from a maximum of 30 Gs to below 4 Gs, while the magnetic field error gradually increases. At a height of 20 cm, the percentage error reaches a maximum of 12.6% for our method, which is 2.1 times the maximum percentage error at 10 cm. The increase in magnetic field error leads to inaccurate localization. However, compared with the optimization-based method, our approach yields smaller magnetic field errors. As the magnet height increases, the dipole moments we estimate in real time change from 17.22 and 5.57 Am2 to 16.54 and 5.32 Am2, gradually approaching their nominal values. Treating the dipole moment as a variable parameter in the model allows it to adapt to real-time magnetic field changes, which partially compensates for model errors. The optimization-based method uses fixed dipole moments to separate the magnetic fields, and the resulting separation errors reduce the localization accuracy of the IPM. In contrast, our method estimates the dipole moments of both the EMS and IPM in real time during localization, avoiding magnetic field separation. This leads to smaller magnetic field errors and, therefore, better localization performance.
In the second experiment, the manipulator guided the IPM along a helical trajectory relative to the sensor array, with distances ranging from 8 cm at the closest point to 18 cm at the farthest. Out-of-plane motion tests demonstrate that the PIA stably localizes the IPM while it moves relative to the sensor array. In Figures 9(e–i), the IPM performs a helical motion perpendicular to the sensor plane, with minimum and maximum distances of 8 cm and 18 cm from the sensors, respectively. Figures 9(e–ii) shows that the maximum position and heading errors are 8.55 mm and 5.34 degrees, while the minimum errors at lower heights are 0.21 mm and 0.91 degrees. Figures 9(e–iii) shows that when the IPM is within 14 cm of the sensor array, the position error remains below 2 mm, and maximum errors increase with height. In Figures 9(e–iv), the percentage error represents the proportion of magnetic field error relative to the maximum measured field. As the IPM moves farther from the sensor array, field fluctuations caused by random noise increase, resulting in reduced localization accuracy. Although the error grows when the IPM moves away from the sensor array, our method enables rapid convergence and error reduction as the IPM approaches the sensors.
4.4. Localization under different indeterminate EMSs
This section tests our method under indeterminate EMSs through three experiments using permanent magnets, rapidly varying electromagnets, and hybrid magnetic sources. The results demonstrate that our method effectively localizes the IPM under different magnetic sources.
In the first experiment, as shown in Figure 10(a), the manipulator controls the motion of two permanent magnets, while the IPM (5.2 Am2) is manually moved above the sensor board. The hardware setup is similar to the previous experiment as shown in Figure 10(b). We estimate the position of the IPM using both our method and the optimization-based method, with the results shown in Figure 10(c). Both methods can localize the IPM in real time. However, in the optimization-based method, the estimated position occasionally deviates from the ground truth, shifting closer to the EMS position. The errors corresponding to the two methods are shown in Figures 10(d) and (e). The optimization-based method yields a position MAE of 4.3 mm and a heading MAE of 6.28 degrees, while our method achieves a position MAE of 3.2 mm and a heading MAE of 4.21 degrees. The localization results of IPM under the influence of two permanent magnets. (a) The experimental platform involves two manipulators controlling the motion of two EMSs. A sensor board is installed at the bottom to estimate the position of the IPM. Markers are attached to these magnets to measure their actual positions. (b) The hardware configuration. (c) The motion trajectories and estimated trajectories of the three magnets. (d) The position MAE of PIA and optimization-based method. (e) The heading MAE of our and optimization-based method. (f) The magnetic fields generated by the three magnets.
The blue regions indicate periods when the estimated values exhibit significant deviations. In these regions, the optimization-based method reaches maximum errors of 15.4 mm and 32.8 degrees. The maximum errors of our method are only 9.54 mm and 12.9 degrees. The theoretical magnetic fields generated by the three magnets are shown in Figure 10(f). As the error increases, the magnetic field generated by the IPM accounts for a smaller proportion of the total magnetic field. Combined with the disturbances caused by inaccurate dipole moment, this results in significant deviations. By considering historical estimates of the IPM position and real-time calibration of the dipole moment, our method maintains good stability despite interference from multiple EMSs.
In the second experiment, we evaluated the localization performance of PIA under rapidly varying electromagnetic fields, which the Navion generates. Navion is a robotic navigation system equipped with three coils, capable of generating magnetic fields in arbitrary directions over a large workspace (Boehler et al., 2022; Gervasoni et al., 2024). As shown in Figure 11(a), the Navion generates a magnetic field with a magnitude of 10 Gs, rotating around the x-axis at a frequency of 1 Hz. The sensor board is placed vertically approximately 0.5 m in front of the Navion. By applying a set of known currents to Navion, we can determine the positions of three coils in the sensor frame based on the measurements. The IPM, mounted on the end of a KUKA manipulator, followed a three-turn helical trajectory (6 cm radius) away from the sensor board, moving from 11 cm to 17 cm. An NDI camera measures the actual IPM position. The hardware setup between the sensors, manipulator, and computer is the same as in the previous experiment. A separate computer with Ubuntu system controls Navion and communicates with the host via TCP. Navion provides current feedback to the host in real time. In this experiment, the currents in the three coils vary sinusoidally, with a peak amplitude of about 1.8 A. The localization results of IPM under electromagnetic field. (a) The experimental platform, hardware setup and measured currents. The magnetic field is generated using the Navion, and the IPM is controlled by a manipulator to move along a helical trajectory. An NDI camera records the actual trajectory. (b) The actual IPM trajectory and the results estimated by PIA and optimization-based method. (c) The position and heading error of two methods. The error associated with the optimization-based method increases as the IPM moves away from the sensor, whereas our method demonstrates small error variation. (d) The average magnetic field on sensors generated by Navion and the average total magnetic field. (e) The magnetic field error obtained using our method and the norm of calibrated IPM moment.
The localization results of the PIA and optimization-based method are given in Figure 11(b), with the latter exhibiting significantly larger errors. Figure 11(c) shows the position and heading errors for three turns. As the number of turns increases, the IPM moves further from the sensor board. For the optimization-based method, the mean absolute error was 5.01 ± 11.70 mm in the first turn, increased to 6.66 ± 25.47 mm in the second, and reached 9.89 ± 29.73 mm in the final turn. In contrast, the mean absolute errors for PIA were 3.76 ± 7.31 mm, 4.55 ± 10.34 mm, and 4.24 ± 7.28 mm for the respective turns. The heading errors for two methods are 5.90 ± 33.83 and 1.95 ± 5.01 degrees, respectively. As the IPM moves away from the sensor, the optimization-based method shows a 97% increase in average error and an increase of 1.7 times in maximum error. In contrast, PIA exhibits minimal variation, maintaining an average error within 5 mm. Figure 11(d) shows the average magnetic field generated by the coils and the total field measured by the sensor. As the IPM moves farther away, the coil-generated field increasingly dominates. Inaccurate model parameters and current feedback delays hinder the optimization-based method from accurately isolating the magnetic field of the IPM, causing localization errors. In contrast, our method maintains stable performance despite high-frequency magnetic field variations. Figure 11(e) shows the real-time calibrated IPM moment obtained by PIA, with its magnitude deviating by up to 13.6% from the nominal moment. The red line represents the mean absolute error between the magnetic field computed from the calibrated moment using the dipole model and the measured field, with a maximum error of 0.19 Gs.
In the third experiment, we localize the position and moment of the IPM in a hybrid magnetic field generated by both permanent magnet and electromagnets. Figure 12(a) shows the configuration of the experimental platform. Six electromagnets are installed 0.14 m beneath the sensor board, with a 0.1 A current applied alternately to each for 0.5 s. The permanent magnet, initially positioned 0.45 m above the sensor board, performs six-DoF sinusoidal motion in accordance with the robot movement as shown in Figure 12(b). The real-time position of the permanent magnet is determined based on the manipulator kinematics, while the positions of the six electromagnets are obtained through calibration and treated as fixed values during the localization process. The IPM, equipped with markers, is manually moved above the sensor board, and the ground truth is recorded using an NDI camera. We compared our method with the optimization-based method, and the estimated trajectories are shown in Figure 12(c). The optimization-based method exhibits significant deviation from the actual trajectory in the hybrid magnetic field, whereas our method provides a stable estimation of the IPM position. Figure 12(d) presents the mean absolute errors of our method, with position and heading errors of 4.01 mm and 6.29 degrees, respectively, and maximum errors of 26.91 mm and 35.50 degrees. The optimization-based method is unstable because the fixed-moment point-dipole model struggles to segment the magnetic field of the IPM from the hybrid magnetic field. As shown in Figures 12(e) and (f), the EMS moment estimated by our method fluctuates around its nominal value, with a maximum deviation of up to 16%. When identical currents are applied, the moments of the electromagnets exhibit variability, resulting in magnetic field errors. The cumulative effect of these errors across multiple electromagnets causes the estimated position to deviate from the actual position. Our method demonstrates strong stability under hybrid magnetic fields, attributed to real-time moment calibration during the localization process. The localization results of IPM under hybrid magnetic field generated by a permanent magnet and six electromagnets. (a) The hybrid magnetic system consists of one permanent magnet and six electromagnets. The IPM moves above the sensor board, while the ground truth is collected using an NDI camera. (b) The motion of the manipulator end and the desired currents in electromagnets. Six electromagnets are supplied with a 0.1 A current in an alternating manner. (c) The motion trajectories of magnets and the localization results of the PIA and optimization-based method. (d) The position and heading error of our method. (e) The nominal and calibrated moment of permanent magnet. (f) Calibrated moments of six electromagnets.
4.5. Test in colon phantom
Our method enables simultaneous localization and actuation of a magnetic endoscope in a colon phantom. The experimental setup is illustrated in Figure 13(a). A magnetic endoscope equipped with an IPM and an onboard camera was actuated by an EMS mounted on the KUKA LBR Med 14. The endoscope was deployed within a colon phantom placed in a human abdominal model to simulate realistic conditions. The sensor array, consisting of 72 Hall sensors, was positioned beneath the abdominal model to measure magnetic fields across the entire abdominal region. The ideal IPM trajectory within the phantom is shown in Figure 13(b). During the experiment, the distance between the IPM and the sensor array varied from 17 cm to 20 cm. The endoscope heading followed the trajectory tangent, and the trajectory was divided into five segments, with lower velocities applied in Segments II and IV to enhance stability during turns. The manipulator controller runs on an Ubuntu system, with the localization and control algorithms implemented as two ROS2 nodes. The localization node receives magnetic field measurements and manipulator joint positions. It outputs the estimated position and magnetic moment of the IPM, as well as the EMS moment, at 100 Hz. A model predictive controller (MPC), detailed in Appendix B, is employed to control both the manipulator and the endoscope. The MPC operates at 40 Hz, taking the manipulator joint positions and the estimated IPM position and heading as inputs, and outputting joint commands to track the desired trajectory. Experimental results of simultaneous magnetic localization and actuation of a magnetic endoscope. (a) The experimental setup for the mock-up test. (b) The control diagram and desired trajectory. (c) Trajectories of the EMS and IPM using the optimization-based method and the PIA. The optimization-based method fails under the same desired trajectory. (d) Position errors of the two methods. (e) Heading error and the calibrated EMS moment. (f) The percentage error of the magnetic field and the range of measurement. (g) With the desired trajectory speed halved, the optimization-based method successfully passes through the colon phantom. (h) Position error using the optimization-based method. (i) The time cost of the two methods.
We perform localization using both the optimization-based approach and our proposed method. Figure 13(c) compares the trajectories obtained using the two localization methods. With the proposed method, the magnetic endoscope completed the entire trajectory. In contrast, the optimization-based method lost control after completing Segment i, leading to task failure. Figure 13(d) shows the position deviation from the ideal trajectory. Both methods exhibit triangular fluctuations, which are caused by stick–slip motion of the magnetically driven IPM, making smooth trajectory tracking difficult. The proposed method maintains a deviation below 2.5 cm throughout the experiment. However, the optimization-based method exhibits much larger fluctuations, with a maximum deviation of 4.5 cm, exceeding the phantom diameter. The resulting inaccurate localization degrades feedback quality and prevents the optimization solver from maintaining stable control. In Figure 13(e), the IPM heading error remains within 10° most of the time. Larger errors, up to 20°, occur in Segments ii and iv, where large rotations are required to change direction. During motion, the EMS dipole moment is calibrated online and fluctuates between 750 and 850 Am2. Figure 13(f) presents the magnetic field measurement errors, with measured field magnitudes within 20 Gs. The real-time magnetic field percentage error is computed as the mean field error normalized by the maximum measured field. The proposed method maintains the error below 6.5%, whereas the optimization-based method shows larger fluctuations, reaching up to 9.6%. Such errors account for more than 20% of the maximum IPM field (black curve), severely degrading localization accuracy. The magnetic dipole moment estimated by the proposed method is adaptively adjusted using real-time field feedback, resulting in lower magnetic field errors. Figure 13(i) compares the computational efficiency of the two methods. The proposed method achieves an average computation time of 1.21 ms, whereas the optimization-based method requires 35.5 ms on average. Due to varying iteration numbers, the optimization-based method reaches a maximum computation time of 68 ms, while the proposed method remains consistently below 2.5 ms. As a result, the optimization-based approach cannot meet the 40 Hz control frequency requirement, further contributing to its unstable control performance. The optimization-based method successfully passes through the colon phantom after the desired trajectory speed is halved, as shown in Figure 13(g). The speeds of Segments ii to iv are reduced to allow gradual heading adjustment. A lower trajectory speed reduces the sensitivity of the controller to unstable localization and timing mismatch, preventing rapid error accumulation. However, as shown by the position error in Figure 13(h), when entering Segment iii, the localization becomes noisier at larger sensor distances, which induces oscillations in the EMS during actuation. The experimental results show that our method provides stable and fast localization under EMS actuation and remains robust to trajectory height variations.
5. Conclusion
This article proposes a method for fast localization of the position and heading of an internal permanent magnet (IPM) under the influence of external magnetic sources (EMSs). The method does not require prior knowledge of the dipole moments of the magnets. Through importance analysis, the proposed method can simultaneously localize the IPM and calibrate the dipole moments of both the IPM and EMSs with high efficiency. The proposed adaptive particle sampling method dynamically adjusts the sampling range, enabling efficient computation with sparse particles while maintaining stability. Simulation results demonstrate that, compared to the optimization-based algorithm, the proposed method achieves higher accuracy and better robustness to measurement noise and errors in EMS dipole moments. The proposed method achieves an average computation time of 1.2 ms on a sensor board with 72 sensors. This high computational efficiency enables effective tracking of rapidly moving magnets. We also discuss the difficulty encountered by existing methods in maintaining high accuracy at large distances between the magnet and the sensor board, and experimentally validate the effectiveness of our method under such conditions. For a small magnet (5.2 Am2) at a height of 20 cm, our method achieves an average localization accuracy of 4.70 mm and 4.17 degrees, and the maximum error is only 41% of that of the optimization-based method. Additionally, we experimentally proved the effectiveness of our method under permanent magnets, electromagnets, or the hybrid magnetic field. Compared to the optimization-based method, our method demonstrates higher accuracy and smoother results, particularly when the magnet is subjected to interference from multiple EMSs. Finally, we further validate our method in the simultaneous magnetic localization and actuation of the endoscope by conducting tests in a colon phantom.
The main limitation of our current method is that it still requires the positions of the EMSs. Simultaneous localization of multiple magnets without this information may result in ambiguities, leading to localization errors. Our future work will focus on addressing the challenge of multi-target localization. The particle filter faces difficulties in handling multiple targets, while optimization-based methods are limited by low computational efficiency. Once this issue is resolved, localization based on the magnetic field can be performed without relying on the calibration of EMSs. Moreover, this approach can be extended to a broader range of scenarios that require fast and simultaneous localization of multiple targets.
Supplemental material
Supplemental material
Supplemental material
Supplemental material
Supplemental material
Supplemental material
Supplemental material
Footnotes
Funding
The authors disclosed receipt of the following financial support for the research, authorship, and/or publication of this article: This project is supported in part by the Hong Kong Research Grant Council with project No. C4042-23GF, 14214322, 14200623, 14206325, and CUHK Departmental Start-up Fund with project No. 7107414. The authors would also like to thank the support from AIR@INNOHK Multiscale Medical Robotics Center and Chow Yuk Ho Technology Center for Innovative Medicine.
Declaration of conflicting interests
The authors declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Supplemental material
Note
Appendix
References
Supplementary Material
Please find the following supplemental material available below.
For Open Access articles published under a Creative Commons License, all supplemental material carries the same license as the article it is associated with.
For non-Open Access articles published, all supplemental material carries a non-exclusive license, and permission requests for re-use of supplemental material or any part of supplemental material shall be sent directly to the copyright owner as specified in the copyright notice associated with the article.
