An active modeling control method for a magnetically driven flexible endoscope

By constructing an extended state-space model and using nonlinear state estimation methods, the modeling errors and hysteresis phenomena of magnetically driven flexible endoscopes are solved, achieving high-precision and fast-response magnetic drive control, which is suitable for precise operation in complex nonlinear environments.

CN122386627APending Publication Date: 2026-07-14NANKAI UNIV +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NANKAI UNIV
Filing Date
2026-06-09
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Traditional flexible bronchoscopes suffer from mechanical friction and structural deformation when exploring deep airways, resulting in insufficient force and torque transmission. Furthermore, the nonlinear modeling errors and hysteresis phenomena of magnetically driven endoscopes lead to insufficient control accuracy and response speed.

Method used

An extended state-space model incorporating modeling errors is constructed. By combining nonlinear state estimation with a quadratic cost function, control of complex nonlinear and unmodeled dynamics is achieved through real-time feedforward compensation. An unscented Kalman filter algorithm is used to estimate modeling errors, and the optimal compensation control input is obtained by minimizing the quadratic cost function.

Benefits of technology

It significantly improves the control accuracy and response speed of magnetically driven flexible endoscopes, reduces phase lag and dynamic tracking errors, and enhances the system's stability and anti-disturbance capability, making it suitable for precise control in complex nonlinear environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122386627A_ABST
    Figure CN122386627A_ABST
Patent Text Reader

Abstract

The present application belongs to the technical field of medical robot control, and provides an active modeling control method for a magnetically driven flexible endoscope, which comprises the following steps: acquiring an actual bending angle of a tip of the endoscope; calculating a nominal control input current by using a nominal controller; constructing an extended discrete state space model of the magnetically driven flexible endoscope; performing real-time estimation on the extended discrete state space model by using a nonlinear state estimation algorithm; constructing a quadratic cost function containing an estimated value of the modeling error, and obtaining an optimal compensation control input current by minimizing the quadratic cost function; adding the nominal control input current and the optimal compensation control input current to obtain an actual input current, which is output to a driving mechanism to control the bending angle of the flexible endoscope. The present method can reduce the phase lag phenomenon of a conventional controller, and greatly reduce the steady-state and dynamic tracking errors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of medical robot control technology, and specifically to an active modeling control method, and more particularly to an active modeling control method for a magnetically driven flexible endoscope. Background Technology

[0002] Respiratory diseases, especially lung cancer, pose a serious threat to human health. Flexible bronchoscopy, a crucial minimally invasive interventional technique in modern medicine, plays an irreplaceable role in early diagnosis and treatment. During the procedure, the surgeon inserts a flexible endoscope deep into the bronchial tree to explore lesions and use microsurgical instruments for precise biopsies or targeted therapy.

[0003] However, traditional flexible bronchoscopes have inherent limitations when exploring deep and tortuous anatomical branches. Their guidance mechanism heavily relies on manual pushing, pulling, and twisting movements by the operator at the proximal end. This purely mechanical transmission method generates severe cumulative friction and structural deformation in the complex terminal airways, significantly reducing the effective transmission of force and torque. Therefore, accurately and non-invasively reaching peripheral lung lesions remains a significant clinical challenge.

[0004] To overcome the limitations of traditional mechanical transmission, robotic flexible endoscopes driven by external magnetic fields have emerged and show great promise for clinical applications. Magnetic drive technology utilizes an externally established magnetic field to remotely drive the magnetic tip of the endoscope, providing an innovative non-contact manipulation solution. This method completely bypasses the mechanical friction limitations caused by traditional cable pulling, and promises to enable more flexible, deeper, and safer interventional procedures into distant deep airways.

[0005] Despite the significant structural advantages of magnetically driven bronchoscopes, achieving high-precision control to meet clinical testing needs still faces significant technical hurdles. Firstly, the highly nonlinear relationship between the external magnetic field force and distance makes establishing an accurate physical motion model extremely challenging. Conventional reference models have limited predictive accuracy across different workspaces, inevitably introducing significant modeling errors. Secondly, the system exhibits typical hysteresis nonlinearity during motion, meaning the system state moves along different paths during the increase and decrease of the driving current. When faced with a highly nonlinear system resulting from the superposition of modeling uncertainties and hysteresis, traditional nominal control methods (such as PID controllers) suffer from inherent phase lag and dynamic tracking errors in actual operation, making it difficult to achieve precise control with high response speed. Summary of the Invention

