Measuring angular displacements with gyro sensors is straightforward, in 
principle, and yields very accurate results over short timespans (a few
tens of seconds).

The hard part is to compensate for small errors that accumulate over time
and cause the integrated angles to "drift" further and further from their
true values. Compensating for this drift requires the use of some kind of
additional external reference besides the gyros themselves.

I spent many hours trying to use accelerometers for this purpose but
finally decided that engine vibration and centrifugal forces prevent
them from being used accurately on a motorcycle.

Instead, I wound up designing a novel scheme to periodically zero out the 
gyros without the use of additional sensors.

It's a little hard to explain, but the idea is simple. When a motorcycle
completes a turn or a transition from one direction to another, there is always
an "inflection point" in the bike's motion where the yaw-rate is zero. This
corresponds to an instant when the bike is standing vertically with respect to the
ground. At this moment we can compare the lean angle computed by the integrator
with zero. Any difference indicates a "drift" error, ie. the camera is not
level with the horizon when it should be.

We could immediately zero out the camera/gyro angle to correct the error, but
this would make the camera jerky. So instead I blend the error correction over a
period of several seconds to make the correction almost invisible. 

It's also important to avoid false corrections, ie. momentary indications of zero
yaw-rates due to noise. So I do a bit of smoothing and also wait until the zero
rate has persisted for several tens of milliseconds before concluding that the
bike is truly at a transition point.

You'll have to look carefully at the code in "imu.h" for the exact details of how
it's all done. The hardest part was determining the appropriate timing constants.
This required many road tests and considerable trial and error.

--DL  12 Aug 2013
