Next Article in Journal
3D Vehicle Detection and Segmentation Based on EfficientNetB3 and CenterNet Residual Blocks
Previous Article in Journal
Multiple Sensor Fault Detection Using Index-Based Method
Previous Article in Special Issue
Body-Worn IMU-Based Human Hip and Knee Kinematics Estimation during Treadmill Walking
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Stateful Rotor for Continuity of Quaternion and Fast Sensor Fusion Algorithm Using 9-Axis Sensors

1
Independent Researcher, Sapporo 063-0867, Japan
2
Graduate School of Information Science and Technology, Hokkaido University, Sapporo 060-0814, Japan
*
Author to whom correspondence should be addressed.
Sensors 2022, 22(20), 7989; https://doi.org/10.3390/s22207989
Submission received: 23 August 2022 / Revised: 15 October 2022 / Accepted: 18 October 2022 / Published: 19 October 2022

Abstract

:
Advances in micro-electro-mechanical systems technology have led to the emergence of compact attitude measurement sensor products that integrate acceleration, magnetometer, and gyroscope sensors on a single chip, making them important devices in the field of three-dimensional (3D) attitude measurement for unmanned aerial vehicles, smartphones, and other devices. Sensor fusion algorithms for posture measurement have become an indispensable technology in cutting-edge research, such as human posture measurement using wearable sensors, and stabilization problems in robot position and posture measurement. We have also developed wearable sensors and powered suits in our previous research. We needed a technology for the real-time measurement of a 3D human body motion. It is known that quaternions can be used to algebraically handle 3D rotations; however, sensor fusion algorithms for three sensors are presently complex. This is because these algorithms deal with the post-rotation attitude (pure quaternions) rather than rotation information (the rotor) to avoid a double covering problem involving the rotor. If we are dealing with rotation, it may be possible to make the algorithm simpler and faster by dealing directly with the rotor. In this study, to solve the double covering problem involving the rotor, we propose a stateful rotor and develop a technique for uniquely determining the time-varying states of the rotor. The proposed stateful rotor guarantees the continuity of the rotor parameters with respect to angular changes, and this paper confirms its effectiveness by simulating two rotations around an arbitrary axis. In addition, we verify experimentally that a fast sensor fusion method using stateful rotor can be used for attitude calculation. Experiments also confirm that the calculated results converge to the desired rotation angle for two spatial rotations around an arbitrary axis. Since the proposed stateful rotor extends and stabilizes the definition of the rotor, it is applicable to any algorithm that deals with time-varying quaternionic rotors. In this research, an algorithm based on a multiply–add operation is designed to reduce computational complexity as a high-speed calculation for embedded systems. This method is theoretically equivalent to other methods, while contributing to power saving and the cost reduction of products.

1. Introduction

Nine-axis sensors, each of which is composed of an accelerometer, magnetometer, and gyroscope, are used to measure the posture and motion of humans and robots [1,2]. Such sensors can either be inertial measurement unit (IMU) sensors or magnetic, angular rate, and gravity (MARG) sensors. Now, to be precise, the IMU is a 6-axis sensor because it does not have a magnetometer, but because the proposed algorithm in this paper is applicable to it, this sensor is regarded without distinction. In any case, the development of micro-electro-mechanical systems has made 9-axis sensors compact and sufficiently popular to be used in smartphones [3] and unmanned aerial vehicles (UAVs) [4,5].
Fast measurement algorithms with small sensors have become an important component of state-of-the-art technology for robot and UAV attitude measurement techniques [6]. In human body motion measurement, and the posture measurement of robots and UAVs, real-time performance is required; thus, a high processing speed is vital. For this reason, we have been developing a fast approximate computation method for nonlinear functions as a fast attitude computation algorithm that can be used in embedded systems [7,8], and have used it in the above-mentioned wearable sensors and powered suits. This has enabled posture measurement on MCUs with small internal memory, where conventional mathematical libraries cannot be incorporated. Using these posture measurement algorithms for embedded systems, we previously developed wearable devices that measure and assist human body motion, mainly in the sagittal plane [9,10,11]. However, although the method of approximating nonlinear functions enabled the fast computation of plane rotations, it was difficult to extend the method to three-dimensional (3D) rotations while keeping computational costs low.
The sensor fusion method algorithm for 3D rotation has been discussed since the 1970s [12]. The goal is to represent the attitude vector in terms of Euler angles, rotation matrices, and pure quaternions, and to eliminate noise from multiple sensors to achieve stable attitude estimation. The implementation methods of this theory include the use of extended Kalman [13,14,15,16,17,18,19], Madgwick [20,21,22,23,24,25] and Mahony filters [26], but our target real-time fast computation for embedded applications requires even lower computational cost and power consumption. Therefore, the design of the proposed algorithm uses a complementary filter that can be processed quickly by embedded computers. Model-based algorithms, such as extended Kalman filters, are difficult to design because the target human body posture measurement and UAV posture are generally difficult to model due to the intervention of the intention of the person being measured and the operator [27]. In contrast, a complementary filter is easy to implement because its frequency characteristics can be controlled via the adjustment of only a single parameter, and simple algorithms can be designed.
Therefore, we propose a sensor fusion algorithm for quaternion rotors, focusing on the fact that the algorithm can be algebraically organized in a simple way by treating quaternions as rotors. If the quaternion rotor is treated as is, sensor fusion cannot be designed due to the problem of guaranteed uniqueness. Therefore, we have developed a stateful rotor that extends the definition of the rotor to solve this problem. The stateful rotor guarantees the continuity of the internal state, allowing the use of statistical and time-series filters. Due to the extension of the definition of rotors, the proposed change to statefulness has the potential to be applied to stabilize various algorithms in addition to the proposed method. In the Results section, we confirm that it is also possible to eliminate time series discontinuities in the rotors computed with conventional algorithms.
The objective of this research is to develop a small, low-consumption, real-time computationally feasible posture measurement sensor that can ultimately be used for human body motion measurements. The proposed method designs the algorithm so that it can be executed only by a multiply–add operation, and run at high speed on MCUs, such as embedded devices. Based on fast computation as a design concept, we used quaternion algebra and complementary filters and designed a stateful rotor and a fast arccos approximation.