[0006] To overcome the shortcomings of existing technologies, this application provides an active modeling and control method for magnetically driven flexible endoscopes.

[0007] This method constructs an extended state-space model that includes modeling errors, and combines nonlinear state estimation with quadratic cost function optimization to achieve real-time feedforward compensation for complex nonlinear and unmodeled dynamics, significantly improving the system's control accuracy and response speed.

[0008] An active modeling and control method for a magnetically driven flexible endoscope includes the following steps:

[0009] Step S1: Obtain the actual bending angle of the endoscope tip;

[0010] Step S2: Calculate the nominal control input current using the nominal controller based on the deviation between the pre-designed target bending angle and the actual bending angle.

[0011] Step S3: Based on the magnetic dipole theory and the Euler-Bernoulli beam theory, establish the differential kinematic equations of the input current and the actual bending angle, and discretize the differential kinematic equations to construct an extended discrete state space model of the magnetically driven flexible endoscope.

[0012] Step S4: Use a nonlinear state estimation algorithm to estimate the extended discrete state space model in real time and output the modeling error estimate.

[0013] Step S5: Construct a quadratic cost function containing the modeling error estimate, and obtain the optimal compensation control input current by minimizing the quadratic cost function;

[0014] Step S6: Add the nominal control input current to the optimal compensation control input current to obtain the actual input current, and output it to the drive mechanism to control the bending angle of the flexible endoscope.

[0015] Furthermore, the process of obtaining the actual bending angle of the endoscope tip in step S1 is as follows:

[0016] Step S11: Use an industrial camera to acquire real-time images of the bending of the soft mirror and send the image sequence to the host computer;

[0017] Step S12: Threshold the original image in the host computer to obtain a binarized image sequence with a white foreground and a black background;

[0018] Step S13: Use topology analysis algorithm to extract all contour lines of the soft lens, and filter out the main contour of the soft lens according to the principle of maximum area;

[0019] Step S14: Use the minAreaRect function in OpenCV to fit the smallest bounding rectangle that fits the contour line, and obtain the bending angle of the soft mirror relative to the initial axis based on the direction of the rectangle.

[0020] Furthermore, the nominal controller mentioned in step S2 is a discrete PID controller.

[0021] Furthermore, the nonlinear state estimation algorithm in step S4 is an unscented Kalman filter algorithm, which is used to estimate the extended state in real time, including the actual bending angle and modeling error.

[0022] Furthermore, the quadratic cost function in step S5 includes a first penalty term for penalizing modeling errors and a second penalty term for penalizing excessive compensation control inputs.

[0023] Furthermore, the state variables of the extended discrete state-space model include: the theoretical rate of change of the bending angle of the tip of the magnetically driven flexible endoscope, the actual rate of change of the bending angle of the system, and the modeling error term.

[0024] Furthermore, the magnetic dipole theory is used to calculate the magnetic torque generated by the external magnetic field at the magnetic tip of the endoscope; the Euler-Bernoulli beam theory is used to describe the mechanical relationship between the elastic deformation and bending angle of the flexible endoscope under the action of magnetic torque.

[0025] The advantages of this application compared to the prior art are:

[0026] The modeling and control method for magnetically driven flexible bronchoscopes proposed in this application overcomes the limitations of traditional physical modeling in accurately describing hysteresis and environmental disturbances. By transforming uncertainty into extended states for real-time estimation and feedforward compensation, the method effectively mitigates the phase lag phenomenon of traditional PID controllers, significantly reducing steady-state and dynamic tracking errors. The strategy of combining a nonlinear state estimation algorithm with a quadratic cost function enables the system to quickly and adaptively adjust to sudden disturbances such as external collisions, ensuring the safety and stability of clinical interventional procedures. Attached Figure Description

[0027] Figure 1 The flowchart of the active modeling and control method for a magnetically driven flexible endoscope according to the present invention;

[0028] Figure 2 The structural block diagram of the active modeling compensation control strategy provided in Example 1;

