Research on attitude compensated algorithm for shipborne dynamic weighing

Shipborne dynamic weighing is fundamental in developing marine fishery resources and oceanographic research. It enables the weighing and sorting of seafood, quantitative baiting, and measurement of research sample weights in marine environments. Therefore, developing shipborne dynamic weighing systems is crucial for the integrated exploitation of marine fishery resources. However, research on shipborne dynamic weighing is limited. To address this issue, the study initially analyzed the impact of ship’s attitude information on weighing results. Subsequently, a mathematical model for shipborne dynamic weighing, incorporating compensation factors, was constructed. The compensation factors were determined using the Recursive Least Squares (RLS) method. And then real-time weight estimation was updated using Kalman filtering, effectively mitigating the influence of ship oscillations and swaying on weight measurements. Furthermore, a shipborne dynamic weighing system with a 24-bit analog-to-digital converter (ADC) and STM32F4 processor was developed. The system performance was evaluated by simulating the sail of a ship under different sea conditions on a swing platform. The results demonstrate that the average absolute percentage error of the test meets the requirement of less than 1%, and the standard deviation of the error is less than 1% F. S., which essentially meets the weight measurement requirements of marine dynamic weighing and sorting.


Introduction
Dynamic weighing is the process of weighing when the weighed object is in motion [1,2], the scale is in motion [3], or both [4].With the development of modern industrial technology, rapid and dynamic weight detection is increasing in demand for production and life [5].With dynamic weighing technology, the product can be detected in the transmission device in the process and can realize a series of tasks, such as automatic weighing, significantly improving work efficiency [6].To ensure the supply and demand of high-protein food, vigorously developing marine fishery aquaculture is an effective development strategy; therefore, developing a dynamic weighing system that can be used on ships is of great significance to the comprehensive development of marine fishery resources [7].Presently, research on dynamic quantitative weighing and sorting equipment on moving carriers is relatively scarce, and more relevant technologies and products must be available.The research and breakthrough of this technology will fill the blank and have high economic and social benefits.
Current research in dynamic weighing technology is focused on obtaining accurate mass readings in noisy and fast-paced environments, so the main dynamic weighing technologies in common use today include modelbased estimation methods, signal processing filtering techniques, and control-based methods.
In model-based estimation methods, it is common practice to create a model of the weighing system and then calculate estimated weights of moving objects based on this model.Halimic et al [8,9] modeled the weighing system of a belt scale using a second-order mass-spring-damper system and developed ideal weight signal models for different materials under test.The results showed that not only the test accuracy but also the signals are stably filtered, and the calculation is fused.The results indicate a significant improvement in dynamically compensated modified weighing signals.The main contents of this paper are as follows: Mathematical modeling of the shipborne dynamic weighing system and analysis of the influence of ship attitude angle, acceleration, and other factors on the weighing results.
The compensation factors in the attitude compensated algorithm are calculated using the recursive least square method.
A attitude compensated algorithm based on Kalman filtering was designed for the influence of the ship attitude angle, acceleration, and other factors on counterweight results.
Through simulation and experimental verification, the field test results met the requirement that the error be less than 1%.

Composition and principle of marine dynamic weighing system
2.1.Composition of marine dynamic weighing system Figure 1(a) depicts a shipborne dynamic weighing system.The dynamic weighing system is installed in a relatively stable working area on the experimental ship.The dynamic weighing system includes a weighing sensor, an inertial carrier, a conveyor belt, and other devices.The weighing conveyor components are typically installed on the strain gauge weighing sensor of the C3 accuracy class.In contrast to traditional weighing technology, thedynamic weighing system is located on an ocean ship.It is generally in the running state of the ship during the dynamic weighing process.At this time, the mechanical vibration of the ship, the fluctuation of the ocean wave surface, and the forward speed of the ship affect the measurement results.The hull motion is illustrated in figure 1(b).
The weighted articles are transferred to the weighing conveyor via the feeding conveyor and weighed using a weighing sensor.Simultaneously, the inertial sensor measures the ship's attitude information.Subsequently, the weighing signal of the weighing sensor, attitude angle information, and acceleration information of the inertial sensor are simultaneously sent to the microprocessor for processing.After processing, the weights of the objects are sorted by the sorting device according to their weight value range [27].

