We have left the code as simple as it can be to make it easier to understand.
The code currently performs angle measurements using the gyroscope and accelerometer , which are fused using a complementary filter. The heading is also calculated using the magnetometer, without tilt compensation. To view pressure;
When using the IMU to calculate angles, readings from both the gyro and accelerometer are needed which are then combined. This is because using either on their own will result in inaccurate readings. And a special note about yaw.
Gyros - A gyro measures the rate of rotation, which has to be tracked over time to calculate the current angle. This tracking causes the gyro to drift. However, gyros are good at measuring quick sharp movements. Accelerometers - Accelerometers are used to sense both static (e.g. gravity) and dynamic (e.g. sudden starts/stops) acceleration. They don’t need to be tracked like a gyro and can measure the current angle at any given time. Accelerometers however are very noisy and are only useful for tracking angles over a long period of time.
Accelerometers cannot measure yaw. To explain it simply, yaw is when the accelerometer is on a flat level surface and it is rotated clockwise or anticlockwise. As the Z-Axis readings will not change, we cannot measure yaw. A gyro and a magnetometer can help you measure yaw. This will be covered in a future guide.
An accelerometer, gyroscope and magnetometer which is specifically designed for the Raspberry Pi.
What is it?
BerryIMU is an inertial measurement unit, or IMU, that measures and reports on velocity, orientation and gravitational forces, using a combination of an accelerometer, gyroscope and a magnetometer.
IMUs can be found in devices like, quad copters, smart phones, segways, Wii Remote etc.. and are used to sense movement and orientation.
Adding BerryIMU to your Pi will open up a whole new world of possibilities.
BerryIMU is specifically designed for the Raspberry Pi and is designed to take some of the complexity out of IMUs and to try and make them more enjoyable to use. BerryIMU includes the latest and greatest sensor ICs.