[0029] Figure 3 A schematic diagram of the hardware platform for the magnetically driven flexible endoscope system provided in Example 1;

[0030] Figure 4 The comparison results of the control method of this application and the PID algorithm in the step trajectory adjustment experiment of Example 2 are shown (blue solid line: PID, red dotted line: AMCC algorithm, black solid line: reference trajectory).

[0031] Figure 5 The comparison results of the control method of this application and the PID algorithm in Example 3 on the sinusoidal trajectory tracking experiment (blue solid line: PID, red dotted line: AMCC algorithm, black solid line: reference trajectory);

[0032] Figure 6 The comparison results of the control method of this application and the PID algorithm in the triangular wave trajectory tracking experiment of Example 3 are shown (blue solid line: PID, red dotted line: AMCC algorithm, black solid line: reference trajectory).

[0033] Figure 7 The comparison results of the control method of this application and the PID algorithm in the anti-disturbance control experiment of Example 4 are shown (blue solid line: PID, red dotted line: AMCC algorithm, black solid line: reference trajectory). Detailed Implementation

[0034] The present technical solution will now be described in detail with reference to the accompanying drawings and embodiments. Unless otherwise stated, the technical or scientific terms used in this application have the ordinary meaning as understood by those skilled in the art.

[0035] Example 1, Reference Figure 1 and Figure 2 An active modeling and control method for a magnetically driven flexible endoscope according to this embodiment includes the following steps:

[0036] Step S1: Obtain the actual bending angle of the endoscope tip based on, for example... Figure 3 The hardware platform implementation of the magnetically driven flexible endoscope system shown is as follows:

[0037] Step S11: Use an industrial camera to acquire real-time images of the bending of the soft mirror and send the image sequence to the industrial control computer;

[0038] Step S12: Threshold the original image in the host computer to obtain a binarized image sequence with a white foreground and a black background;

[0039] Step S13: Use topology analysis algorithm to extract all contour lines of the soft lens, and filter out the main contour of the soft lens according to the principle of maximum area;

[0040] Step S14: Use the minAreaRect function in OpenCV to fit the smallest bounding rectangle that fits the contour line, and obtain the bending angle of the soft mirror relative to the initial axis based on the direction of the rectangle.

[0041] Step S2: Calculate the nominal control input current using the nominal controller based on the deviation between the pre-designed target bending angle and the actual bending angle.

[0042] Step S3: Based on the magnetic dipole theory and the Euler-Bernoulli beam theory, establish the differential kinematic equations of the input current and the actual bending angle, and discretize the differential kinematic equations to form a discrete reference model. Based on the discrete reference model, construct an extended discrete state space model of the magnetically driven flexible endoscope.

[0043] Step S31: Construct the torque balance equation of the soft mirror using a magnetic dipole model, wherein the magnetic dipole model is as follows:

[0044] (1)

[0045] (2)

[0046] in, Indicates the permeability in a vacuum environment. Represents the identity matrix. These are the position vectors of the flexible mirror tip and the permanent magnet, respectively. It is the magnetic moment of the permanent magnet. This is the magnetic field generated by the permanent magnet at the flexible mirror coil. The magnetic moment of the coil itself is determined by parameters such as the number of turns, cross-sectional area, and current. The expression for the magnetic moment of the coil is as follows:

[0047] (3)

[0048] Number of turns For input current, Let be the cross-sectional area of ​​the coil. It is the direction vector at the end of the flexible mirror;

[0049] The magnetic torque generated by the interaction between the soft mirror coil and the permanent magnet was further calculated. :

[0050] (4)

[0051] (5)

[0052] in It is magnetic torque The components on the z-axis, , These represent the components of the magnetic moment of the coil on the corresponding subscript axes. , Let represent the components of the magnetic field generated by the permanent magnet on the corresponding subscript axes. According to the Euler-Bernoulli beam theory, the equilibrium equation (6) for the internal torque and external magnetic torque of the flexible mirror bending can be obtained. For equation (6) with respect to time... By taking the derivative, we can obtain equation (7);

[0053] (6)

[0054] (7)

