Kalman Filtering of IMU Sensor For Robot Balance Control
Kalman Filtering of IMU Sensor For Robot Balance Control
by
Gina Angelosanto
The author hereby grants to MIT permission to reproduce and to distribute publicly
paper and electronic copies of this thesis document in whole or in part
in any medium now known or hereafter created.
Signature of Author:
Department of Mechanical Engineering
May 9, 2008
Certified
Certified bv:
b
Wai K. Cheng
Professor of Mechanical Engineering
/
Thesis Supervisor
Certified b
Certified
by:
a r
Anareas noimann
,\,•Dectorof Machine Learning R&D, Vecna Technologies
Thesis Supervisor
Accepted by:_
John H. Lienhard V.
Professor of Mechanical Engineering
Chairman, Undergraduate Thesis Committee
ARCHrIs
Kalman Filtering of IMU Sensor for Robot Balance Control
by
Gina Christine Angelosanto
Abstract
This study explores the use of Kalman filtering of measurements from an inertial
measurement unit (IMU) to provide provide information on the orientation of a robot
for balance control. A test bed was created to characterize the random noise and errors
inherent to orientation sensing in the MicroStrain 3DM-GX1 IMU for static cases as
well as after experiencing an impact force. Balance simulations were performed to
control the center of mass location of a robot modeled as an inverted pendulum. The
controlled center of mass trajectories with state estimates generated from Kalman
filtering were compared, where possible, to the CM trajectory based on unfiltered
sensor measurements of the states. For the simple case of inverted pendulum control,
it was determined that noise and error in the IMU are sufficiently small that Kalman
filtering is not necessary when all states can be measured, but results in significant
improvements in the RMS error of the actual and desired center of mass positions.
measurements and uncorrupted control are inputs to the Kalman filter. ...... 11
3.1 Hardware test bed used to compare angle readings of the IMU and a magnet encoder. 13
link of length 1 extends from the zero moment point to the center of mass. The
angle of the link with respect to the ground 0, horizontal locations of the center of
mass and zero moment point Xcm and Xzmp, and height of the center of mass zzmp
4.1 Graph of angle in degrees vs. time for both encoder (shown in red) and IMU (shown
in blue). Angle was held at rest for approximately 5 seconds per angle in angle
in blue). This graph shows the angle recordings from the two sensors over a full
360 degrees, and demonstrates that the difference between the IMU and encoder is
line connects error averaged over each angle increment; black dots show error for
each data point included in the angle increment, or the range of the error for each
4.7 Graph on left shows 1000 linear fits to standard deviation of error vs. angle
the frequency of line slopes. Note that the order of magnitude of the standard
deviation is 10-2 degrees, while the order of magnitude of the slopes is 10- 4. . 28
4.8 Graph of angle in degrees vs. time for both encoder (shown in red) and IMU (shown
in blue). Pendulum link holding IMU was released from a 90 degree starting angle,
struck an object at 0 degrees and came to rest for approximately 3 seconds, and
in blue). Pendulum link holding IMU was released from a 90 degree starting angle,
4.15 Center of mass x-position vs. time with an initial displacement of 10 cm, generated
High-power 19g
hydraulic
upper
body
2 Background
The method of least-squares has been used to fit a model to data in a wide
range of applications from finance to engineering. The concept of using a least-
squares analysis on noisy data to find optimal coefficients for a model of a system has
been of particular interest in the field on control theory. One of the main problems
with using least-squares filtering techniques to estimate states in controls is "batch
processing," or the requirement that all measured data be available before a fit to
the data can be generated. Consequently, filtering by least-squares could not occur
in real time [3].
One solution to the problem of real-time least-squares filtering proposed by
Rudolph Kalman in 1960 was a recursive filter that allowed each state estimation
to be made using the method of least-squares as soon as a measurement is taken.
The Kalman filter estimates states based on a mathematical model represented by
linear difference equations; essentially, these state estimations are made by computing
a model-based estimate and adding to it a scaled "residual" representing the difference
between the predicted and actual measurements. The scaling factor, which is
calculated for each time step, is referred to as the Kalman gain and reflects how
much "trust" is placed on the measurements as compared to the model. A small
Kalman gain indicates low confidence in the measurements, while a high Kalman
gain places priority on measurements when estimating the state.
The Kalman filter may be thought of as a two-step process consisting of a
prediction step and a correction step [4]. In the prediction step, the anticipated
state x* based on the linear mathematical model of the system is represented as
where xk-1 is the current state estimate and u represents system inputs. The
anticipated error covariance matrix P* can then be estimated as a function of the
model matrix A, the current error covariance Pk- 1 , and the process noise covariance
Q reflecting random noise at the control input:
Pk = A Pk-1 AT + Q (2)
Pk = (I - Kk H) Pk (5)
This process of predicting and correcting the states repeats for all k. This
description of the Kalman filter assumes white Gaussian noise and a linear model of
the system. The extended Kalman filter has been developed to incorporate nonlinear
difference equations [4]. A more detailed description of the Kalman filter may be
found in [3 - 4].
Figure 2.1 shows a block diagram of Kalman filter implementation in Matlab.
Process noise is added to the control input u; this corrupted control signal is then
sent to the plant. Noise is likewise added to the "true" outputs of the plant, y,
to represent noisy measurements y,. Both the uncorrupted control signal and noisy
measurements are input to the Kalman filter, which outputs the estimated states
Ye based on the recursive least-squares filter discussed above. The Kalman filter
combines both a plant model and measurements to make optimal state estimates in
a least-squares sense.
V
Es
1'
Figure 2.1: Block diagram representation of a system with Kalman filtering [5]. Noisy output
measurements and uncorrupted control are inputs to the Kalman filter.
2.2 Sensor Technology
[9].
3 Methods
A testbed was created to study the measurement error in the IMU. When held
static, the IMU angle was compared to the known angle of the test setup; dynamic
orientation and orientation after impact were compared to angles registered by an
encoder. The hardware, shown in Figure 3.1, consisted of a enclosed Hall-effect
encoder held rigidly inside of an aluminum base. A pendulum link of length 6 inches
was affixed to the shaft of the encoder and had a right-angle shelf on the bottom
where the IMU sat. The IMU was fixed to the link base with heavy-duty foam tape
and zip ties threaded through mounting holes in the IMU. An arc-shaped plate with
(a) Solid model of test bed
Figure 3.1: Hardware test bed used to compare angle readings of the IMU and a magnet encoder.
holes drilled every 10 degrees over a 180 degree interval was attached to the aluminum
base such that a pin, when placed through a hole in the arec and a corresponding hole
in the pendulum link, could hold the link at a fixed angle. The link could be held
at any multiple of 10 degrees over a full circle. The base of the test bed could be
clamped to a tabletop to prevent motion of the base itself as the link was moved.
The parts for the test bed were created from 1/4-inch aluminum sheet, 1-inch
by 2.5-inch extruded rectangular aluminum stock, and 1-inch aluminum L-bracket.
The pendulum link and the affixed shelf to hold the IMU were fabricated with an
Omax waterjet rapid prototyping machine from the aluminum sheet. The solid model
shown in part (a) of figure 3.1 was generated to create the toolpaths for the waterjet;
all holes were deliberately made under-sized and reamed on a drill press to avoid
inaccuracies do to the waterjet kerf lines. The rectangular components of the base
and L-bracket were made with a manual mill with a digital position readout accurate
to .0001 inches. The mill head was realigned immediately before fabrication. The
shelf to hold the IMU was attached to the pendulum link with the L-bracket and the
entire pendulum link assembly was bolted to a gear attached to the encoder shaft as
shown in part (b) of Figure 3.1.
Data was recorded simultaneously from the encoder and the IMU for two cases:
static angle measurements and impact applied to the pendulum link. The base of the
testbed was clamped to a laboratory table for all measurements in order to prevent
the base from moving while the pendulum was in motion. For each case, prior to
measuring the angles the encoder reading was recorded when the pendulum link was
allowed to come to rest hanging freely under its own weight. This position was then
considered the true zero degree point and the value was consequently subtracted
from each encoder reading. Data from the encoder, IMU, and the elapsed time were
recorded on a laboratory computer and imported into Matlab for further analysis.
Encoder values were converted into degrees from the raw data prior to analysis.
The static angle tests involved pinning the pendulum link at a set angle for
approximately 5-10 seconds, then moving the link down one angle increment on the
test bed and repeating the process. Two tests were run recording the static angles
over the entire range of 360 degrees in 10-degree increments, beginning at 90 degrees
(horizontal). Five tests were run recording static angles over a range of 180 degrees,
beginning at 90 degrees and moving in 10-degree increments to -90 degrees. Errors
between the encoder, IMU and expected static angle based on the test setup were
calculated over each angle increment, and the standard deviation of the IMU noise
was determined over the increment as well.
Impact tests involved releasing the pendulum link from a fixed angle so that it
fell freely under its own weight. Ten tests involved an impact force applied to the
pendulum after its release, in the form of a pin inserted into a hole on the test bed
which interfered with the falling pendulum link. For three of these impact tests, the
pendulum was released from 90 degrees, struck a pin at 50 degrees, and remained
at rest for approximately 5 seconds before the pin was removed and the pendulum
continued its fall. Another four tests involved the same process with a pin located at
0 degrees. The final three impact tests involved the pendulum being released from 90
degrees and striking a pin at 0 degrees which was immediately removed, allowing the
pendulum to continue its oscillation about the zero degree point. The time history of
these motions was recorded and imported into Matlab for analysis.
ZCn
X
I I
zmnp m
Figure 3.2: Simplified schematic diagram of "inverted pendulum" model of robot. A massless link
of length 1 extends from the zero moment point to the center of mass. The angle of the link with
respect to the ground 0, horizontal locations of the center of mass and zero moment point Xcm and
Xzmp, and height of the center of mass Zzmp are shown.
zero moment point xz,,p. Three linear equations relating these state variables and
their derivatives are necessary to represent the system in state-determined form. The
input to the system is the velocity of the zero moment point, which is implemented
in real life as the speed of the treads driving the base of the robot. From Figure 3.3,
the forces acting on the center of mass may be expressed as
Fz = F sin 0 = Fz (7)
Combining equations 6 and 7 yields the force acting on the center of mass in the
x-direction as a function of the x positions of the center of mass and zero moment
point, the force on the center of mass in the z-direction, and the height of the center
of mass:
F
Figure 3.3: Force F acting on the center of mass from massless link is shown resolved into
components in the x and z directions.
Fz d2xcm
Fx = zm(xcm - Xzmp) = m d(8)t2
where m is the mass of the robot. This continuous equation can be used to
dt F dt Fz
icm[i + 1] = xcm[i] + ----Fxcm[i] - Xzmpi] (9)
P? Zcm m zcm
and
Xzmp[i + 1] = xzmp[i] + u[i]dt (11)
where u is the control input, i,,p. Combining these equations into the form
7P[i + 1] = AT [i] + Bu[i] yields the following expression used to generate a model of
the plant:
SxCm[i
cm[i
+1]
+ 1] =
1 dt
mdt
z mm
1 Z
0
zcm m
mdt
Xm[i]
icm[i] +
0
0 u[i] (12)
Xzmp[i + 11 0 0 1 Xzmp[i] dt
For the purposes of simulation, the model is considered to be linear; that is, the
variations in the angle 0 are assumed to be within +/- 10 degrees such that sin 0 60.
As a result, there is little variation in the CM height Zzmp, and the acceleration in the
z-direction is negligible such that the force in z is assumed to be only the constant
weight of the center of mass. Consequently, all entries in the matrices A and B are
constants for the linear model.
To form the control law used to determine the x-velocity of the zero moment point,
a PD control law is first used to determine the desired acceleration of the center of
mass ("desired" states are marked with a hat). PD control is used for a fast response
with low overshoot. The terms K, and K, represent the proportional and derivative
gains, respectively.
Next, the desired ZMP velocity (the control input) was computed using propor-
tional control:
Taking a sum of torques about the ZMP using the notation of Figure 3.2 yields
a differential equation for the angular acceleration in terms of 0 and the ZMP
acceleration,
where J is the moment of inertia of the point mass about xzmp and g is the
acceleration due to gravity. This equation can be checked by examining Lagrange
equations for the inverted pendulum with x•m, and its derivatives specified as a
constraint:
In the absence of generalized forces, the single equation required to describe the
constrained motion of the pendulum reduces to
d (aL 0= -. Psin 0+ + gcos 0 (19)
which simplfies to the expression of equation 17. The ZMP acceleration izmp was
calculated by subtracting subsequent values of the control input u (the ZMP velocity)
and dividing by the time step dt. Eqn. 17 was solved in Matlab for 0 using Euler's
method. The initial values of 0 and ) were calculated each time the control input was
changed (that is, every At seconds), as
0= - m(21)
1sin 0o
The state xzmp was calculated by integrating the vector u; ,cmand xzmp were
determined as
A discrete Kalman filter was implemented using the 'kalmf' command to estimate
the states based on the given plant model and state measurements. Simulations were
run with all states measured, then repeated with the CM velocity as an unmeasured
state. Three pieces of information were returned for each simulation: the '"true" CM
position state as determined by the dynamics, the measurement of the CM position
including measurement noise, and the Kalman estimate of the CM position. All
simulations were performed initially with true states generated from the linear plant,
then repeated with true states generated from the nonlinear dynamics simulation.
Control of the CM position was also simulated without filtering where possible to
show how Kalman filtering can improve upon the stability of the system. The
magnitude and form of measurement noise added to the system was based on the
characterization of the noise from physical testing described in the previous section.
Separate simulations were performed using data gathered from static testing and
impact testing to represent two separate cases of "normal" control of the CM position
and control after the IMU has experienced an impact.
The values of constants used in the simulation were a link length 1 of 1 m, CM
height zm of 1 m, z-direction force Fz of 1000 N, and mass m of 100 kg. The value of dt
used for the simulation of dynamics was .01 sec; a value of At during which the same
control input u was applied to the system was chosen to be .1 sec for a mechanical
system. Allowing 10 time steps for dynamics to change between recalculations of the
control input is an attempt to simulate the fact that discrete computation of the input
u may always occur slowly compared to the continuous changes of states due to the
system dynamics. Control parameters used a value of 8 for Kp, 5 for Kv, and 10 for
K1; these were determined by simulating balance control without noise or filtering
and selecting gains to provide a reasonably fast dynamic response with low overshot.
Initial values were set for the system with a .1 m offset of the center of mass in the
positive x-direction, zero CM velocity, and zero as the starting x-position of the ZMP.
4 Results
Figure 4.1 shows examples of the angles recorded from the encoder and the IMU
while the pendulum link was held stationary. In both graphs shown, the angle is
held in increments of roughly 10 degrees for a period of time between 5-10 seconds
before being moved to another angle. Figure 4.1 (a) shows an overview of the sensor
readings over the range of angles from -90 to 90 degrees, which spans the entire range
of angles that the inverted pendulum can achieve, while Figure 4.1 (b) focuses more
closely on the range of angles from 0 to 90 degrees. In both cases, it is clear from
the graphs that there is a wide systematic error in the encoder reading at the +/-
Static Test 1
I
* Encoder
* IMU
-50 -
-inn ~ SI I I
0 20 40 60 80 100 120
Time
(a) IMU and encoder angle vs. time for a range of -90 to 90 degrees.
Static Test 4
* Encoder
* IMU
100 .,owmt
80
60
0 -
20
-f I I I I I #
10 20 30 40 50 60 70
Time
(b) IMU and encoder angle vs. time focused over a range of -90 to 0 degrees.
Figure 4.1: Graph of angle in degrees vs. time for both encoder (shown in red) and IMU (shown in
blue). Angle was held at rest for approximately 5 seconds per angle in angle increments of roughly
10 degrees.
90 degree extremes which tapers down to a much smaller error near zero degrees.
Fortunately, both sensors will be used in real life to measure small fluctuations about
zero degrees, where the systematic error is smallest (note that the angle 0 shown in
Figure 3.2 is different from the angle recorded on the physical setup by 90 degrees).
One incongruity to clarify is the fact that on the robot, the IMU sensor will be
mounted such that the center of mass is in an unstable position (in an "inverted
pendulum" configuration) whereas testing of the IMU was performed such that the
center of mass was allowed to fall into a stable equilibrium (a regular pendulum
configuration). This choice of testing configuration was made so that the IMU could
be made to swing back and forth periodically about a desired point or be allowed
to fall and impact an object at a set angle under gravity. If the configuration of
the testing were reversed such that the pendulum could be made to oscillate around
180 degrees or impact an object as it approached the 180 degree point, some form
of external actuation would be needed to make the pendulum exhibit this behavior,
complicating the hardware test bed unnecessarily. Figure 4.2 shows that when when
the angle at which the pendulum is statically held approaches +/- 180 degrees, the
error between the encoder and the IMU again approaches zero. From these results
it follows that the IMU and encoder error behave the same near 0 and 180 degrees;
consequently, information taken near zero degrees should be useful in describing sensor
behavior on an inverted pendulum.
To average the IMU noise, each region of constant angle (the "flat" ranges of the
graphs in Figures 4.1 and 4.2) registered by both the encoder and the IMU must be
recognized in Matlab as an isolated set of data referred to from here on as a "step".
Steps were defined by first creating a new vector containing every third data point
recorded from the IMU; each element in this vector was then subtracted from the
previous element. When the difference between subsequent resampled angles was
sufficiently large, a "jump" in the angles was reported and the time was used as a
reference point where the previous step ended and a new step began. This method
returned the times corresponding to each individual step in the recorded data. To
compare the IMU and encoder angle readings to the anticipated or '"true" angle
Static Test 3
?nn
Zuu
*
150 0
- *
100 .0
* * * Encoder
S*, IIMU
50 3 3.
CD
0a)
-50 ~.
-100 f~rS
r,0
-150 9t
-0nn
0 50 100 150 200 250 300
Time
Figure 4.2: Graph of angle in degrees vs. time for both encoder (shown in red) and IMU (shown
in blue). This graph shows the angle recordings from the two sensors over a full 360 degrees, and
demonstrates that the difference between the IMU and encoder is minimized around both zero and
+/- 180 degrees.
reading based on the physical testbed, a new vector of the true values was created
with steps in exact 10-degree increments; the times of each step in this true value
vector corresponded to the step times determined by analysis of the IMU and encoder
data. Sensor error was then determined simply as the difference between each element
in the vector of true angles and the actual angle readings recorded by the sensors.
The mean IMU error was determined over each step and is shown as a function of
the angle in Figure 4.3 for a single trial. The mean IMU error vs. angle is plotted
as a dotted line; the range of errors observed in each step are represented as black
dots on the same graph. It is reassuring to note that all observed errors for the IMU
are within the sensor specifications of +/- 2 degrees. The error observed for all trials
ranged between 0.1359 and -1.712 degrees, a span of 1.848 degrees. The IMU error is
likely to be incorrectly biased toward negative values due to the test setup; the pin
used to secure the pendulum link in place, though sized to fit the holes in both the
link and the base, was likely not a prefect fit. Any looseness when the link was pinned
would be seen as a slight negative error due to gravity acting on the link holding the
IMU.
-0.2
-0.6 S .,
t........
........
r\,i ....... - Mean error
*. Error range
..
1'
. .II .. I
Figure 4.3: Graph of IMU error vs. angle in degrees for static angle increments. Red dashed
line connects error averaged over each angle increment; black dots show error for each data point
included in the angle increment, or the range of the error for each average angle.
Another point of concern with reporting the mean orientation of the IMU over
each step is the possibility that the data was not recorded for a sufficiently long
time for the mean of the IMU readings to reflect the steady-state angle reading. To
examine this possibility, the cumulative mean of the IMU values was compared to
the overall average IMU angle for every step. If the cumulative average converged
to the overall average, the sampling time was considered to be adequate. Figure 4.4
shows an example of the cumulative mean converging to the overall mean for one
step, demonstrating that the angle was held constant for a sufficiently long period of
time.
It is clear from the data presented in Figures 4.1 and 4.2 that the hall effect rotary
encoder exhibits only quasi-linear behavior. The error between the encoder and the
19.2 r
19.1
* I 1
I * Cumulative averarie i -
- - Overall average
18.9
18.8
- *
18.7
18.6
r
1o8
in
0I 20 40 60 80 100 120 140 160
Index
Figure 4.4: Cumulative average of encoder angle converging to overall average of encoder angle
across a single 'step.'
-2
-10
-12
-14
Figure 4.5: Encoder error vs. angle. Dots represent mean error over each angle increment; line is
a sine curve fit to the data.
angle of the test bed setup, shown in Figure 4.5, is minimized at zero and +/- 180
degrees and reaches a maximum at +/- 90 degrees. Here, black x-marks show the
averaged encoder error over each step while the red line shows a sine curve fit to the
data. The fit curve is of the form
0.07 _
O Trial 1l · i i O
,0.06 . Trial 2 ........
X Trial 3
.. .... ..........,
s0.05 .....
.... ... 0 .. .........
L, 0
0
S0.04 I
xx
C x xo -0 0o .
S.. .... .. X
. --.....
0.03 I x x i O:
O
* . . . . . . , . . .. .. .
C.O . . 0. ..."..
..... O
.... *:
...
Oox .. X
* . . . . .! . . . . . . . . . . ...
............. i .........
-. -. . . . . .
A .... In , ~~ | | ,
Figure 4.6: Standard deviation of error for each static angle increment vs. mean encoder reading.
Data for three trials is shown.
U.U0 12
I
x Data
0.07 - Linear fit
100
I 0.06
80
.1
60
C
M 40
(13
20
n , I
-150 -100 -50 0 50 100 150 -2 -1 0 1 2
Angle (degrees) Slope of linear fit x 10.4
Figure 4.7: Graph on left shows 1000 linear fits to standard deviation of error vs. angle generated
by bootstrapping imposed over actual data. Histogram on right shows the frequency of line slopes.
Note that the order of magnitude of the standard deviation is 10-2 degrees, while the order of
magnitude of the slopes is 10- 4 .
Once it was determined that the standard deviation of the IMU error (representing
the random noise in the IMU) has no clear correlation with the angle, the value of the
standard deviation of noise to be considered for balance simulation was determined
by averaging the set of all error standard deviations calculated over each step in
every trial. The mean value of the standard deviation of the IMU error was then
found to be a constant .0315 degrees. This noise in the IMU readings corresponds
to variations of approximately half a millimeter in the center of mass location for an
inverted pendulum model. The static tests of the IMU reveal that the sensor is far
more precise than accurate; the average standard deviation of the error is roughly
two orders of magnitude smaller than the error itself. This investigation leads to
two conclusions regarding the sensor noise: that it is independent of the angle of the
sensor and therefore regarded as constant, and it is negligibly small compared to the
overall sensor error.
Impact testing
Figure 4.8 shows the recordings of encoder and IMU angles vs. time for an impact
test in which the pendulum was released from 90 degrees, struck a pin located at 0
degrees, remained at rest for approximately 3 seconds, and was released. From the
graph, it is clear that while the encoder shows a constant angle while the pendulum
is at rest (between 10 and 14 seconds), the IMU data depicts a slight negative slope
in the angle vs. time. The values of the slope of angle vs. time reported by the IMU
90-
80 -* Encoder
IMU
70
60 -
S 50
, 40
$30
20
V0
-10 I I I
15 16 17 18 19 20 21 22 23
Time (seconds)
Figure 4.8: Graph of angle in degrees vs. time for both encoder (shown in red) and IMU (shown
in blue). Pendulum link holding IMU was released from a 90 degree starting angle, struck an object
at 0 degrees and came to rest for approximately 3 seconds, and was then released.
while at rest for the four tests with an impact at zero degrees are reported in Table
1. The average value of the slope of the IMU reading was -0.8875 degrees/second.
Table 1 also reports the actual value of the angle of the pendulum link while at rest.
Although the pin that the link struck was located at the zero degree point, the width
of the pendulum link itself resulted in the non-zero angle of the pendulum center
line. The true angle of the pendulum link was calculated by applying Equation 24 to
the value of the encoder reading to find the encoder error; maximum IMU error was
then determined as the greatest difference between the IMU and calculated true angle.
Table 1: Slope of IMU reading with pendulum link at rest immediately after impact.
Mean encoder reading Pendulum angle Max. IMU error IMU Slope
(degrees) (degrees) (degrees) (degrees/second)
6.88 6.05 12.46 -0.7884
6.71 5.88 10.99 -0.8058
6.65 5.82 11.77 -1.0810
7.03 6.20 9.66 -0.8766
Figure 4.9 shows the results for a similar test in which the pendulum was
released from 90 degrees and struck an object at zero degrees which was immediately
removed. Here, the encoder once again demonstrates the (presumably) correct
dynamic behavior, showing small oscillations about zero degrees. The IMU initially
records oscillations about roughly 20 degrees; five seconds after the impact it reports
oscillation around roughly 15 degrees. Repeated tests demonstrated similar results.
This admittedly crudely determined slope of -1 degree/second agrees well with the
resting slope of the IMU angle with time as calculated above and suggests that the
IMU angle error due to an impact is indifferent to static or dynamic behavior.
Impact Test 8
! -I I I I I I
* Encoder
100 amwrname
c. .MU *
80
-o * *I
60
a,
S40 JI* ** *
2 ** * ** . o
*÷j * ° ** o * *
o.
... ** ** *** *.* ** **4
0 *° *. *I*
t * .**, .
*$*~~ *r .V *r*t9
*~
** *
* •
-20
*
I I I I I
-An
l8 9 10 11 12 13 14 15 16
Time
Figure 4.9: Graph of angle in degrees vs. time for both encoder (shown in red) and IMU (shown
in blue). Pendulum link holding IMU was released from a 90 degree starting angle, struck an object
at 0 degrees and was immediately released.
The results of the noise characterization indicated that the IMU noise was
insignificant compared to the overall error in the angle reading. The error in the
IMU had a total range of 1.848 degrees; this error was modeled as measurement noise
in the balance simulation with standard deviation of a = 1.848/6 = .308 degrees.
Calculation of the standard deviation assumes a normal distribution with a total
range roughly equal to 6a. The center of mass position vs. time without the use of a
Kalman filter with true states generated from a linear dynamics simulation is shown in
Figure 4.10. Use of a Kalman filter to estimate the states results in the graphs shown
in Figure 4.11, where again the pendulum dynamics are assumed to be linear. Both of
these simulations assume that the CM velocity can be measured and has error on the
order of that measured in the IMU for position. Figure 4.11 (a) shows the actual and
measured center of mass position vs. time while (b) compares the Kalman estimate
f't 4"•
U. 1L
0.1
0.08
- 0.06
0
0.04
0 0.02
-0.02
-0.04
3
Time (s)
Figure 4.10: Center of mass position vs. time from balance simulation without Kalman filter.
Acutal CMi position and sensor measurements are shown.
of the center of mass vs. time with the actual center of mass position. Figure 4.12
shows the actual CM position, measurements of CM position, and Kalman estimate
of the CM position when a nonlinear dynamic simulation generates the actual states.
A comparison between figures 4.10 and 4.11 reveals that Kalman filtering can
significantly improve control of the inverted pendulum. The RMS error of the center
of mass position was calculated from a time of 5 seconds to 100 seconds for the
simulations with and without Kalman filtering. The five-second delay in evaluating
the RMS difference allowed the system time to settle from the initial displacement to a
steady-state behavior. Averages of the RMS values for 10 trials of each simulation are
shown in Table 2. Unsurprisingly, when linear dynamics are used in the simulation to
generate the 'true' states making the linear Kalman filter model
perfectly accurate,
the RMS error is small compared to a simulation run with states generated from
nonlinear dynamics. Use of Kalman filtering with the IMU reduces the RMS error
by a factor of 15 with a linear dynamic simulation and by a factor of 4.33 with
a
nonlinear dynamic simulation. Although the Kalman filter is not necessary to control
0.
0.1
0.1
0.1
0.1
0-nL0
0 1 2 3 4 5 6 7 8 9 10
Time (s)
".. 4
' .-
U.12
0.1
0.08
0.06
0.04
0.02
0-02
0 1 2 3 4 5 6 7 8 9 10
Time (s)
(b) Kalman filter estimate of center of mass position shown in black; actual
position shown in red.
Figure 4.11: Center of mass x-position vs. time with an initial displacement of 10 cm, generated
from linearized pendulum model with all states measured.
0.12
0.1
0.08
0.06
0.04
0.02
-0.02
-n fA
0 1 2 3 4 5 6 7 8 9 10
Time (s)
U. 12
0.1
0.08
0.06
S0.04
0.02
-n n)
0 1 2 3 4 5 6 7 8 9 10
Time (s)
(b) Kalman filter estimate of center of mass position shown in black; actual
position shown in red.
Figure 4.12: Center of mass x-position vs. time with an initial displacement of 10 cm, generated
from nonlinearized pendulum model with all states measured.
balance with the sensor error in the IMU when all three states are measured, it can
significantly improve upon the error between the desired and actual center of mass
position.
Table 2: RMS error of actual CM position compared to desired CM position. Results given are
averages from 10 trials. Simulation length was 100 seconds; RMS error was calculated after an initial
5-second period during which the system reacted to initial conditions.
The results of the noise characterization indicate that an impact force applied
to the pendulum link can cause significant systematic error in the IMU angle
reading. Based on testing, a maximum error of 10 degrees is assumed when the
IMU experiences impact. In the simulation, the +10 degree error was translated into
a center of mass position error of +0.1736 m. All measurements were assumed to
have noise on the same order as the previous simulations; however, the CM position
measurement had an additional constant error of .1736 m to represent an impact.
Adjusting the measurement of the variance noise input to the Kalman filter for
the center of mass position to reflect noise on the order of 10 degrees and running
the simulation with nonlinear dynamics results in the graphs shown in Figure 4.13.
To reiterate, a large noise variance was reported to the Kalman filter in order to
decrease confidence in the measurements which are now known to be inaccurate after
an impact. The CM measurements themselves were not then generated as random
Gaussian noise on the order of 10 degrees, but rather as noise associated with static
error plus an additional constant, positive position offset. It should be noted that this
simulation assumes a constant error offset, while the results of the noise and error
characterization demonstrate that the error decreases with time at a rate on the order
of one degree per second. The simulation could be improved in future iterations by
modeling the error as decreasing with the observed slope rather than a constant in
0.2
0.
0.1
0.0
_nn
0 1 2 3 4 5 6 7 8 9 10
Time (s)
U.12
0.1
0.08
0.06
0.04
0.02
-n09
0 1 2 3 4 5 6 7 8 9 10
Time (s)
(b) Kalman filter estimate of center of mass position shown in black; actual
position shown in red.
Figure 4.13: Center of mass x-position vs. time with an initial displacement of 10 cm, generated
from nonlinearized pendulum model with impact force.
time.
From Figure 4.13, it can be seen that by lowering confidence in the measured
values appropriately (thus having the Kalman filter place more emphasis on the
model) balance may be achieved about a center of mass position of zero in spite
of large differences in the measured and actual positions. This highlights some
important issues for future work when considering the effect of impact forces on the
IMU measurements: that either the noise parameters input to the Kalman filter must
be corrected to reflect lower confidence in the measurements for a period of time after
an impact, or the error must be understood well enough to be modeled effectively as a
function of time and force. Additionally, if confidence in the measurements is lowered,
the model used with the Kalman filter must be sufficiently accurate to compensate
for poor measurements. These challenges with modeling impact force effects on the
IMU could be the basis for further study and exploration.
No velocity
o
C.
L)
0
0
Time (s)
C?
0
CD
0
0a
0 1 2 3 4 5 6 7 8 9 10
Time (s)
(b) Kalman filter estimate of center of mass position shown in black; actual
position shown in red.
Figure 4.14: Center of mass x-position vs. time with an initial displacement of 10 cm, generated
from linearized pendulum model witout velocity measurements.
0.12
0.1
0.08
0.06
-0.04
0
o 0.02
-0.02
0-l 0l4
0 1 2 3 4 5 6 7 8 9 10
Time (s)
U. IZ
0.1
0.08
0.06
" 0.04
0.02
-0.02
0 1 2 3 4 5 6 7 8 9 10
Time (s)
(b) Kalman filter estimate of center of mass position shown in black; actual
position shown in red.
Figure 4.15: Center of mass x-position vs. time with an initial displacement of 10 cm,
generated
from nonlinearized pendulum model witout velocity measurements.
are multiplied, errors in the measurements may propogate and yield results that are
far different from the true states. Additionally, some IMUs only report orientation
and do not offer information about angular velocity. In these cases, the ability of the
Kalman filter to generate estimates for all states when not all states are measurable
is important. Figures 4.14 and 4.15 show the actual CM position and the Kalman
estimate of CM position with states generated from linear and nonlinear dynamics,
respectively, without a CM velocity measurement. Measurement noise for the CM
and ZMP positions are generated with a = .308 degrees as is consistent with the
error from the static IMU testing. A simulation that did not use Kalman filtering to
estimate the unmeasurable velocity but rather differentiated the noisy measurements
proved to be unstable for the same parameters.
Figures 4.14 and 4.15 demonstrate that the Kalman estimate of the CM position
loses accuracy when the velocity is not measured and calculated only based on the
linear model. The RMS error in the actual CM position compared to the desired
position of zero was found to be 7.10 -10- 3 m for both the linear and nonlinear
dynamics generation of the true states. The fact that Kalman filtering can be used to
estimate unmeasurable states with enough accuracy to control a system illustrates the
usefulness of Kalman filtering techniques with complicated robots. A similar analysis
of the capabilities of Kalman filtering with unmeasured states could be carried out
on more complicated models of the BEAR for a more rigorous future study.
5 Conclusion
Testing of the IMU revealed that the sensor is significantly more precise
than accurate. The overall error in static orientation sensing spanned a range of
approximately 2 degrees; the standard deviation of noise in the IMU during static
testing proved to be roughly two orders of magnitude smaller. Overall, the sensor
noise was deemed insignificant in comparison to systematic errors. Impact testing
revealed maximum errors in the IMU on the order of 10 degrees after the pendulum
link holding the IMU was struck. The IMU error then decreased with a slope of
approximately -1 degree per second regardless of whether the IMU was oscillating or
held static. The information found regarding the static and impact error in the IMU
was used in a balance simulation to evaluate the necessity of Kalman filtering with
the IMU.
When all states of the inverted pendulum model were measurable, the Kalman
filter was not necessary to control the center of mass position sufficiently to maintain
balance. However, the use of Kalman filtering was found to decrease the root
mean squared error of the CM position by more than a factor of four compared
to a simulation using unfiltered measurements. When not all states are measurable,
the Kalman filter can increase the system stability compared to other methods of
obtaining the unmeasurable states, such as differentiating or integrating sensor data
from the measurable states. Kalman filtering techniques can also improve balance of
the inverted pendulum model in response to impact forces when noise parameters are
adjusted to lower confidence in the faulty measurements. The ability to sense impact,
change the noise parameters to the Kalman filter, or model the error accurately
upon impact remain subjects for further study. Overall, based on this study Kalman
filtering is not strictly necessary when the MicroStrain 3DM-GX1 IMU is used, but
can provide significant benefits without the inherent time delays associated with low-
pass filtering.
6 References
[1] Photograph courtesy of Vecna Technologies, Inc: http://vecnarobotics.com/
robotics/product-services/bear-robot/bear_details.shtml
[6] Fraden, Jacob. Handbook of Modern Sensors. New York: Springer, 2004.
[7] Wilson, J,S,. Ed. Sensor Technology Handbook. New York: Elselvier, 2005.
[9] Kong, Xiaoying, and Craig Scott. "GPS-aided INS alignment algorithm for
IMU with poor sensitivity." Mobile Robots: New Research, pp. 259-289, Nova
Science Publishers, 2005.
7 Appendix A: Matlab code
%Constants
dt = 0.01;
controldt = 0.1;
m = 100;
kz = 1000;
Q2 = Q;
R2 = eye(3) * R;
%Control Constants
kv = 5;
kp = 8;
ki = 10;
x_dcm = 0;
x = [.1, 0,0];
x_est = x;
y = x;
y_est = x_est;
yv = y + (rand(1,3) - 0.5) * sqrt(R);
x_acc = [x];
yacc = [y];
yv_acc = [yv];
x_est_acc = [x_est];
yest_acc = [y_est, y_est];
u_acc = [0];
unoise_acc = [0];
t = 0: dt: control_dt;
u = zeros(size(t));
x_last = x(xs(1),:);
y_last = yv(xs(1),:);
x_est_last = xest(xs(1),:);
u-noiset = u-noise';
u-t = u';
u_noise_acc = [u_noiseacc; u_noise_t(2:xs(1), :)];
u_acc = [u_acc; u_t(2:xs(1), :)];
%Control input and measured output over the last control interval
u-kalm = [ut, yv];
[y_est, t-est, x_est] = isim(kalmf, u-kalm, t, xestlast);
end
%Constants
1 = 1;
g = 9.806;
m = 100;
cm.pos = 1;
cmvel = 2;
zmp-pos = 3;
J = m*l^2;
/.Run simulation
for i = 1:length(u)-1
Tgrav = -m*g*l*cos(theta(i));
Tforce = F_x(i)*l*sin(theta(i));