2. Methods

This section is structured as follows. In Section 2.1, we define the symbols for the quaternions and rotations used in this paper. In Section 2.2, we clarify the problems in designing algorithms for handling rotors and propose a stateful rotor to solve them. In Section 2.3, a fast sensor fusion algorithm using stateful rotor is designed. Finally, in Section 2.4, we propose a linear approximation of a nonlinear function to obtain the attitude angle from a rotor at high speed for embedded systems.

2.1. Definition of Quaternion Rotor

The use of quaternions provides advantages such as the absence of singularities and the use of interpolation expressions. These advantages will serve as essential algebraic properties in this algorithmic design. The handling of rotations by quaternions is based on previous studies [28,29,30].
In this paper, the scalar part of a quaternion is represented by s or w, and the vector part comprises the elements v = ( x , y , z ) . We use the following general definition of a quaternion rotor.
q r = s r , v r = cos θ 2 , n sin θ 2
In this definition, θ denotes the angle of rotation, and n denotes the axis of rotation.
The rotation from a point p = ( x p , y p , z p ) to another point p = ( x p , y p , z p ) in 3D space by a quaternion is expressed as
q p = q r q p q r * ,
where the conjugation q r * denotes ( s r , v r ) and q p denotes the quaternion; where 0 is added to the scalar part, a pure quaternion is realized, i.e., q p = ( 0 , x p , y p , z p ) . Regarding rotations by quaternions, given that both the rotation operator q r and the point q p of the operation target are four-dimensional quantities, confusion in distinguishing the two concepts can greatly hinder understanding. Therefore, in this paper, the rotor q r and the point q p are regarded separately by using subscripts.
In summary, this section defines the symbols for quaternions and rotors used in this paper. Using these symbols, the proposed algorithmic design is discussed in the next section.

2.2. Stateful Rotor

The rotor is defined by Equation (1). Based on the use of complex numbers in circular statistics, the use of trigonometric functions corresponds to an unwrapping process that smoothly connects π rad and π rad. Thus, initially, Equation (1) also seems to guarantee continuity in the quaternion space. However, because the arguments in Equation (1) are multiplied by a factor of 1/2, the value of θ must range within [ 2 π , 2 π ] for the trigonometric functions to be continuous over a cycle. In contrast, it is sufficient to consider [ π , π ] if we describe every posture only statically. To account for the continuity of the rotor, we need to consider [ 2 π , 2 π ] because of the influence of the trigonometric function of the definition.
For example, the behavior of each element of q r with respect to the angle n = ( 0.267 , 0.535 , 0.802 ) ( 1 , 2 , 3 ) , when the axis of rotation is θ , is shown in Figure 1. This simulation was calculated when the initial angle was 2 π and was varied continuously up to 2 π . The dashed lines are the values that must be taken for the rotor to be continuous, whereas the solid lines are the values calculated from Equation (1). In the range where θ is [ π , π ] , both the scalar and vector parts appear to be continuous, but the vector part cannot be connected because the signs of the values at π and π are reversed. This discontinuity has a negative impact on the design of time-series or statistical filters; thus, it is necessary to remove the discontinuity to guarantee continuity.
The problem here is that although θ can represent a 3D rotation in the range [ π , π ] , if we extend it to [ 2 π , 2 π ] because of the continuity of the trigonometric functions, there will be two different rotors representing the same attitude. This corresponds to the fact that q r and q r represent the same attitude, as is evident from the definition of the rotation of quaternions (2). Whereas uniqueness could be ensured through the selection of either q r or q r when the domain of definition is [ π , π ] , the space in which the domain is expanded to [ 2 π , 2 π ] contains both q r and q r , which leads to arbitrariness with regard to the value that the rotor takes. Figure 1 is a simple case, and thus we can take q r for | θ | π and q r for | θ | > π . In reality, however, θ is an unknown number, and the threshold varies depending on the state of the rotation axis n . Thus, it is difficult to make a decision based solely on this information.
To simultaneously solve the problems of guaranteeing the continuity of trigonometric functions and the uniqueness of the rotor, we propose the use of a stateful rotor. First, the continuity of the trigonometric functions can be guaranteed if the domain of the definition is set to [ 2 π , 2 π ] , as described previously. Next, we consider whether the value computed from the definition of the rotor, expressed by Equation (1), should be q r or q r . However, because q r and q r are equivalent informative values, we cannot make a proper choice based on this information alone. Therefore, given that the purpose of this study is time-series signal processing for posture measurement, we consider using dynamic information. Specifically, the optimal state is maintained through the construction of a tracking system that uses the state of one previous rotor to calculate the likelihood. An overview of the designed stateful rotor is shown in Figure 2.
This is ultimately a choice between q r or q r , which can be thought of as a question of whether q r should be multiplied by 1 . Therefore, based on a comparison between the currently obtained value q r , i and the past state q ^ r , i 1 , it is determined that q r is the optimal value if the distance is close, and q r is the optimal value if the distance is far. The distance can be evaluated based on the inner product of the elements of q r , i and q ^ r , i 1 , that is, the scalar part of the conjugate quaternion product.
J = vec ( q r , i ) · vec ( q ^ r , i 1 ) = Re ( q r , i q ^ r , i 1 * ) = w r , i w r , i 1 + x r , i x r , i 1 + y r , i y r , i 1 + z r , i z r , i 1 ,
where vec is a vectorization that treats elements as vectors. Because this evaluation function is an inner product, it can be computed quickly in the implementation using a multiply–add operation of the elements. Because J is an inner product, it has a positive value in the same direction if it is close, and a negative value in the opposite direction if it is far away. Therefore, the sign of J can be used to determine the sign of q r as it is.
q ^ r , i = sign ( J ) q r , i
The q ^ r , i is a stateful rotor, which guarantees continuity and uniqueness. Examples are shown in Figure 3 and Figure 4. Figure 3 shows the results when the arbitrarily settable initial condition q ^ r , 0 and the measurement initial value q r , 1 are close. Continuity is preserved across the function, and the ends of the domain of definition can also be connected. Figure 4 shows the results when the initial condition q ^ r , 0 and q ^ r , 0 are far apart. Although the values are inverted, because q r and q r are equivalent, the inversion of the negative sign is not a problem, and continuity is guaranteed as in the result shown in Figure 3. Therefore, the initial state value can be arbitrary without any problem, and the state-tracking algorithm can obtain a behavior with guaranteed continuity thereafter.
In summary, the discontinuity and uniqueness of the time-varying rotors were identified as problems, which were both solved by introducing the stateful rotor. The stateful rotor is an extension of the definition of rotors; thus, it is an algorithm that can be applied to other research dealing with rotations of quaternions.