[0055] in It is Young's modulus. Moment of inertia of cross section It is the length of the curved portion of the flexible lens. It is the theoretical bending angle of the soft lens tip. It is the angular velocity of the theoretical bending angle;

[0056] Further substitution and simplification yields the differential kinematic equation (8) relating the bending angle of the flexible mirror to the input current:

[0057] (8)

[0058] Step S32, the specific implementation of discretizing the differential kinematic equations is as follows:

[0059] The state-space model of the original continuous system can be written as:

[0060] (9)

[0061] in The bending angle output by the system. , representing the rate of change of current, the system sampling time is set to Discretize formula (9) as follows:

[0062] (10)

[0063] Among them, the rate of change of current , express The current value at time [time]. express The current value at time [time]. It is a defined operator, representing an operation on... Find the partial derivatives.

[0064] Further discrete form of the state space:

[0065] (11)

[0066] Step S33: Based on the discretized model in step S32, further construct an extended discrete state-space model. The specific process is as follows:

[0067] Modeling error Represented as:

[0068] (12)

[0069] in It is the process noise driving the continuous-time error of the model. This represents the theoretical rate of change of the bending angle at the tip of a magnetically driven flexible endoscope. This represents the actual rate of change of the system bending angle at the tip of the magnetically driven flexible endoscope.

[0070] Treating the modeling error as a slowly changing state, further discretized as:

[0071] (13)

[0072] Furthermore, Along with the modeling error, the extended discrete state-space model is constructed as follows:

[0073] (14)

[0074] This represents the process noise that drives the model error. express The actual bending angle output by the system at any given time. Indicates process noise. Indicates the measurement noise of the system. This represents the actual system bending angle of the tip of the magnetically driven flexible endoscope. This represents the rate of change of nominal current. Indicates the expected rate of change of current. Represents function symbols.

[0075] The main idea behind this construction is to aggregate the unmodeled dynamics and hysteresis nonlinearities between the differential kinematic equations and the output of the actual physical system into a slowly changing modeling error term, and use this as an extended state variable to construct an extended discrete state-space model of a magnetically driven flexible endoscope.

[0076] In compact form:

[0077] (15)

[0078] The superscript 'e' indicates the extended form;

[0079] The extended vector is defined as:

[0080] (16)

[0081] in , This represents the process noise vector.

[0082] Step S4: The extended discrete state space model is estimated in real time using a nonlinear state estimation algorithm, outputting the modeling error estimate at the current moment. This includes iterative prediction and updating of the extended discrete state space model using an unscented Kalman filter (UKF). The specific process is as follows:

[0083] Step S41: Based on the extended state space model and extended state vector defined by equations (15) and (16) Control input vector and process noise vector Construct the system to be estimated. Expand the state vector. exist The average estimate at time step 1, i.e., the posterior state estimate at the current time step 2, is defined as follows: Extended state vector The covariance matrix is ​​defined as For an n-dimensional state vector The posterior state estimate at the current time and its covariance matrix Generate 2n+1 sigma points, 2n+1 sigma points ( , , )as follows:

[0084] (17)

[0085] in, Denotes the square root of a matrix based on Cholesky's square root. OK, It is a scaling parameter for adjusting the size; sigma points are a set of deterministic sampling points used in unscented Kalman filtering.

[0086] Step S42: Substitute the sigma point into the extended state equation corresponding to (15) for propagation and calculate the prior state estimate. and the prior covariance matrix as follows:

[0087] (18)

[0088] in It is the process noise covariance matrix, and the weights in the above formula are... and The definition is as follows:

[0089] (19)

[0090] Define parameters and , It can affect the distribution of sigma points. Used to Prior information about the distribution is incorporated into the weights.

[0091] Step S43: After obtaining the prior estimation results, calculate the predicted measurement value, the measurement covariance matrix, and the state-measurement cross-covariance matrix; calculate the Kalman gain. The prior state is then corrected using actual measured outputs to obtain the estimated posterior state. and posterior covariance matrix as follows:

[0092] (20)

[0093] in This represents the predicted measurement value for each sigma point. This represents the expected average measurement. Indicates measurement noise The covariance matrix, To measure the predicted value of covariance, State-measure cross-covariance;

[0094] Kalman gain Posterior state estimation and the posterior estimate of covariance. Calculate using the following equation:

[0095] (twenty one)

[0096] Finally, from the posterior state estimate Extracting modeling error components The estimated value is used as the basis for subsequent compensation control input calculation to achieve real-time compensation for system uncertainties and modeling errors.

[0097] Step S5: In this embodiment, a quadratic cost function is constructed to minimize the impact of modeling error. The estimated modeling error is substituted into this cost function, and the optimal compensation control input current is calculated by solving for the minimum value of the cost function.

[0098] Step S51: In order to make the compensated system output as close as possible to the desired state, establish the error elimination conditions that the compensation control input should satisfy.

[0099] (twenty two)

[0100] This formula shows that, within the current sampling period, the deviation between the actual bending angle and the expected bending angle of the system at the next moment can be expressed as a combination of the current actual bending angle, the compensation input term, and the modeling error term estimated in step S4.

[0101] Among them, the influence coefficient of the compensation input on the system state error as follows:

[0102] (twenty three)

[0103] This coefficient is determined by the magnetic moment component, the external magnetic field component, the system structural parameters, and the sampling period, and is used to characterize the strength of the effect of the compensation input change on the end bending angle change.

[0104] Step S52: Furthermore, to prevent numerical instability issues that may arise from direct solution, this scheme adopts an optimization solution method based on a quadratic cost function to construct the optimization objective function. as follows:

[0105] (twenty four)

[0106] in, The first term in the cost function represents the desired bending angle. The second term is used to address state deviations that persist even after penalty compensation. The parameter is used to penalize excessively large compensation control inputs. Parameters used to measure the importance of error terms It is used to constrain and compensate the input amplitude, thereby achieving a balance between control accuracy and control smoothness.

[0107] After establishing the cost function, its relationship with the control quantity to be compensated is... Find the partial derivative and set the result to zero:

[0108] Then, the optimal compensation control input is obtained. :

[0109] (25)

[0110] Finally, it is converted into the compensation current value at the current moment. :

[0111] (26)

[0112] in, Indicates the nominal control input current. This represents the actual input current of the system;

[0113] Further, in step S6, the nominal control input current is added to the optimal compensation control input current to obtain the actual input current, which is then output to the drive mechanism to control the bending angle of the flexible endoscope. In step S6, the compensation current value is superimposed with the nominal control input to obtain the actual input current applied to the system. This completes the closed-loop calculation process from "modeling error estimation" to "compensation current generation," enabling the magnetically driven flexible endoscope to maintain high trajectory tracking accuracy and control stability even in the presence of hysteresis and environmental disturbances.

[0114] Example 2: Based on the scheme of Example 1, this example uses the Active Modeling Control (AMCC) method described in steps S1 to S6 of this scheme to perform step trajectory tracking control on a magnetically driven flexible endoscope. In the experiment, a discrete PID controller was selected as the nominal controller, with its parameters set to Kp=0.0001, Ki=0.003, and Kd=0. The optimized compensation controller parameters were set to H1=1 and H2=0.015. The initial stable bending angle of the flexible endoscope tip was set to 30°, and the reference trajectory was set to a rectangular wave trajectory switching between 35° and 55° with a change period of 20s. Two cycles of tracking experiments were conducted. The following indicators were selected for quantitative comparative analysis:

[0115] a. Mean Absolute Error The absolute value of the tracking error is the average value over the entire time series.

[0116] b. Error variance : The variance of the tracking error over the entire time series.

[0117] c. Arrival Time The time when the tracking error first reaches 0 or enters the allowable error band.

[0118] Experimental results are as follows Figure 4 Table 1 shows that when a step change occurs, the active modeling compensation control strategy using the method of this invention can eliminate phase lag more quickly, and compared with the traditional PID controller, its error enters the allowable range in a shorter time. The time was shortened from 3.6s to 2.8s, and the mean absolute error was reduced. The error variance decreased from 1.485 to 1.291. The mean absolute tracking error decreased from 12.585 to 10.284, a reduction of approximately 13.1%, and there was almost no significant overshoot or oscillation after reaching steady state. This indicates that the method of the present invention can effectively improve the adjustment speed and steady-state accuracy of the magnetically driven flexible endoscope in the nonlinear working range.