Weighing principle of dynamic conveyor belt
In a dynamic weighing system, the ideal strain gauge load cell is usually modeled as a mass-spring-damp model [28], as shown in figure 2. When an external force is applied to the load cell, the dynamic response can be described by equation (1) Where M(t) is the mass of the object to be weighed, m is the weight of scale body, c is the equivalent damping ratio, and k is the equivalent stiffness.For solid objects, the weight exerted on the load cell can be ideally modeled as a trapezoidal pulse of finite duration (as shown in figure 2(b)): the period [t 1 ,t 2 ) represents the object moves onto the weighing platform, the period [t 2 ,t 3 ] during which the whole object is on the platform, and the period (t 3 ,t 4 ] during which the object slides off the platform [16,29].Thus the effect of the weighed object on the sensor output during dynamic weighing can be studied based on the strain x in the system.

Effect of ship attitude on weight results
When the scale body received tilt and acceleration, the tilt angle was θ, the vertical acceleration perpendicular to the carrier plane was α 1 , and the parallel acceleration parallel to the carrier plane was α 2 .As shown in figure 3, the force analysis of the load in the figure can be obtained as equation (3) and equation (4).
Where F 1 is the force applied to the load cell in the vertical direction, with good linearity; F 2 is the force applied to the load cell in the horizontal direction, the direction of the scale tilt, the load weight and the size of the tilt angle will make the load cell stretch, twist and deform, thus having the load cell output as equation (5)  = + ( ) Where F is the weighing output of the load cell, f (F 2 ) represents the result of the influence of the horizontal force on the output of the load cell.
In the process of fast movement on the sea, roll, pitch, lifting, forward, and lateral drift motions all impact the marine weighing platform.
A coordinate system is established in the installation base plane, as shown in figure 4. The X axis is the vertical line of the hole axis of the double-hole cantilever beam, and the Y axis is the parallel line of the hole axis of the double-hole cantilever beam, and this coordinate system coincides with the attitude sensor and the coordinate system of the ship.The carrier coordinate system (X 1 Y 1 Z 1 ) based on the body of the weighing device and the geographic coordinate system (XYZ) based on the ground surface are constructed, and the transformation process of the two coordinate systems is plotted as figure 5.
In figure 5, (a) shows the relative schematic diagram of the (X 1 Y 1 Z 1 ) coordinate system rotated by γ degree around the OX axis, (b) shows the relative schematic diagram of the (X 1 Y 1 Z 1 ) coordinate system rotated by θ degree around the OY axis based on (a), and (c) shows the relative schematic diagram of the (X 1 Y 1 Z 1 ) coordinate system rotated by ψ degree around the OZ axis based on (b).
According to the above transformation, the attitude transformation matrix is obtained as follows: Then considering the ship's sway angle and acceleration effects, the forces on the weighed object in the XYZ direction of the carrier coordinate system are respectively as in equations ( 7)- (9).
It is known that the impact forces in different directions have different sensitivity to the deformation output of the load cell, so the force on the load cell is as equation (10) Where F z is the vertical force perpendicular to the plane of the weighing device, F x is the horizontal force in the x direction of the weighing device, F y is the horizontal force in the y direction of the weighing device.
Then when the pitch angle, cross-roll angle and longitudinal, transverse and vertical acceleration exist at the same time, the weighing error is as equation (11).
It can be observed from the above formula that when the load weight is fixed, the error is F error .With inclination and acceleration becoming increasingly larger, it can be observed that the pitch angle, roll angle, and longitudinal, transverse, and vertical accelerations significantly affect the weighing accuracy of the load.
In a shipborne dynamic weighing system, the dynamic weighing signal is shown in figure 6.From figure 6 it can be seen that, in addition to the influence of low frequency signals such as the ship's attitude, the dynamic weighing system is also adversely affected by conventional low frequency vibrations generated by mechanical structures such as motors, active running belts and rollers when the object is being transmitted.The operation of the vessel also generates some impulse noise with random characteristics.As a result, the weighing signals obtained from load cells are usually highly oscillatory and non-stationary, they never reach a steady-state value corresponding to the static weight, and the weighing signals are still very different from the ideal ones even after using digital filtering algorithms.
Therefore, the motion of the ship affects the force exerted on an object.To ensure the accuracy of dynamic weighing, a compensation method must be designed to reduce the impact of the motion of the ship.As a result, an attitude compensated algorithm for shipborne dynamic weighing is presented in this article.