2.3. Sensor Fusion Algorithm for the Stateful Rotor

Because the stateful rotor guarantees the time-series continuity of the rotor, sensor fusion with time-series filters can be applied. Although previous studies have proposed extended Kalman and Madgwick filters with complementary filters for the sensor fusion of coordinate q p , we considered the sensor fusion of q r with the stateful rotor. We considered the application of complementary filters for the purpose of low-cost and fast computation, which was the design concept. The basis of optimization for embedded applications was to eliminate division and nonlinear computation from the algorithm and to use a multiply–add operation to perform the computation. From this perspective, the first-order complementary filter was the best choice because it could be performed using only a multiply–add operation.
Sensor fusion of the rotor with a complementary filter can be designed by analogy with a one-dimensional complementary filter. We designed an algorithm to calculate the rotor via the sensor fusion of 9-axis sensors, using the measured values a of the acceleration sensor, m of the magnetometer, and ω of the gyroscope as inputs.

2.3.1. Low-Frequency Side: Magnetometer and Accelerometer

Gyroscopes measure absolute angular rates in the world frame, and relative value changes in attitude can be calculated from it. In contrast, magnetometers and accelerometers measure absolute attitudes relative to Earth. Methods for obtaining the quaternion attitude include long-established methods, such as the quaternion estimation algorithm (QUEST) and algebraic quaternion algorithm (AQUA); factored quaternion algorithm (FQA) for calculating roll, pitch, and yaw angles; and super-fast attitude from accelerometer and magnetometer (SAAM) for high-speed calculation. Because SAAM has singular postures, as will be shown later, this study used a method based on a direction cosine matrix (DCM), which is as fast as SAAM and as accurate as FQA.
First, we considered normalization and orthogonalization of sensor data. The sensor value matrix as a DCM is as follows.
R = m x c x a x m y c y a y m z c z a z = m c a .
a is the normalized vector of the sensor value of the accelerometer a s , and therefore a = a s / a s . c is the virtual axis derived by c = ( a × m s ) / ( a s × m s ) , where m s is the measured value from the magnetometer. Vector c is always orthogonal to a and m s ; however, a and m s are not guaranteed to be orthogonal. Thus, orthogonality is guaranteed by the cross product of c and a as follows: m = ( c × a ) / ( c × a ) . This technique is known as tri-axial attitude determination [31,32]. This process ensures that R is an orthogonal matrix, enabling the transformation formula for rotation matrices and quaternion rotors to be applied. The matrix R is referred to as the Earth fixed frame.
Next, the quaternion responsible for the low-frequency side of the complementary filter was generated from the sensor measurements. The method to reconstruct a rotor at high speeds without a singular axis of rotation from DCM is as follows.
First, we consider the element matrix M as follows.
M = D 0 N 1 N 2 N 3 N 1 D 1 P 3 P 2 N 2 P 3 D 2 P 1 N 3 P 2 P 1 D 3 = M 0 M 1 M 2 M 3 .
This matrix is filled with information on sensor measurements as follows. The diagonal components D i are
D 0 = 1 + m x + c y + a z , D 1 = 1 + m x c y a z , D 2 = 1 m x + c y a z , D 3 = 1 m x c y + a z ,
and the nondiagonal components P i and N i are
P 1 = a y + c z , N 1 = a y c z , P 2 = m z + a z , N 2 = m z a x , P 3 = c x + m y , N 3 = c x m y .
Next, we reconstructed the quaternion rotor from M. We only used a one-column vector M k . The k is the index that maximizes D i , i.e., k = arg max i ( D i ) . The quaternion rotor q r s was reconstructed from the component vector v q s as follows:
v q s = 1 2 D k M k k = argmax ( D i ) .
The quaternion rotor q r s reconstructed from the component vector is
q r s = v q · v q e .
Here, v q e is a vector that has the unit elements of the quaternion, i.e., v q e = [ 1 , i , j , k ] .
With regard to the programming, all D i were first calculated, and k was determined as k = argmax ( D i ) . The k-th column vector of the element matrix M was then calculated and divided by 2 D k . Then, we could obtain the four components of the desired quaternion. Its calculation cost was 13 additions, 5 multiplications, 1 conditional branch, and 1 reciprocal square root. For example, if the fast inverse square root algorithm [33,34,35,36,37,38] was used for the reciprocal square root, this algorithm could be executed using only multiply–add operations.

2.3.2. High-Frequency Side: Gyro Sensor

Next, we consider how to treat the gyro sensor value ω as a rotor.
If the rotation ω measured by the gyro sensor is the rotor q r ω , then based on the definition of the gyro sensor measurement, the rotation angle per minute time is ω Δ t , and the rotation axis is ω ω . Therefore, q ω could be obtained from the definition of the rotor Equation (1) as
q r ω = cos ω Δ t 2 , ω x ω sin ω Δ t 2 , ω y ω sin ω Δ t 2 , ω z ω sin ω Δ t 2 .
Using the small-angle approximation sin θ θ ( θ 1 ) and the rotor condition q r = 1 , we obtain
q r ω = ( s ω , v ω ) 1 v ω 2 2 , ω x Δ t 2 , ω y Δ t 2 , ω z Δ t 2 .
Therefore, the integration of the attitude by the gyroscope became the following update rule.
q p , n = q r ω , n q p , n 1 q r ω , n * = q r ω , n q r ω , n 1 q p , n 2 q r ω , n 1 * q r ω , n * = i = 1 n q r ω , i q p , 0 i = 1 n q r ω , i *
From this, the update rule for the rotor by the gyro sensor is
q r , n = q r ω , n q r , n 1 .
The expression could have a simplified form because it needs only Equations (12) and (14).