[0119] Example 3, (1) The Active Modeling Control (AMCC) method described in steps S1 to S6 of this scheme is used to perform sinusoidal trajectory tracking control on a magnetically driven flexible endoscope. The above-mentioned PID parameters and compensation parameters are still used in the experiment, and the reference trajectory is set as follows:

[0120] (27)

[0121] To examine the system's dynamic tracking performance under continuously varying reference input. Additional error metrics to consider:

[0122] d. Maximum error The maximum error during subsequent tracking after the system first catches up with the reference trajectory.

[0123] Experimental results are as follows Figure 5 Table 2 shows that after adopting the active modeling control method of this scheme, the tracking error of the flexible endoscope to the sinusoidal reference trajectory is significantly reduced, and the mean absolute error is reduced. The error variance decreased from 1.541 to 0.500. The maximum tracking error decreased from 3.311 to 0.558. The time it takes for the error to enter the acceptable range is reduced from 2.970 to 0.920. The time was shortened from 9.000s to 1.290s.

[0124] (2) The active modeling control method of this scheme was also used for triangular wave trajectory tracking control. In the experiment, the amplitude range of the triangular wave reference trajectory was set to 35° to 55°, the period was set to 20s, and the other control parameters remained unchanged.

[0125] Experimental results are as follows Figure 6 Table 2 shows that, compared to the traditional PID controller, the active modeling control method also exhibits superior dynamic tracking performance during the continuous reciprocating motion of the triangular wave, with a lower mean absolute error. The error variance decreased from 1.396 to 0.499. The maximum tracking error decreased from 2.818 to 0.560. The time it takes for the error to enter the allowable range is reduced from 2.490 to 1.230. The time was shortened from 4.000s to 2.300s.

[0126] Experiments combining sinusoidal and triangular wave trajectories show that the active modeling control method proposed in this scheme can reduce the average absolute tracking error by about 65% and the error variance by more than 80% under continuously changing trajectories. This indicates that it can effectively suppress the phase delay and dynamic fluctuations of the magnetically driven flexible endoscope in reciprocating motion, and perform real-time estimation and compensation for unmodeled dynamics and hysteresis errors in the system, thereby significantly improving the tracking accuracy and response speed under continuous trajectories.

[0127] Example 4: The Active Modeling Control (AMCC) method described in steps S1 to S6 of this scheme was used to verify the anti-disturbance control of a magnetically driven flexible endoscope. In the experiment, the bending angle of the flexible endoscope tip was first stabilized at 30°. Within a 40s control cycle, additional disturbance currents with a duration of 1s and an amplitude of 0.3A were superimposed on the steady-state current of the system at the 10s, 20s, and 30s respectively, to form a disturbance effect of about 5°, which was used to simulate the effect of doctor's hand tremors or external environmental disturbances on the system.

[0128] Considering the mean absolute error and error variance These two sets of error indicators:

[0129] Experimental results are as follows Figure 7 As shown in Table 1, under disturbances, the active modeling control method of this scheme can still maintain good trajectory recovery capability, eliminating tracking error within about 3 seconds after the disturbance occurs, while the recovery time of the traditional PID controller exceeds 7 seconds; at the same time, the active modeling control method of this scheme reduces the mean absolute error... The error variance decreased from 0.702 to 0.445. The error was reduced from 2.102 to 1.148, resulting in a decrease of approximately 36.6% in the mean absolute error and approximately 45.4% in the error variance. This demonstrates that the method of this invention not only improves the trajectory tracking accuracy of magnetically driven flexible endoscopes but also exhibits strong resistance to external disturbances and robustness, making it more suitable for precise manipulation in real-world clinical environments.

[0130] Table 1 shows... Figure 4 , Figure 7 Comparison results of various error indicators recorded in the corresponding experiment;

[0131] Table 2 is... Figure 5 , Figure 6 The results of the comparison of various error indicators recorded in the corresponding experiment.

[0132]

[0133]

[0134] This application has disclosed the preferred embodiments above, but it is not intended to limit the invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed structure and technical content to create equivalent embodiments without departing from the scope of the technical solution of this application, and all such modifications or alterations shall still fall within the scope of the technical solution of this application.

Claims