Compensation factors calculation based on the RLS algorithm
The ideal weight of the weighed object is m 0 .The weight of the weighed object measured by the load cell is m 1 .The inertial sensor outputs the real-time acceleration a x , a y , a z in the carrier coordinate system and the attitude angle of the weighing device with respect to the geographic coordinate system including yaw angle ψ, pitch angle θ and roll angle γ.According to the real-time acceleration values a x , a y , a z and attitude angles ψ, θ, γ, the ideal weight m 0 of the weighted object is obtained by compensating the weight sensor output value m 1.
After building the carrier coordinate system (X 1 Y 1 Z 1 ) based on the weighing device body and the geographic coordinate system (XYZ) based on the surface [30], According to the above error analysis, it can be concluded that the sensitivity of the three directions to the force on the sensor is different, and the output of the dual hole weighing sensor is linear within the effective weighing range.Therefore, the errors introduced in the X and Y directions are simplified as linear, and the compensation factors in the three directions are set as respectively a x , a y and a z .It is used to establish the input and output relationship between the weight output value of the load cell and the actual force on the load cell.
First, the actual weight m 0 of the object to be weighed is decomposed into [m 0x , m 0y , m 0z ] in three directions under the carrier coordinate system, and the weight output value m 1 measured by the load cell is also decomposed into [m 1x , m 1y , m 1z ] in three directions under the carrier coordinate system.According to the compensation factors in three directions, the load cell output weight m 1 is expressed as equation (12) According to the real-time acceleration value and expressed as the local gravity acceleration value in g, the real-time impact force of the symmetric weight sensor in three directions under the carrier coordinate system generated by the acceleration can be calculated, and the force of the symmetric weight sensor in three directions can be obtained as equation (13).Where M = [0, 0, m 0 ] T denotes the components of the ideal weight m 0 of the three axes in the geographic coordinate system.According to the above equations and known weight output value m 1 .Solve the equation to calculate the ideal weight m 0 of the weighed object in motion.
Based on equations 12, 14 and 15, the load cell output weight m 1 can be expressed as equation ( 16) Where the matrix C = [c x , c y , c z ] T is the compensation parameter matrix to be solved.From the above equation, it can be inferred that before performing dynamic compensation on the ship's dynamic weighing system, it is necessary to calculate the compensation factors.It can be obtained from equation (17) that it is a multivariate linear equation, while RLS is a recursive method to solve the least-squares solution of the multivariate linear equation, which can establish the mapping relationship between input and output in real time and online [31][32][33].Its fundamental principle is to utilize existing observational data (weight measurement value m 1 , pitch angle θ, roll angle γ and three-axis accelerations a x , a y , a z ) to estimate the necessary compensation factors c x , c y , c z , minimizing the mean squared prediction error to optimize the estimation results.Where m 1k represents the kth group of load cell output .M k T 1 represents the input observation of the kth group.
then the least squares solution is equivalent to equation (19).
When the data is input in real time, the least squares method takes up a lot of memory and requires a lot of computation.In this case, the RLS algorithm can update Ĉk online.Let According to the above formula, we can establish - Ĉk 1 and Ĉk recursive relationship as equation (23).
According to the above formula, the recursive relationship of the parameters e Ĉ U P , , , When there is sufficient observation data, the compensation factor matrix C can be derived by the RLS algorithm [34,35].
Then, through real-time estimation using Kalman filtering, the estimated value of the weighed object with dynamic compensation can be obtained.