2.3.3. Sensor Fusion with Complementary Filter

Finally, q r s and q r ω are combined by a complementary filter. Because of the characteristics of the sensor, the high-frequency side of q r s is subject to motion acceleration noise among others, whereas the low-frequency side is highly reliable. On the other hand, the low-frequency side of q r ω accumulates integration errors, whereas the high-frequency side is highly reliable. The complementary filter is a technique that uses only the frequency responses of these reliable portions of the data and filters the bands with the most errors [27,39,40,41]. The complementary filter can be calibrated using α , a cut-off frequency control parameter that takes a value from 0 to 1, as follows.
q r c , i = α q r ω q r c , i 1 + ( 1 α ) q r s
The first term on the right-hand side is an updated expression based on the integration of the gyro rotation, whereas the second term on the right-hand side represents the current attitude estimate obtained from the Earth fixed frame. Through interpolation by α , the frequency characteristics were improved, and the error was converged to zero.
Here, q r c , i and q r s appear on the right-hand side. Therefore, as discussed on the stateful rotor in Section 2.2, because q r s has the degrees of freedom, q r s and q r s , the entire system becomes unstable if the one far from q r c , i is selected. Therefore, stabilization is performed via the transformation of q r s to statefulness, with q r c , i as the state, as shown in Figure 5.
Finally, sensor fusion could be performed such that the error converges to zero as in the following equation, resulting in a time-series stable rotor.
q ^ r c , i = α q r ω q ^ r c , i 1 + ( 1 α ) q ^ r s
To summarize this subsection, a sensor fusion method for the 9-axis sensors using a stateful rotor is proposed. The algorithm developed adheres to the design concept of implementation by a multiply–add operation as much as possible, and the calculation method is suitable for embedded systems.

2.4. Fast Angle Estimation from Rotor

We propose a method to linearly approximate the nonlinear operations required in the angle calculation with high accuracy in order to speed up the algorithm for embedded systems. This removes the nonlinear computation from the entire attitude estimation algorithm and optimizes it for embedded systems with limited computational resources.
In the previous section, to update the rotation state at high speeds, sensor fusion of the rotor using quaternions was performed. Ultimately, the rotation state could be intuitively determined if the rotation angle and axis of rotation were obtained from the rotor.
Based on the definition of the rotor Equation (1), the angle of rotation and the axis of rotation are
θ = 2 arccos ( w ) ,
n = 1 sin θ 2 x , y , z T = 1 1 w 2 x , y , z T .
Although n could be calculated using only elements and inverse square roots, the arccos operation, a nonlinear function, is required to calculate θ . Given the use of low-performance MCUs for downsizing wearable sensors and UAVs, the use of nonlinear functions should be avoided as much as possible. Therefore, this nonlinear function is processed by approximation to achieve high speeds. The residual correction method proposed in our previous study [7,8] allowed calculations using only square root operations, as shown in the following equation. When β = 0.351 , the maximum approximation error was less than 0.5 deg as showin in Figure 6.
θ = 2 arccos ( w ) ( π β w ) 1 w if w 0 2 π ( π + β w ) 1 + w otherwise
In summary, we use the fast inverse square root algorithm to represent everything from sensor measurements to attitude computation in a multiply–add operation. This enables fast and low-power computation, even on embedded systems with limited computational resources.

3. Results

We confirm the effectiveness of the proposed stateful rotor and fast sensor fusion by using it. In Section 3.1, we confirmed through simulation that the stateful rotor guaranteed continuity of all four parameters of the rotor with respect to the time variation of the angle. In Section 3.2, we confirmed that sensor fusion using stateful rotor worked correctly for arbitrary 3D rotations through experiments using actual sensors.

3.1. Effects of Stateful Rotor

We performed simulations to compare the quaternion q r s reconstructed from the accelerometer and magnetometer before and after transformation to statefulness. The item to be verified here was the four parameters of the quaternion by using stateful rotor maintained continuity for time-varying angles. In addition to the DCM used for sensor fusion, we also applied the stateful rotor to FQA and SAAM to confirm its applicability to other methods.
The transformation to statefulness was confirmed to remove rotor discontinuity for when the angle θ changes continuously. The angle was varied continuously from 360 deg to 360 deg, and the axis of rotation was n ( 1 , 2 , 3 ) from 360 deg to 120 deg and n = ( 0 , 0 , 1 ) from 120 deg to 360 deg. It also varied continuously from 120 deg to 120 deg in between. The initial value of state was q ^ r , 0 = ( 1 , 0 , 0 , , 0 ) .
The respective stateless and stateful results are shown in Figure 7, Figure 8 and Figure 9.
According to the results, DCM and FQA have the same calculation results; whereas statelessness causes a discontinuity point, a transformation to statefulness makes the change continuous. By comparison, SAAM is faster but has a singular rotational axis, and the calculation results at approximately n = ( 0 , 0 , 1 ) become q r = ( 0 , 0 , 0 , 0 ) . Therefore, by calculating the rotor based on a change to statefulness, the method based on DCM without a singular rotation axis is suitable for embedded applications with a minute amount of computation, which is approximately the same as that for SAAM.

3.2. Sensor Fusion of Rotor with Complementary Filter

Next, we experiment with the fast computation of sensor fusion and angle estimates for the rotor using complementary filters based on conversion to statefulness. A DCM-based method is used to obtain q r s from the accelerometer and magnetometer. The verification item from this experiment is to confirm that the four parameters of the respective rotors of q r s and q r ω are restored to the desired values. We also confirm that the angle measurements are correct when they are combined by sensor fusion.
Because the dynamic characteristics of the complementary filter have to be verified, experiments were conducted using actual equipment. The sensor was an MPU9250 (InvenSense) with a sampling time of d t = 0.1 s. The device used in the experiment is shown in Figure 10 and the measured values from the sensor are shown in Figure 11.
The sensors were calibrated using only the values on the datasheet, and were not calibrated for individual differences. The first half of the experiment involved a rotation around the y-axis, whereas the second half involved a rotation around the z-axis, each ranging 360 deg. In this experiment, the sensor was held in the hand at a speed of one rotation approximately every four seconds. Therefore, the frequency response α of the complementary filter was experimentally searched to be able to follow the frequency of such human motion.
Based on these data, the results of the stateless complementary filter are shown on the left side of Figure 12. The stateless complementary filter synthesized the measured values with different frequency characteristics by a first-order infinite impulse response low-pass filter and high-pass filter to keep the gain at one. Therefore, as a design principle, the two values to be synthesized should have the same trend. However, according to the left side of Figure 12, the values of q r s and q r ω are completely different, and thus the synthesis failed.
Next, the results of the computation of the rotor by the complementary filter when it was converted to statefulness are shown in the right side of Figure 12. The continuity of q r s is guaranteed, eliminating discontinuities, and the behavior is close to that of q r ω calculated by fast quaternion integration based on the gyro sensor measurements. Therefore, these could be synthesized simply by a complementary filter using the regions where each frequency characteristic is strong, and the rotor update calculation could be performed reliably.