1. An active modeling and control method for magnetically driven flexible endoscopes, characterized in that: Includes the following steps: Step S1: Obtain the actual bending angle of the endoscope tip; Step S2: Calculate the nominal control input current using the nominal controller based on the deviation between the pre-designed target bending angle and the actual bending angle. Step S3: Based on the magnetic dipole theory and the Euler-Bernoulli beam theory, establish the differential kinematic equations of the input current and the theoretical bending angle of the endoscope, and discretize the differential kinematic equations to construct an extended discrete state space model of the magnetically driven flexible endoscope. Step S4: Use a nonlinear state estimation algorithm to estimate the extended discrete state space model in real time and output the modeling error estimate. Step S5: Construct a quadratic cost function containing the modeling error estimate, and calculate the optimal compensation control input current by minimizing the quadratic cost function; Step S6: Add the nominal control input current to the optimal compensation control input current to obtain the actual input current, and output it to the drive mechanism to control the bending angle of the flexible endoscope.

2. The active modeling and control method for a magnetically driven flexible endoscope according to claim 1, characterized in that: The process of obtaining the actual bending angle of the endoscope tip in step S1 is as follows: Step S11: Use an industrial camera to acquire real-time images of the bending of the soft mirror and send the image sequence to the host computer; Step S12: Threshold the original image in the host computer to obtain a binarized image sequence with a white foreground and a black background; Step S13: Use topology analysis algorithm to extract all contour lines of the soft lens, and filter out the main contour of the soft lens according to the principle of maximum area; Step S14: Use the minAreaRect function in OpenCV to fit the smallest bounding rectangle that fits the contour line, and obtain the bending angle of the soft mirror relative to the initial axis based on the direction of the rectangle.

3. The active modeling and control method for a magnetically driven flexible endoscope according to claim 1, characterized in that: The nominal controller mentioned in step S2 is a discrete PID controller.

4. The active modeling and control method for a magnetically driven flexible endoscope according to claim 1, characterized in that: The process of constructing the differential kinematic equations in step S3 is as follows: The torque balance equations for a soft mirror are constructed using a magnetic dipole model, which is as follows: (1) (2) in Indicates the permeability in a vacuum environment. Represents the identity matrix. These are the position vectors of the flexible mirror tip and the permanent magnet, respectively. It is the magnetic moment of the permanent magnet. It is the magnetic field generated by the permanent magnet at the soft mirror coil, and the magnetic moment of the coil. The expression is as follows: (3) Number of turns For input current, Let be the cross-sectional area of ​​the coil. It is the direction vector at the end of the flexible mirror; The magnetic torque generated by the interaction between the soft mirror coil and the permanent magnet was further calculated. : (4) (5) in yes The components on the z-axis, , These represent the components of the magnetic moment of the coil on the corresponding subscript axes. , Let represent the components of the magnetic field generated by the permanent magnet on the corresponding subscript axes. According to the Euler-Bernoulli beam theory, the equilibrium equation (6) for the internal torque and external magnetic torque of the soft mirror bending can be obtained. Differentiating equation (6) yields equation (7). (6) (7) in It is Young's modulus. Moment of inertia of cross section It is the length of the curved portion of the flexible lens. It is the theoretical bending angle of the soft lens tip. It is the angular velocity of the theoretical bending angle. Indicates the rate of change of current; Further, the differential kinematic equation (8) relating the bending angle of the flexible mirror to the input current is obtained: (8)。 5. The active modeling and control method for a magnetically driven flexible endoscope according to claim 4, characterized in that: The process of discretizing the differential kinematic equations in step S3 to construct the extended discrete state-space model of the magnetically driven flexible endoscope is as follows: The specific implementation of discretization of differential kinematic equations is as follows: Formula (8) can be expressed by the space state equation as follows: (9) in The bending angle output by the system. The system sampling time is set to Discretize the formula as follows: (10) The rate of change of current , express The current value at time [time]. express The current value at time [time]. It is a defined operator, representing an operation on... Taking the partial derivatives, the discrete form of the state space can be further written as follows: (11) Based on the above discretization process, an extended discrete state-space model is further constructed, as follows: Modeling error Represented as: (12) in It is the process noise driving the continuous-time error of the model. This represents the theoretical rate of change of the bending angle at the tip of a magnetically driven flexible endoscope. The angular velocity, representing the actual bending angle of the endoscope tip, is further discretized as: (13) Furthermore, the extended discrete state-space model is constructed as follows: (14) This represents the process noise that drives the model error. express The actual bending angle output by the system at any given time. Indicates process noise. Indicates the measurement noise of the system. This represents the actual system bending angle of the tip of the magnetically driven flexible endoscope. This represents the rate of change of nominal current. Indicates the expected rate of change of current. Represents function symbols.