Dynamic compensation algorithm based on kalman filtering
After obtaining the compensation factors c x , c y , c z through the RLS algorithm, the real-time mathematical model of the ship's dynamic weighing system is as equation (25).Considering the dynamics of the ship's dynamic weighing system and the effects of noise, the Kalman filter is used for weight estimation.The Kalman filter is a recursive filtering method primarily used for dynamic system state estimation.It also operates on the principles of least squares estimation, but unlike least squares, the goal of the Kalman filter is to estimate the system state at each time step based on current observational data and the state model, gradually updating the estimate to account for new observational data.This makes the Kalman filter suitable for dynamic systems where the state evolves over time [36][37][38].
In the shipborne dynamic weighing system, the dynamic compensation problem is modeled as a state estimation problem, with the state vector denoted as X = [m 0 ].It is often assumed that the object's mass does not change over time, hence state transition matrix is F = [1] and Q is system noise.The state model is as equation (26).
The relationship between the observation vector Z = [m 1 ] of the weight sensor and the state vector X, as given in equation (25), yields the observation matrix H.And R is observational noise.
Because the pitch angle θ, the roll angle γ, and the three-axis accelerations a x , a y , a z of the ship are constantly changing in real-time, the observation matrix H also varies in real-time.At each time step k, the observation matrix H is different.Therefore, through the Kalman filtering algorithm, we perform prediction and update steps at each time step to estimate the true mass of the object.Ultimately, we obtain an estimate that is close to the ideal value m 0 .
Using the state transition model for state prediction as equation (28).
Predicting the covariance matrix as equation ( 29).

= +
-- Subsequently, the Kalman gain K, state estimation X , k and estimation covariance matrix P k are updated as equation ( 30)

Simulation of compensation algorithm
To getthe corresponding compensation factors c x , c y , c z , reference weights with known values were placed on top of the sensors.By simulating the behavior of the ship under different attitudes and accelerations, measurements of the weight sensor m 1 and outputs of the inertial sensor θ, γ, a x , a y , a z were recorded.Subsequently, using the actual measurement values and known weights m 0 , compensation factors were calculated using the RLS algorithm mentioned in section 3.1, as shown in the following table 1. Acquisition of compensation factors is completed before dynamic compensation; however, these factors may vary due to changes in sensor performance.Therefore, regular recalibration or updates are necessary to ensure the system's accuracy.
Once the correct compensation factors are obtained, the Kalman filtering is used for dynamic compensation.Simulated mass data affected by the ship's attitude was generated using MATLAB based on the combined attitude information under typical sea conditions with the addition of random noise as shown in figure7 and equation (31).According to the weight output value and attitude information as the input of dynamic attitude compensation algorithm, the modified mass curve is output after the algorithm simulation processing.
When 500 g, 1000 g, and 2000g are used as input quantities, the compensation results after the compensation algorithm are shown in figure 8.The uncompensated output curve deviates far from the ideal curve for different ideal input values when different ship motion attitude information is input, while the compensated output curve basically coincides with the ideal curve whereas.The non-linear error is used to describe the compensation effect as equation ( 32) As shown in table 2, after attitude compensation, the nonlinear error of the output curve during the swinging process is minimized to 0.70%, and the output measurement is closer to the target weight value.
This indicates that the attitude compensated algorithm can compensate for marine weighing disturbances in the motion system and improve the weight measurement accuracy.

