Mariia Ivanchenko, Khrystyna Mysak, Dzvenyslava Butynets, Ksenia Kretsula.
Inertial Measurement Unit is a specific type of sensor that measures angular rate, force and sometimes magnetic field.
There are many different kinds of IMU devices each containing various measuring tools that pertain to specific uses. For example a 3-axis gyroscope and accelerometer would make up a 6-axis IMU while a 9-axis IMU also contains a 3-axis magnetometer.
Accelerometers are one of the most commonly used motion sensors and are used to measure the rate of change in an object's velocity due to linear forces acting upon it.
We can integrate a vehicle's acceleration to calculate velocity and integrate velocity to calculate distance traveled. So using accelerometer data it is possible to calculate distance from a set start point. In order to more accurately determine the position of a vehicle in 3d space more data types are required.
Acceleration data alone does not account for turns and non-linear movement that a vehicle makes along its journey. To solve this most IMU devices contain a gyroscope which measures angular velocity of three axes roll about the y-axis pitch about the x-axis and yaw about the z-axis. Although gyroscopes have no initial frame of reference like accelerometers when data from both is combined using sensor fusion techniques a vehicle's position and orientation can be reliably calculated. Also, the problem for gyroscope is the zero drift that has to be compensated for any usable application.
Magnetometers are used to measure the strength and direction of a magnetic field. In IMUs, they can provide a point of reference. A magnetometer is mainly used for speed detection and with fusion algorithm it can eliminate the gyroscope offset.
Since IMU does not use known reference points calculations can often contain small errors which in time can add up to larger errors. The Kalman filtering that uses only accelerometer and gyroscope, is a relatively simple state-space algorithm to produce estimates of the hidden variables based on uncertain and inaccurate measurements. It predicts the systems future state based on past estimations and is applied to model systems with multiple noisy inputs and outputs hopefully less noisy and more accurately estimated output data.
Other commonly known algorithms are Sebastian Madgwick's fusion algorithm and Mahony's algorithm.
In this project we are using RISC Microcontroller: STM32F411E-DISCO.
- LSM303DLHC (mag + acc)
- L3GD20 (gyro)
- UART
This is an orientation filter applicable to IMUs consisting of 3-axial gyroscopes and accelerometers, and MARG (magnetic angular rate and gravity) arrays, which also include 3-axial magnetometers, proposed by Sebastian Madgwick.
The filter employs a quaternion representation of orientation to describe the nature of orientations in three-dimensions and is not subject to the singularities associated with an Euler angle representation, allowing accelerometer and magnetometer data to be used in an analytically derived and optimised gradient-descent algorithm to compute the direction of the gyroscope measurement error as a quaternion derivative.
Innovative aspects of this filter include:
- A single adjustable parameter defined by observable systems characteristics.
- An analytically derived and optimised gradient-descent algorithm enabling performance at low sampling rates.
- On-line magnetic distortion compensation algorithm.
- Gyroscope bias drift compensation.
The foundation of quaternions lies in the principles of the complex number system. Complex numbers are represented in two-dimensional space and are expressed as
By adding two imaginary numbers to the complex number system in addition to $i$, we can extend this to a 3-dimensional space. This augmentation results in a quaternion, a four-dimensional mathematical entity introduced by William Rowan Hamilton in 1843.
Link to an article detailing the historical background of the subject.
The set of quaternions is denoted as
where
According to Hamilton’s famous expression:
and
In quaternion algebra, commutativity is not applicable
Rotation from frame A to frame B
An arbitrary orientation of frame B relative to frame A can be achieved through a rotation of angle
The orientation of frame B is achieved by a rotation, from alignment with frame A, of angle θ around the axis
The quaternion describing this orientation
where
Quaternion arithmetic often requires that a quaternion describing an orientation is first normalised. It is therefore conventional for all quaternions describing an orientation to be of unit length.
Quaternion Conjugate
The quaternion conjugate, denoted by ∗, can be used to swap the relative frames described by an orientation. For example,
Quaternion Product
Denoted by
The quaternion product of
Quaternion operations on vectors
A three-dimensional vector can be rotated by a quaternion using the equation:
The orientation described by
Euler angles. Roll, pitch and yaw
Euler angles
-
$\psi$ around$\widehat z_B$ — yaw, -
$\theta$ around$\widehat y_B$ — pitch, -
$\phi$ around$\widehat x_B$ — roll.
This Euler angle representation of
Quaternions provide a few obvious advantages over using matrices or Euler angles for representing rotations in 3D space.
- Rotation concatenation using quaternions is faster than combining rotations expressed in matrix form.
- For unit-norm quaternions, the inverse of the rotation is taken by subtracting the vector part of the quaternion. Computing the inverse of a rotation matrix is considerably slower if the matrix is not orthonormalized (if it is, then it’s just the transpose of the matrix).
- Converting quaternions to matrices is slightly faster than for Euler angles.
- Quaternions only require 4 numbers to represent a rotation whereas a matrix requires at least 9 values.
Orientation from angular rate
A tri-axis gyroscope will measure the angular rate of the
the quaternion derivative describes the rate of change of orientation of the earth frame relative to the sensor frame
The orientation of the earth frame relative to the sensor frame at the time
$$ E^S \dot q{ω,t} = \frac{1}{2} \ ^S_E \widehat q_{est,t-1} \ ⊗ \ ^S\omega_t \tag{15} $$
$$ E^S q{ω,t} = \ ^S_E \widehat q_{est,t-1} + \ E^S \dot q{ω,t}\Delta t \tag{16} $$
provided that initial conditions are known. In these equations,
Orientation from vector observations
A tri-axis accelerometer will measure the magnitude and direction of the field of gravity in the sensor frame compounded with linear accelerations due to the motion of the sensor.
Similarly, a tri-axis magnetometer will measure the magnitude and direction of the earth’s magnetic field in the sensor frame compounded with local magnetic flux and distortions.
In the context of an orientation filter, it will initially be assumed that an accelerometer will measure only gravity, and a magnetometer will measure only the earth’s magnetic field.
Knowing the direction of the Earth's magnetic field in the Earth frame, measuring the field's direction within the sensor frame enables the calculation of the orientation of the sensor frame relative to the Earth frame.
However, for any given measurement there will not be a unique sensor orientation solution, instead, there will be infinite solutions represented by all those orientations achieved by the rotation of the true orientation around an axis parallel with the field.
In some applications, it may be acceptable to use an Euler angle representation allowing an incomplete solution to be found as two known Euler angles (pitch and roll) and one unknown (yaw). The unknown angle is the rotation around an axis parallel to the direction of the field.
A quaternion representation requires a complete solution to be found which involves solving an optimization problem. This is achieved by finding the sensor orientation
To simplify, imagine having a sensor, and you want to figure out how it's oriented relative to the Earth's magnetic field. You know the preferred direction of the Earth's field (
Therefore
where equation
defines the objective function.
The order of multiplication is swapped to ensure that the conjugate
The components of each vector are defined in equations:
Many optimisation algorithms exist but the gradient descent algorithm is one of the simplest to both implement and compute. Equation
describes the gradient descent algorithm for
Equation:
computes the gradient of the solution surface defined by the objective function and its Jacobian; simplified to the 3-row vectors defined by equations:
$$ J^T(^S_E \widehat q_k, \ ^E \widehat d) = \left[\begin{array}{} 2d_yq_4-2d_zq_3 & 2d_yq_3+2d_zq_4 & -4d_xq_3+2d_yq_2-2d_zq_1 & -4d_xq_4+2d_yq_1+2d_zq_2\
-2d_xq_4+2d_zq_2 & 2d_xq_3-4d_yq_2+2d_zq_1 & 2d_xq_2+2d_zq_4 & -2d_xq_1-4d_yq_4+2d_zq_3\
2d_xq_3-2d_yq_2 & 2d_xq_4-2d_yq_1-4d_zq_2 & 2d_xq_1+2d_yq_4-4d_zq_3 & 2d_xq_2+2d_yq_3 \end{array}\right] \tag{25} $$
Equations (22) to (25) describe the general form of the algorithm applicable to a field predefined in any direction. However, if the direction of the field can be assumed to only have components within 1 or 2 of the principle axes of the global coordinate frame then the equations simplify.
An appropriate convention would be to assume that the direction of gravity defines the vertical, z-axis as shown in the equation:
Substituting
for
$$ J^T_g(^S_E \widehat q) = \left[\begin{array}{} -2q_3 & 2q_4 & -2q_1 & 2q_2\
2q_2 & 2q_1 & 2q_4 & 2q_3\
0 & -4q_2 & -4q_3 & 0 \end{array}\right] \tag{29} $$
The earth’s magnetic field can be considered to have components in one horizontal axis and the vertical axis (the vertical component due to the inclination of the field which is between 61.1° and 69.1° to the horizontal in the Ukraine [3]).
Components of Earth's magnetic field:
- total field F,
- horizontal component H,
- vertical component Z,
- north component X,
- east component Y,
- declination D,
- inclination I.
This can be represented by equations representing the Earth's magnetic field vector and the normalised magnetic field vector measured by a sensor respectively:
where
Substituting
$$ J^T_b(^S_E \widehat q, \ ^E \widehat b) = \left[\begin{array}{} -2b_zq_3 & 2b_zq_4 & -4b_xq_3-2b_zq_1 & -4b_xq_4+2b_zq_2\
-2b_xq_4+2b_zq_2 & 2b_xq_3+2b_zq_1 & 2b_xq_2+2b_zq_4 & -2b_xq_1+2b_zq_3\
2b_xq_3 & 2b_xq_4-4b_zq_2 & 2b_xq_1-4b_zq_3 & 2b_xq_2 \end{array}\right] \tag{33} $$
As has already been discussed, the measurement of gravity or the earth’s magnetic field alone will not provide a unique orientation of the sensor. To do so, the measurements and reference directions of both fields may be combined as described by equations:
Whereas the solution surface created by the objective functions in equations (28) and (32) have a minimum defined by a line, the solution surface define by equation (34) has a minimum define by a single point, provided that
A conventional approach to optimisation would require multiple iterations of equation (22) to be computed for each new orientation and corresponding senor measurements. Efficient algorithms would also require the step-size
However, these requirements considerably increase the computational load of the algorithm and are not necessary in this application. It is acceptable to compute one iteration per time sample provided that the convergence rate governed by
calculates the estimated orientation
The form of
An optimal value of
where
Filter fusion algorithm
An estimated orientation of the sensor frame relative to the earth frame
where
An optimal value of
where
Equations (39) and (41) ensure the optimal fusion of
The definition of
It is possible from equation (43) to also assume that
Substituting equations (16), (42) and (43) into equation (39) directly yields equation:
$$ ^S_E q_{est,t} = \frac{\beta \Delta t}{\mu_t} \cdot \bigg(- \mu_t \frac{\nabla f}{|| \nabla f ||}\bigg) + (1-\frac{\beta \Delta t}{\mu_t}) \cdot \bigg(\ ^S_E \widehat q_{est,t-1} + \ E^S \dot q{ω,t}\Delta t \bigg) $$
$$ ^S_E q_{est,t} = \frac{\beta \Delta t}{\mu_t} \cdot \bigg(- \mu_t \frac{\nabla f}{|| \nabla f ||}\bigg) + (1-0) \cdot \bigg(\ ^S_E \widehat q_{est,t-1} + \ E^S \dot q{ω,t}\Delta t \bigg) \tag{44} $$
It is important to note that in equation (44),
Equation (44) can be simplified to equation:
where
and
It can be seen from equations (45) to (47) that the filter calculates the orientation
Block diagram representation of the complete orientation filter implementation for an IMU
Magnetic distortion compensation
Measurements of the earth’s magnetic field will be distorted by the presence of ferromagnetic elements (familiar metals that are noticeably attracted to a magnet, a consequence of their substantial magnetic permeability) in the vicinity of the magnetometer.
These distortions from sources like electrical appliances and metal structures can introduce errors in orientation sensors.
Thus the measured direction of the earth’s magnetic field in the earth frame at time
The effect of an erroneous inclination of the measured direction earth’s magnetic field,
Compensating for magnetic distortions in this way ensures that magnetic disturbances are limited to only affect the estimated heading component of orientation. The approach also eliminates the need for the reference direction of the earth’s magnetic field to be predefined.
Gyroscope bias drift compensation
The gyroscope zero bias will drift over time, with temperature and with motion. Any practical implementation of an IMU or MARG sensor array must account for this. An advantage of Kalman-based approaches is that they are able to estimate the gyroscope bias as an additional state within the system model. However, Mahony showed that gyroscope bias drift may also be compensated for by simpler orientation filters through the integral feedback of the error in the rate of change of orientation. A similar approach will be used here.
The normalised direction of the estimated error in the rate of change of orientation
derived as the inverse to the relationship defined in equation (14). The gyroscope bias
The first element of
The compensated gyroscope measurements
Block diagram representation of the complete filter implementation for a MARG sensor array, including the magnetic distortion and gyroscope bias drift compensation
Filter gains
The filter gain
- sensor noise,
- signal aliasing,
- quantisation errors,
- calibration errors,
- sensor miss-alignment,
- sensor axis non-orthogonality,
- frequency response characteristics.
The filter gain
where
https://ahrs.readthedocs.io/en/latest/filters/madgwick.html
https://nitinjsanket.github.io/tutorials/attitudeest/mahony.html