6. The active modeling and control method for a magnetically driven flexible endoscope according to claim 1, characterized in that: The nonlinear state estimation algorithm in step S4 is an unscented Kalman filter algorithm, which is used to estimate the extended state in real time, including the actual bending angle and modeling error.

7. The active modeling and control method for a magnetically driven flexible endoscope according to claim 5, characterized in that: The specific process of step S4 is as follows: Step S41: Write the extended discrete state-space model in the following form: (15) The superscript 'e' indicates the extended form; Definition: Extended vector: (16) Based on the above extended state space model and extended state vector Control input vector and process noise vector Construct the system to be estimated and expand the state vector. exist The average estimate at time is defined as Extended state vector The covariance matrix is ​​defined as ; Estimated from the posterior state at the current time and its covariance matrix Generate 2n+1 sigma points as follows: (17) in, Denotes the square root of a matrix based on Cholesky's square root. OK, This is the scaling parameter for resizing, where n represents the state vector. The dimension; Step S42: Substitute the sigma point into the extended state equation corresponding to (15) for propagation and calculate the prior state estimate. and the prior covariance matrix as follows: (18) in It is the process noise covariance matrix, and the weights in the above formula are... and The definition is as follows: (19) Define parameters and , It can affect the distribution of sigma points. Used to Prior information about the distribution is incorporated into the weights; Step S43: After obtaining the prior estimation results, calculate the predicted measurement value, the measurement covariance matrix, and the state-measurement cross-covariance matrix; calculate the Kalman gain. The prior state is then corrected using actual measurement outputs to obtain the estimated posterior state. and posterior covariance matrix as follows: (20) in This represents the predicted measurement value for each sigma point. This represents the expected average measurement. Indicates measurement noise The covariance matrix, To measure the predicted value of covariance, State-measure cross-covariance; Kalman gain Posterior state estimation and the posterior estimate of covariance Calculate using the following equation: (21) Finally, from the posterior state estimate Extracting modeling error components The estimated value is used as the basis for subsequent compensation control input calculation to achieve real-time compensation for system uncertainties and modeling errors.

8. The active modeling and control method for a magnetically driven flexible endoscope according to claim 1, characterized in that: The quadratic cost function in step S5 includes a first penalty term for penalizing modeling errors and a second penalty term for penalizing excessive compensation control inputs.

9. The active modeling and control method for a magnetically driven flexible endoscope according to claim 7, characterized in that: The specific process of step S5 is as follows: Step S51: Establish the error elimination conditions that the compensation control input should meet; (22) The influence coefficients of the compensation input on the system state error are as follows: (23) Step S52: Construct the optimization objective function using an optimization solution method based on a quadratic cost function. as follows: (24) in, The first term in the cost function represents the desired bending angle. The second term is used to penalize or compensate for state deviations that persist after the penalty or compensation. Used to penalize excessively large compensation control inputs; parameters Parameters used to measure the importance of error terms Used to constrain and compensate input amplitude. Treatment of compensation control quantity Find the partial derivative and set the result to zero: Then, the optimal compensation control input is obtained. ; (25) Finally, it is converted into the most compensated control input current at the current moment. ; (26) in, Indicates the nominal control input current. This represents the actual input current of the system.

10. The active modeling and control method for a magnetically driven flexible endoscope according to claim 1, characterized in that: The magnetic dipole theory mentioned in step S3 is used to calculate the magnetic torque generated by the external magnetic field at the magnetic tip of the endoscope; the Euler-Bernoulli beam theory is used to describe the mechanical relationship between the elastic deformation and bending angle of the flexible endoscope under the action of magnetic torque.