Experimental verification and result analysis 4.1. Experimental platform
To evaluate the performance and applicability of the marine dynamic compensation algorithm based on attitude compensation, an experimental platform for weighing scales with less than 2000 g and attitude measurement, as shown in figure 9, was designed.The experimental platform includes a weighing sensor, an inertial sensor, a weighing section, and a degree-of-freedom swing platform.The three-degree-of-freedom platform is a complex  mechatronic product comprising a Stewart mechanism, computer control system, drive system, and pump station.The lower platform was fixed to the ground, whereas the upper platform served as the support platform.By coordinating the strokes of the electro-hydraulic cylinders, the computer control system facilitates the platform's three degrees of freedom, enabling lifting and lowering motion and rotation in the right angle coordinate system.The platform is suitable for marine environment testing and multi-motion simulation, with customizable sea state and motion performance [30].
The block diagram of the data acquisition and processing circuit is shown in figure 10.The strain gauge load cell PW10A50KG with a maximum capacity of 50 kg was used, and the signal of the load cell was processed by the data acquisition module.With the rapid development of microelectronic technology, the integration of electronic measurement components has increased.Many devices usually integrate standard functions; therefore, the application design of these devices has gradually become simpler.The middle three links of the data acquisition module were removed under the condition of ensuring the demand of the dynamic weighing and sorting system: isolation, filtering, and amplification.The AD7190 chip is commonly used to simplify the design circuit of the data acquisition module.The extremely low noise 24-bit ADC AD7190 was used to convert the analog output voltage into a digital signal, which was then sent to STM32F407.Simultaneously, the inertial sensor VG200 fuses the acceleration value and angle output by the accelerometer and gyroscope through Kalman filtering and then sends the ship's attitude information to STM32F407 through RS485 communication.Finally, the dynamic compensation algorithm processes the weight and attitude information, and the estimated weight results are displayed on a display screen.

In-field test
In the shipborne dynamic weighing system, the acquired weighing signals are first compensated for motion weighing based on attitude information.
In this study, three different weights (500 g, 1000 g, and 2000 g) were used under laboratory conditions.According to the conditions of the regular operation of the ship, a three-degrees-of-freedom platform system was selected as the swing platform for simulating ship operation.The belt running speed was 1.2 m s −1 .
Figures 11, 12   attitude compensation algorithm, the trapezoidal signal of the dynamic weighing is recovered and the noise is further reduced.

The test results and the evaluation
To confirm the measurement quality and reliability, the mean relative error of indication s ¯, the standard deviation of error s , and the mean value of indication m were used as verification standards [39].

Figure 3 .
Figure 3. Establishment of rectangular coordinate system on the installation base plane.

Figure 4 .
Figure 4. Establishment of coordinate system on the installation base plane.

Figure 5 .
Figure 5. Attitude transformation schematic: (a) Schematic diagram depicting rotation around the X-axis; (b) Schematic diagram depicting rotation around the Y-axis based on (a); (c) Schematic diagram depicting rotation around the Z-axis based on (b). g

0Where M 0 =
List in matrix form as equation(14).[m 0x , m 0y , m 0z ] T denotes the components of the ideal weight m 0 on the three axes of the carrier coordinate system, M 1 = [m 1x , m 1y , m 1z ] T denotes the components of the weight m 1 measured by the load cell on the three axes of the carrier coordinate system, A = [a x , a y , a z ] T denotes the acceleration component in the direction of the three axes in the carrier coordinate system.According to the direction cosine matrix R, M 0 can be calculated from equation(15) the RLS algorithm is as equation(24).
and 13 represent the field test results of 500 g, 1000 g and 2000g moving objects, respectively.Each figure contains two parts of information.The upper part of the figure represents the load cell output signals under different swing states and the output results after the Kalman filter-based attitude compensation algorithm.The lower part of the figure represents the different attitude information of the simulated ship.From the figure, it can be seen that before the dynamic compensation, the trapezoidal weighing signals in the original acquired signals are distorted while mixed with serious noise signals.After applying the Kalman filter-based

Figure 10 .
Figure 10.Signal acquisition and processing circuit block diagram.

Figure 11 .
Figure 11.In-field test results of 500 g moving object: (a) The swing table sways around the X-axis; (b) The swing table sways around the Y-axis; (c) The swing table sways around the XY-axis; (b) The swing table rises and falls around the Z-axis.

Figure 12 .
Figure 12.In-field test results of 1000 g moving object: (a) The swing table sways around the X-axis; (b) The swing table sways around the Y-axis; (c) The swing table sways around the XY-axis; (b) The swing table rises and falls around the Z-axis.

Figure 13 .
Figure 13.In-field test results of 2000 g moving object: (a) The swing table sways around the X-axis; (b) The swing table sways around the Y-axis; (c) The swing table sways around the XY-axis; (b) The swing table rises and falls around the Z-axis.

Table 2 .
The non-linear error.Simulate ship information in different sea conditions.

Table 3 .
Verification standards of three test loads.