**4.4 Orientation update using magnetic sensors**

Huang et al (2010) update orientation using magnetic field signals from magnetic sensors, i.e., magnetometers.

In order to determine the orientation of the sensor module for rotation representation and transformation between the l-frame and the b-frame, the Euler angles must be determined. In the swing phases, the Euler angles are calculated through integration of the angular velocity over time assuming that the original orientation of the sensor module is known. However, the original orientation is usually unknown in reality. In addition, the gyroscope signal summed during integration is perturbed by gyroscope bias. Thus the accuracy of the

The Application of Magnetic Sensors in Self-Contained Local Positioning 77

x (North)

hy

No matter whether a person is standing or walking, the sensor module attached to the human body is not confined to a flat and level plane. This makes it more difficult to determine the heading direction, because the tilt angles of the x-axis and the y-axis are always changing and the sensor module cannot stay horizontal to the earth's surface. Errors

To compensate the tilt of the sensor module when it is in an arbitrary position, the l-frame is transformed into the b-frame through three rotations with Euler angles ψ, θ and

sequence. The DCMs of the rotations are denoted as **R**1(*ψ*, z), **R**2(*θ*, y) and **R**3(*ϕ*, x) respectively. These Euler angles are related to the tilt but they are not all the tilts of the

> b T <sup>T</sup> sin sin cos cos cos *<sup>l</sup>* **g Rg**

2 2

 

atan 2 , *ggg xyz* (14)

in

(13)

y (East)

Magnetic Field

Heading

Fig. 6. Heading defined in the horizontal x-y plane

z (Down)

hz

hx

caused by tilt angles can be large if not compensated.

sensor module. The algorithm (Huang et al 2010) is as follows.

where **g**b = (gx gy gz]T and **g**l = (0 0 1]T. Therefore, we have

Rotations of the gravity vector from the l-frame to the b-frame are given by

orientation will decay overtime. Therefore, Huang et al (2010) use magnetometers to detect the magnetic field of the earth. Using data from magnetometers, together with gyroscopes and accelerometers, the orientation in the beginning of each human walk can be found. Similarly, the orientation of the sensor module in stance phase, when the sensor module is in a near-static status, can be updated in each gait. With the updates of orientation in stance phases, the integral drifts of rotated angles, which increase linearly over time, are greatly reduced.

To find the near-static orientation, the Euler angles *ψ*, *θ* and *φ* must be calculated. Because gyroscopes cannot be used in a near-static status, signals from accelerometers and magnetometers have to be used to calculate the orientations of the sensor module. However, these angles cannot be obtained directly. To resolve this problem, the tilts and heading of the sensor module need to be investigated.

Both x-tiltαand y-tilt β of the sensor module, or the sensor on it, as shown in Fig. 5, can be found simultaneously using acceleration outputs of all three axes as below:

$$\alpha = \operatorname{atan2}\left(a\_{x'}\sqrt{a\_y^2 + a\_z^2}\right) \tag{10}$$

$$\mathcal{B} = \operatorname{atan2}\left(a\_{y'} \sqrt{a\_x^2 + a\_z^2}\right) \tag{11}$$

where the two-argument function, atan2, is a variation of the arctangent function. For any real arguments *x* and *y*, which are not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.

The heading of a pedestrian, thus that of the sensor module on him/her, can be calculated using the x-axis and y-axis magnetic field outputs if the sensor module is level in a horizontal plane. As shown in Fig. 6, only the *x* and *y* components of the Earth's magnetic field, are used when determining the heading of sensor module. The headingγ is defined by:

$$\gamma = \operatorname{atan2} \{ h\_{\mathbf{y}}, h\_{\mathbf{x}} \} \tag{12}$$

where *h*x, *h*y and *h*z are components of magnetic field on x, y, z axis respectively.

Fig. 5. x-tilt and y-tilt assignments relative to ground

orientation will decay overtime. Therefore, Huang et al (2010) use magnetometers to detect the magnetic field of the earth. Using data from magnetometers, together with gyroscopes and accelerometers, the orientation in the beginning of each human walk can be found. Similarly, the orientation of the sensor module in stance phase, when the sensor module is in a near-static status, can be updated in each gait. With the updates of orientation in stance phases, the integral drifts of rotated angles, which increase linearly over time, are

To find the near-static orientation, the Euler angles *ψ*, *θ* and *φ* must be calculated. Because gyroscopes cannot be used in a near-static status, signals from accelerometers and magnetometers have to be used to calculate the orientations of the sensor module. However, these angles cannot be obtained directly. To resolve this problem, the tilts and heading of

Both x-tiltαand y-tilt β of the sensor module, or the sensor on it, as shown in Fig. 5, can be

2 2 atan 2 , *x yz*

2 2 atan 2 , *<sup>y</sup> x z*

where the two-argument function, atan2, is a variation of the arctangent function. For any real arguments *x* and *y*, which are not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.

The heading of a pedestrian, thus that of the sensor module on him/her, can be calculated using the x-axis and y-axis magnetic field outputs if the sensor module is level in a horizontal plane. As shown in Fig. 6, only the *x* and *y* components of the Earth's magnetic field, are used

y x

*a aa* (10)

*a aa* (11)

atan 2( , ) *h h* (12)

x

β

α

y

found simultaneously using acceleration outputs of all three axes as below:

when determining the heading of sensor module. The headingγ is defined by:

where *h*x, *h*y and *h*z are components of magnetic field on x, y, z axis respectively.

Sensor

Horizontal Plane Gravity Vector

Fig. 5. x-tilt and y-tilt assignments relative to ground

greatly reduced.

the sensor module need to be investigated.

Fig. 6. Heading defined in the horizontal x-y plane

No matter whether a person is standing or walking, the sensor module attached to the human body is not confined to a flat and level plane. This makes it more difficult to determine the heading direction, because the tilt angles of the x-axis and the y-axis are always changing and the sensor module cannot stay horizontal to the earth's surface. Errors caused by tilt angles can be large if not compensated.

To compensate the tilt of the sensor module when it is in an arbitrary position, the l-frame is transformed into the b-frame through three rotations with Euler angles ψ, θ and in sequence. The DCMs of the rotations are denoted as **R**1(*ψ*, z), **R**2(*θ*, y) and **R**3(*ϕ*, x) respectively. These Euler angles are related to the tilt but they are not all the tilts of the sensor module. The algorithm (Huang et al 2010) is as follows.

Rotations of the gravity vector from the l-frame to the b-frame are given by

$$\mathbf{g}^{\text{b}} = \mathbf{R}^{\text{T}} \cdot \mathbf{g}^{\text{l}} = \begin{bmatrix} -\sin\theta & \sin\phi\cos\theta & \cos\phi\cos\theta \end{bmatrix}^{\text{T}} \tag{13}$$

where **g**b = (gx gy gz]T and **g**l = (0 0 1]T. Therefore, we have

$$\theta = \operatorname{atan2}\left(\operatorname{g}\_{"\prime} \sqrt{\left\|\operatorname{g}^{\prime} + \operatorname{g}^{\prime}\right\|}\right) \tag{14}$$

The Application of Magnetic Sensors in Self-Contained Local Positioning 79

Many factors, including size, cost, dynamic range, sampling rate and bias, have to be considered in choosing an appropriate sensor module. Firstly, the size of the sensor module should be small enough to be installed unobtrusively on footwear. Consequently, all 3D gyroscopes, 3D accelerometers and 3D magnetometers should be integrated into, actually orthogonally mounted in, this inertial/magnetic sensor module. Secondly, the price of this sensor module should be low enough to meet budget constraints for the targeted applications. Thirdly, the dynamic range of the sensor module should meet the requirements of the applications. Fourthly, the sampling rate should be high enough to avoid sampling errors. The sampling rate of the sensors should be at least 100 Hz. Finally, because of the sensitivity of sensors to temperature, each sensor in a module should be

With all these considerations an inertial measurement unit (IMU) was selected to build the prototype for testing. The IMU provides serial digital outputs of 3D acceleration, 3D angular

In the experiments, the sensor module is mounted on the arch, i.e., the upper of closed footwear, as shown in Fig 7. The installation of the sensor should ensure that the relative

Using the methods introduced in Section 4 and the sensor module selected in Section 5.1, several experiments have been conducted at different paces in different places and different

times. Most of these experiments are two-dimensional (2D) tests.

individually compensated for bias, which is a function of temperature.

movement between the sensor module and the foot-ware is minimized.

**5.1 Sensor module selection** 

velocity, and 3D magnetic field.

**5.2 Sensor module mounting** 

Fig. 7. Sensor Module Mounting

**5.3 Field experiment** 

This equation is actually the same as equation (10) if the sensor module is not moving. Using equation (13) and (14), we obtain

$$\phi = \operatorname{atan2}\left(g\_y \operatorname{sign}(\cos \theta), g\_z \operatorname{sign}(\cos \theta)\right) \tag{15}$$

This equation is different from equation (11). Hence the angle of roll is not the y-tilt angle *β*. y-tilt should not be used as roll for orientation calculation and magnetometer compensation.

After both pitch *θ*and roll are found from acceleration data, the attitude, or yaw*ψ*, can be found from magnetic field data by solving the following simultaneous equation:

$$\mathbf{m}^{\mathsf{b}} = \mathbf{R}^{\mathsf{T}} \cdot \mathbf{m}^{\mathsf{l}} \tag{16}$$

where **m**b = [*m*<sup>x</sup> *m*<sup>y</sup> *m*z]T, **m**l = [*a 0 b*]T (*a* and *b* are the horizontal and vertical components of the magnetic field of the earth vector) and **R**T=**R**<sup>l</sup> T(*ψ*,z)**R**2T(*θ*,y)**R**<sup>3</sup> T(,x). Hence we get

$$\mathbf{R}\_1^\mathrm{T} \left( \boldsymbol{\psi}, \mathbf{z} \right) \cdot \mathbf{m}^\mathrm{l} = \mathbf{R}\_2^\mathrm{T} \left( \boldsymbol{\theta}, \mathbf{y} \right) \cdot \mathbf{R}\_3^\mathrm{T} \left( \boldsymbol{\phi}, \mathbf{x} \right) \cdot \mathbf{m}^\mathrm{b} \tag{17}$$

As illustrated in Fig. 6, *h*x, *h*y and *h*z are the projections of magnetic field on the horizontal plane and the *z*-axis (pointing downward) respectively, i.e., **h**b = [*h*<sup>x</sup> *h*<sup>y</sup> *h*z]T =(acos*ψ*, -asin*ψ*]T. Then the compensated magnetic field can be obtained as below:

$$h\_x = m\_x \cos \theta + m\_y \sin \theta \sin \phi + m\_z \sin \theta \cos \phi \tag{18}$$

$$h\_y = m\_y \cos \phi - m\_z \sin \phi \tag{19}$$

$$h\_z = m\_x \sin \theta + m\_y \cos \theta \sin \phi + m\_z \cos \theta \cos \phi \tag{20}$$

Accordingly, the heading on the horizontal plane, or the Euler angle yaw, can be defined as

$$\boldsymbol{\nu} = \operatorname{atan2}\left[ -\boldsymbol{h}\_{\mathbf{y}}, \boldsymbol{h}\_{\mathbf{x}} \right] \tag{21}$$

The angle *ψ* calculated in equation (21) is actually a compass reading, i.e., the heading relative to magnetic north. To get the true heading, denoted as*ψ*T here, the magnetic declination *D* must be deduced from the compass reading*ψ*:

$$
\psi\_T = \psi - D \tag{22}
$$

where *D* is the difference between magnetic north and true north. This difference is caused by the tilt of the earth's magnetic field generator relative to the earth's spin axis.

### **5. Experimental study**

To implement the methods introduced in the Section 4,. A commercial sensor module shall be carefully selected And then mounted to on a person rigidly. The result of the on-site pedestrian tracking is promising.