4. Discussion

In this section, we first discuss, from the experimental results, that sensor fusion at the rotor stage, which could not be performed by the conventional method (stateless), is now possible by using a stateful rotor. Next, we discuss the objectives of this study, namely, the reduction in computational cost and implementation of a multiply–add operation.

4.1. Usefulness of Conversion to Statefulness

Through the conversion of the rotor to statefulness, q ^ r s was calculated quickly without a singular rotation axis using DCM, whereas q ^ r c was calculated via a combination of gyro sensor integration with fast quaternion integrating with a complementary filter, and its effect was confirmed through experiments. Herein, the conversion from rotor to attitude angle estimates, which was the objective, is considered. For sagittal surfaces, arctangent calculations can be used after projection, but in this case, a fast arccos approximation method, expressed as Equation (19), is used. Figure 13 shows the calculation results.
As shown in the results, for the stateless rotor and because of the state ambiguity caused by the double covering problem, the composite by the complementary filter failed. This failure resulted in angle estimates that were far from the true value or the gyro-integral value, which was close to the true value. Therefore, the conventional method stateless rotor can only be used to the extent that it does not exceed the point of discontinuity. On the other hand, the stateful rotor is able to track the rotation state well, even after a 360-deg rotation, and the estimated attitude angle is close to the gyro-integral value. In addition, the effect of the complementary filter eliminates the integration error remaining in the gyro-integral value, indicating that the sensor attitude angle can be estimated with good frequency response.
Next, a more specific example of measured thigh motion during walking is shown in Figure 14. This walking motion is measured simultaneously with an optical motion capture system. The results show that IMU using the proposed stateful algorithm is able to measure the same motions as motion capture. However, the stateless algorithm shows that there is an attitude that makes the calculation wrong when it turns around. This is due to the jump in states shown in the simulation, and we have confirmed that the stateful algorithm can solve this problem.
In summary, we confirmed that sensor fusion failed with the conventional using the stateless rotor, but stable attitude measurement was possible with the proposed stateful rotor. For limitation, there is no restriction on the rotational motion because the algorithm measures two rotational movements in arbitrary axes this time, and there are no singularities or gimbal locks, and the algorithm supports infinite rotation. In addition, for human body measurement applications, wearable IMUs do not have the limitations of the measurement area as optical motion capture has. In this time, experimental parameter search was conducted so that the frequency response of the complementary filter would be optimized by human motion. Although it cannot be adaptively optimized like the Kalman gain of a Kalman filter, it has a degree of freedom as a design parameter in measurements where the frequency response can be estimated.

4.2. Calculation Cost

Herein, the computation speed is considered. In an embedded system, the computation speed is proportional to the amount of central processing unit (CPU) time required for an operation, and because the CPU time varies depending on the capabilities of the CPU and microcontroller unit (MCU) used, we count the number of operations required for a computation.
First, the computational complexity of finding q r s from magnetometer and acceleration sensor measurements is determined. This is then compared with the computational complexity of the algorithm after orthogonalization and normalization of the sensor data. The results are shown in Table 1. The proposed algorithm is as fast as SAAM, and by using the fast inverse square root, all calculations can be performed using multiply–add operations.
Next, we consider the computational cost of the gyro-integral and complementary filters required for sensor fusion. With regard to updating based on q p , there were many methods that treated ω as an antisymmetric matrix [3,43,44,45,46,47,48,49,50]. Almost all the methods, from those designed by Bortz in the 1970s [12] to those in the 2020s, used this technique. However, this approach is computationally expensive. In contrast, if the rotor q r is used as a base, the “Fast Quaternion Integration for Attitude Estimation” approach [51,52], which is an intuitive update law based on the definition of the rotor, becomes available.
The computational cost of the gyro-integral and complementary filters required for sensor fusion is shown in Table 2.
Conversion to statefulness is also a multiply–add operation because it is the inner product of vectors, and thus the entire algorithm can be expressed as a multiply–add operation. The conversion to angles can also be calculated via the residual correction method using Equation (19). Therefore, even MCUs that do not have floating-point units can perform attitude calculations at high speeds.
In summary, the computational cost of the proposed method was discussed. The computation cost of q r s , which is the most computationally expensive, was comparable to that of other optimal methods and can be implemented entirely by a multiply-add operation, which is fast. In addition, since a complementary filter is used for sensor fusion, this can also be performed using only a multiply–add operation, making it an optimized structure for embedded systems. The final angle calculation can also be performed only by a multiply–add operation using our fast approximation of nonlinear functions. Therefore, by optimizing all calculations using a multiply–add operation, it is an optimal attitude calculation algorithm for embedded systems.

5. Conclusions

In this study, for the purpose of high-speed computation for embedded systems using low-performance CPUs, such as MCUs, q r s was computed quickly from sensor measurements using DCM, and gyro-sensor values were processed using fast quaternion integration for complementary filtering. Using the fast inverse square root algorithm and other algorithms, all of these could be easily computed using only multiply–add operations, making the algorithm suitable for embedded systems.
As shown in one example in the experiment, the proposed method has the potential to be used for stable and fast measurement of human body motion. In particular, because the proposed algorithm does not have a singular posture, it is considered effective for complex three-dimensional movements in which the axis is not fixed, such as upper body rotational movements. For future work, we will develop a wearable sensor as a small embedded system to measure more complex human body movements and investigate the range of applicability and limitations of the proposed method.

