|
2 | 2 | This library fuses the outputs of an inertial measurement unit (IMU) and stores the heading as a quaternion. It uses a _modified Mahony_ filter that replaces the PI controller with a damped 2nd-order system. The proportional term was removed and the integral term was forced to decay to damp the system. The correction steps are as follows: |
3 | 3 |
|
4 | 4 | __Mahony:__ |
5 | | -$\ E_{k} = \theta_{accel} - \theta_{k-1} $ |
| 5 | +$\ E = \theta_{accel} - \theta_{k-1} $ |
6 | 6 |
|
7 | | -$\ I_{k} = I_{k-1} + {E_{k}}{\Delta t} $ |
| 7 | +$\ I_{k} = I_{k-1} + {E}{\Delta t} $ |
8 | 8 |
|
9 | | -$\ \theta_{k} = \theta_{k-1} + \dot{\theta}{\Delta t} + K_{p}E_{k} + K_{i}I_{k} $ |
| 9 | +$\ \theta_{k} = \theta_{k-1} + \dot{\theta}{\Delta t} + K_{p}E + K_{i}I_{k} $ |
10 | 10 |
|
11 | 11 | __Modified Mahony:__ (this filter) |
12 | | -$\ E_{k} = \theta_{accel} - \theta_{k-1} $ |
| 12 | +$\ E = \theta_{accel} - \theta_{k-1} $ |
13 | 13 |
|
14 | | -$\ I_{k} = K_{p}{E_{k}} + (1 - K_{c})I_{k-1} $ |
| 14 | +$\ I_{k} = K_{p}{E} + (1 - K_{c})I_{k-1} $ |
15 | 15 |
|
16 | 16 | $\ \theta_{k} = \theta_{k-1} + \dot{\theta}{\Delta t} + I_{k} $ |
17 | 17 |
|
18 | 18 | The behavior of the modified filter is analogous to spring-mass system. Kp (stiffness) and Kc (damping) are related by the [Q-factor](https://en.wikipedia.org/wiki/Q_factor). This value is held constant, so the behavior of the filter is controlled by a single parameter (Kp): |
19 | 19 |
|
20 | 20 | $\ K_{c} = \sqrt{ K_{p}/Q } $ |
21 | 21 |
|
22 | | -To improve the response of the filter, the acceleration is checked to see if it lies within a given deviation from its steady-state value (1g vertically). If the acceleration is within this band, it will strongly correct the orientation. However, if the acceleration lies outside of this band, it will barely affect the orientation. This is accomplished with a kalman-like filter that uses the deviation from vertical to update its variance and gain: |
23 | | - |
24 | | -$\ \overrightarrow{a_{rel}} = \overrightarrow{a_{local}} - (0,0,1) $ |
25 | | - |
26 | | -$\ K_{\sigma} = 1/(1 + \frac{ {\sigma}^2 }{ {\sigma}_{acc}^2 } ) $ |
27 | | - |
28 | | -$\ {\sigma}^2 = | \overrightarrow{a_{rel}} |^2 + K_{\sigma}{\sigma}^2 $ |
29 | | - |
30 | | -$\ E_{k} = K_{\sigma} E_{k} $ |
31 | | - |
32 | 22 | As the filter uses a quaternion to encode rotations, it's easy to perform coordinate transformations. The library has functions to: |
33 | 23 | - Transfor a vector to the local or global frame. |
34 | 24 | - Get the unit vectors of the X, Y and Z axes in the local or global frame. |
|
0 commit comments