Author Contributions

Conceptualization, T.K.; investigation, T.K.; methodology, T.K.; supervision, T.T.; validation, T.K. and T.T.; writing—original draft, T.K.; writing—review and editing, T.T. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

Not applicable.

Conflicts of Interest

The authors declare no conflict of interest.

References

  1. Krzysztof, K.; Świetlicka, A.; Majchrzycki, M.; Gugała, K.; Karoń, I.; Rybarczyk, A. Nine-Axis IMU Sensor Fusion Using the AHRS Algorithm and Neural Networks; University of West Bohemia: Plzen, Czech Republic, 2013. [Google Scholar]
  2. Wondosen, A.; Jeong, J.S.; Kim, S.K.; Debele, Y.; Kang, B.S. Improved Attitude and Heading Accuracy with Double Quaternion Parameters Estimation and Magnetic Disturbance Rejection. Sensors 2021, 21, 5475. [Google Scholar] [CrossRef] [PubMed]
  3. Renaudin, V.; Combettes, C. Magnetic, Acceleration Fields and Gyroscope Quaternion (MAGYQ)-Based Attitude Estimation with Smartphone Sensors for Indoor Pedestrian Navigation. Sensors 2014, 14, 22864–22890. [Google Scholar] [CrossRef] [PubMed] [Green Version]
  4. Alaimo, A.; Artale, V.; Milazzo, C.; Ricciardello, A. Comparison between Euler and quaternion parametrization in UAV dynamics. AIP Conf. Proc. 2013, 1558, 1228–1231. [Google Scholar] [CrossRef]
  5. Carino Escobar, J.; Abaunza Gonzalez, H.; Castillo Garcia, P. Quadrotor Quaternion Control. In Proceedings of the 2015 International Conference on Unmanned Aircraft Systems (ICUAS), Denver, CO, USA, 9–12 June 2015. [Google Scholar] [CrossRef]
  6. Mur-Artal, R.; Montiel, J.M.M.; Tardos, J.D. ORB-SLAM: A Versatile and Accurate Monocular SLAM System. IEEE Trans. Robot. 2015, 31, 1147–1163. [Google Scholar] [CrossRef] [Green Version]
  7. Kusaka, T.; Tanaka, T.; Kajiwara, H. Residual correction method for fast calculation of arctangent in embedded systems. In Proceedings of the 2015 IEEE International Conference on Advanced Intelligent Mechatronics (AIM), Busan, Korea, 7–11 July 2015; pp. 42–47. [Google Scholar] [CrossRef]
  8. Kusaka, T.; Tanaka, T. Fast and Accurate Approximation Methods for Trigonometric and Arctangent Calculations for Low-Performance Computers. Electronics 2022, 11, 2285. [Google Scholar] [CrossRef]
  9. Tsuchiya, Y.; Imamura, Y.; Tanaka, T.; Kusaka, T. Estimating Lumbar Load During Motion with an Unknown External Load Based on Back Muscle Activity Measured with a Muscle Stiffness Sensor. J. Robot. Mechatron. 2018, 30, 696–705. [Google Scholar] [CrossRef]
  10. Kusaka, T.; Tanaka, T.; Kaneko, S.; Suzuki, Y.; Saito, M.; Kajiwara, H. Assist Force Control of Smart Suit for Horse Trainers Considering Motion Synchronization. Int. J. Autom. Technol. 2009, 3, 723–730. [Google Scholar] [CrossRef]
  11. Yoshida, M.; Tanaka, T.; Tsuchiya, Y.; Kusaka, T. Reducing Lumbar Load with Active Corset. J. Robot. Mechatron. 2018, 30, 740–751. [Google Scholar] [CrossRef]
  12. Bortz, J.E. A New Mathematical Formulation for Strapdown Inertial Navigation. IEEE Trans. Aerosp. Electron. Syst. 1971, AES-7, 61–66. [Google Scholar] [CrossRef]
  13. Caron, F.; Duflos, E.; Pomorski, D.; Vanheeghe, P. GPS/IMU data fusion using multisensor Kalman filtering: Introduction of contextual aspects. Inf. Fusion 2006, 7, 221–230. [Google Scholar] [CrossRef]
  14. Lefferts, E.; Markley, F.; Shuster, M. Kalman Filtering for Spacecraft Attitude Estimation. J. Guid. Control Dyn. 1982, 5, 417–429. [Google Scholar] [CrossRef]
  15. Sabatini, A. Quaternion-based extended Kalman filter for determining orientation by inertial and magnetic sensing. IEEE Trans. Biomed. Eng. 2006, 53, 1346–1356. [Google Scholar] [CrossRef]
  16. Sabatini, A.M. Kalman-filter-based orientation determination using inertial/magnetic sensors: Observability analysis and performance evaluation. Sensors 2011, 11, 9182–9206. [Google Scholar] [CrossRef]
  17. Wang, L.; Zhang, Z.; Sun, P. Quaternion-Based Kalman Filter for AHRS Using an Adaptive-Step Gradient Descent Algorithm. Int. J. Adv. Robot. Syst. 2015, 12, 131. [Google Scholar] [CrossRef]
  18. Wu, J.; Zhou, Z.; Fourati, H.; Liu, M. Recursive Linear Continuous Quaternion Attitude Estimator From Vector Observations. IET Radar Sonar Navig. 2018, 12, 1196–1207. [Google Scholar] [CrossRef]
  19. Mahony, R.; Trumpf, J. Equivariant Filter Design for Kinematic Systems on Lie Groups. IFAC-PapersOnLine 2021, 54, 253–260. [Google Scholar] [CrossRef]
  20. Madgwick, S. An efficient orientation filter for inertial and inertial/magnetic sensor arrays. Rep. X-Io Univ. Bristol (UK) 2010, 25, 113–118. [Google Scholar]
  21. Santos, S.; Folgado, D.; Rodrigues, J.; Mollaei, N.; Fujão, C.; Gamboa, H. Exploring Inertial Sensor Fusion Methods for Direct Ergonomic Assessments. In Biomedical Engineering Systems and Technologies, Proceedings of the 13th International Joint Conference, BIOSTEC 2020, Valletta, Malta, 24–26 February 2020; Ye, X., Soares, F., De Maria, E., Gómez Vilda, P., Cabitza, F., Fred, A., Gamboa, H., Eds.; Communications in Computer and Information Science; Springer International Publishing: Cham, Switzerland, 2021; pp. 289–303. [Google Scholar] [CrossRef]
  22. Briales, E.; Urda, P.; Escalona, J.L. Track frame approach for heading and attitude estimation in operating railways using on-board MEMS sensor and encoder. Measurement 2021, 184, 109898. [Google Scholar] [CrossRef]
  23. Kim, S.U.; Lee, J.; Yoon, J.; Ko, S.K.; Kim, J. Robust methods for estimating the orientation and position of IMU and MARG sensors. Electron. Lett. 2021, 57, 816–818. [Google Scholar] [CrossRef]
  24. Madgwick, S.O.H.; Harrison, A.J.L.; Vaidyanathan, R. Estimation of IMU and MARG orientation using a gradient descent algorithm. In Proceedings of the 2011 IEEE International Conference on Rehabilitation Robotics, Zurich, Switzerland, 29 June–1 July 2011; pp. 1–7. [Google Scholar] [CrossRef]
  25. Al-Fahoum, A.; Abadir, M. Design of a Modified Madgwick Filter for Quaternion-Based Orientation Estimation Using AHRS. Int. J. Comput. Electr. Eng. 2018, 10, 174–186. [Google Scholar] [CrossRef] [Green Version]
  26. Mahony, R.; Hamel, T.; Pflimlin, J.M. Nonlinear Complementary Filters on the Special Orthogonal Group. IEEE Trans. Autom. Control 2008, 53, 1203–1218. [Google Scholar] [CrossRef] [Green Version]
  27. Del Rosario, M.; Lovell, N. Quaternion-Based Complementary Filter for Attitude Determination of a Smartphone. IEEE Sens. J. 2016, 16, 6008–6017. [Google Scholar] [CrossRef]
  28. Shoemake, K. Quaternions. 1994. Available online: https://web.archive.org/web/20200503045740/http://www.cs.ucr.edu/~vbz/resources/quatut.pdf (accessed on 11 September 2022).
  29. Dam, E.B.; Koch, M.; Lillholm, M. Quaternions, Interpolation and Animation; Technical Report; Datalogisk Institut, Kobenhavns Universitet: Copenhagen, Denmark, 1998. [Google Scholar]
  30. Vicci, L. Quaternions and Rotations in 3-Space: The Algebra and Its Geometric Interpretation; Technical Report; UNC: Chapel Hill, NC, USA, 2001. [Google Scholar]
  31. Black, H.D. A passive system for determining the attitude of a satellite. AIAA J. 1964, 2, 1350–1351. [Google Scholar] [CrossRef]
  32. Shuster, M.D.; Oh, S.D. Three-axis attitude determination from vector observations. J. Guid. Control 1981, 4, 70–77. [Google Scholar] [CrossRef]
  33. Moroz, L.V.; Samotyy, V.V.; Horyachyy, O.Y. Modified Fast Inverse Square Root and Square Root Approximation Algorithms: The Method of Switching Magic Constants. Computation 2021, 9, 21. [Google Scholar] [CrossRef]
  34. Walczyk, C.J.; Moroz, L.V.; Cieśliński, J.L. Improving the Accuracy of the Fast Inverse Square Root by Modifying Newton–Raphson Corrections. Entropy 2021, 23, 86. [Google Scholar] [CrossRef]
  35. Eberly, D.H. GPGPU Programming for Games and Science; A K Peters/CRC Press: New York, NY, USA, 2014. [Google Scholar] [CrossRef]
  36. id-Software/Quake-III-Arena. 2022. Available online: https://github.com/id-Software/Quake-III-Arena/blob/master/code/game/q_math.c (accessed on 31 January 2012).
  37. Warren, H.S. Hacker’s Delight, 2nd ed.; Pearson Education: London, UK, 2013. [Google Scholar]
  38. Hasnat, A.; Bhattacharyya, T.; Dey, A.; Halder, S.; Bhattacharjee, D. A fast FPGA based architecture for computation of square root and Inverse Square Root. In Proceedings of the 2017 Devices for Integrated Circuit (DevIC), Kalyani, India, 23–24 March 2017; pp. 383–387. [Google Scholar] [CrossRef]
  39. Calusdian, J.; Yun, X.; Bachmann, E. Adaptive-gain complementary filter of inertial and magnetic data for orientation estimation. In Proceedings of the 2011 IEEE International Conference on Robotics and Automation, Shanghai, China, 9–13 May 2011; pp. 1916–1922. [Google Scholar] [CrossRef] [Green Version]
  40. Valenti, R.G.; Dryanovski, I.; Xiao, J. Keeping a Good Attitude: A Quaternion-Based Orientation Filter for IMUs and MARGs. Sensors 2015, 15, 19302–19330. [Google Scholar] [CrossRef] [Green Version]
  41. Yi, C.; Ma, J.; Guo, H.; Han, J.; Gao, H.; Jiang, F.; Yang, C. Estimating Three-Dimensional Body Orientation Based on an Improved Complementary Filter for Human Motion Tracking. Sensors 2018, 18, 3765. [Google Scholar] [CrossRef] [Green Version]
  42. Wu, J.; Zhou, Z.; Fourati, H.; Cheng, Y. A Super Fast Attitude Determination Algorithm for Consumer-Level Accelerometer and Magnetometer. IEEE Trans. Consum. Electron. 2018, 64, 375–381. [Google Scholar] [CrossRef]
  43. Phuong, N.H.Q.; Kang, H.J.; Suh, Y.S.; Ro, Y.S. A DCM Based Orientation Estimation Algorithm with an Inertial Measurement Unit and a Magnetic Compass. J. Univers. Comput. Sci. 2009, 15, 859–876. [Google Scholar]
  44. Won, S.h.; Parnian, N.; Golnaraghi, F.; Melek, W. A quaternion-based tilt angle correction method for a hand-held device using an inertial measurement unit. In Proceedings of the 2008 34th Annual Conference of IEEE Industrial Electronics, Orlando, FL, USA, 10–13 November 2008; pp. 2971–2975. [Google Scholar] [CrossRef]
  45. Pongsak, L.; Okada, M.; Sinohara, T. Attitude Estimation by Compensating Gravity Direction. In Proceedings of the 21th Annual Conference of the Robotics Society in Japan, Tokyo, Japan, 20–22 September 2003. [Google Scholar]
  46. Cruz, S. IMU Data Processing to Recognize Activities of Daily Living with a Smart Headset. Master’s Thesis, University of California, Santa Cruz, CA, USA, 2018; 115p. [Google Scholar]
  47. Wrona, M. Designing a Quaternion-Based EKF for Accelerometer, Gyroscope, & Magnetometer Fusion. Section: Posts. 2020. Available online: https://mwrona.com/posts/attitude-ekf/ (accessed on 31 July 2022).
  48. Narayan, A. How to Integrate Quaternions. 2017. Available online: https://www.ashwinnarayan.com/post/how-to-integrate-quaternions/ (accessed on 31 July 2022).
  49. Cavaliere, A.D. Calculating Tait Bryan Angles by Acceleration and Gyroscope Sensors Signal Fusion. 2016. Available online: https://www.monocilindro.com/2016/06/04/how-to-calculate-tait-bryan-angles-acceleration-and-gyroscope-sensors-signal-fusion/ (accessed on 31 July 2022).
  50. Yadav, N.; Bleakley, C. Accurate Orientation Estimation Using AHRS under Conditions of Magnetic Distortion. Sensors 2014, 14, 20008–20024. [Google Scholar] [CrossRef] [PubMed]
  51. Phillip. Phillip’s Technology Corner: Fast Quaternion Integration for Attitude Estimation. 2014. Available online: http://philstech.blogspot.com/2014/09/fast-quaternion-integration-for.html (accessed on 31 July 2022).
  52. Wetzstein, G. Inertial Measurement Units II. Available online: https://stanford.edu/class/ee267/lectures/lecture10.pdf (accessed on 31 July 2022).
Figure 1. Incontinuity of rotor’s definition.
Figure 1. Incontinuity of rotor’s definition.
Sensors 22 07989 g001
Figure 2. Block diagram of stateful rotor.
Figure 2. Block diagram of stateful rotor.
Sensors 22 07989 g002
Figure 3. Continuity and uniqueness of stateful rotor when the initial state q ^ r , 0 is close to q r , 1 .
Figure 3. Continuity and uniqueness of stateful rotor when the initial state q ^ r , 0 is close to q r , 1 .
Sensors 22 07989 g003
Figure 4. Continuity and uniqueness of stateful rotor when the initial state q ^ r , 0 is far from q r , 1 .
Figure 4. Continuity and uniqueness of stateful rotor when the initial state q ^ r , 0 is far from q r , 1 .
Sensors 22 07989 g004
Figure 5. Block diagram of stateful complementary filter.
Figure 5. Block diagram of stateful complementary filter.
Sensors 22 07989 g005
Figure 6. Approximation for fast posture estimasion.
Figure 6. Approximation for fast posture estimasion.
Sensors 22 07989 g006
Figure 7. Comparison between stateless DCM (left) and stateful DCM (right).
Figure 7. Comparison between stateless DCM (left) and stateful DCM (right).
Sensors 22 07989 g007
Figure 8. Comparison between stateless FQA (left) and stateful FQA (right).
Figure 8. Comparison between stateless FQA (left) and stateful FQA (right).
Sensors 22 07989 g008
Figure 9. Comparison between stateless SAAM (left) and stateful SAAM (right).
Figure 9. Comparison between stateless SAAM (left) and stateful SAAM (right).
Sensors 22 07989 g009
Figure 10. Experimental device for retrieving 9-axis sensor data.
Figure 10. Experimental device for retrieving 9-axis sensor data.
Sensors 22 07989 g010
Figure 11. Experimental data obtained from actual equipment (MPU9250).
Figure 11. Experimental data obtained from actual equipment (MPU9250).
Sensors 22 07989 g011
Figure 12. Comparison of sensor fusion results between stateless and stateful rotors.
Figure 12. Comparison of sensor fusion results between stateless and stateful rotors.
Sensors 22 07989 g012
Figure 13. Fast angle estimation for stateful rotor.
Figure 13. Fast angle estimation for stateful rotor.
Sensors 22 07989 g013
Figure 14. Measurement of walking motion using wearable IMU and optical motion capture. (a) Motion capture experiment (IMU placed on right thigh). (b) Comparison among motion capture and stateful/less IMU (shaded areas are within the motion capture measurement volume).
Figure 14. Measurement of walking motion using wearable IMU and optical motion capture. (a) Motion capture experiment (IMU placed on right thigh). (b) Comparison among motion capture and stateful/less IMU (shaded areas are within the motion capture measurement volume).
Sensors 22 07989 g014
Table 1. Comparison of calculation cost of q r s (results of SAAM and FQA are cited from [42]).
Table 1. Comparison of calculation cost of q r s (results of SAAM and FQA are cited from [42]).
+×/ cos ·
DCM-based without fast inverse square root135110
DCM-based with fast inverse square root159000
SAAM1816120
FQA1853436
Table 2. Calculation cost of complementary filtering.
Table 2. Calculation cost of complementary filtering.
+×/ ·
Fast quaternion integration3700
Complementary filter241600
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Share and Cite

MDPI and ACS Style

Kusaka, T.; Tanaka, T. Stateful Rotor for Continuity of Quaternion and Fast Sensor Fusion Algorithm Using 9-Axis Sensors. Sensors 2022, 22, 7989. https://doi.org/10.3390/s22207989

AMA Style

Kusaka T, Tanaka T. Stateful Rotor for Continuity of Quaternion and Fast Sensor Fusion Algorithm Using 9-Axis Sensors. Sensors. 2022; 22(20):7989. https://doi.org/10.3390/s22207989

Chicago/Turabian Style

Kusaka, Takashi, and Takayuki Tanaka. 2022. "Stateful Rotor for Continuity of Quaternion and Fast Sensor Fusion Algorithm Using 9-Axis Sensors" Sensors 22, no. 20: 7989. https://doi.org/10.3390/s22207989

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop