Friday, July 14, 2017

5 - Raspberry Pi and Sense Hat (II): IMU (Inertial Management Unit) with Accelerometer, Gyroscope and Magnetometer


- Layout for this exercise:

1 - Introduction

- The Sense HAT has a movement sensor called an IMU (Inertial Management Unit) which can measure the type of movement it is experiencing:

- An IMU is an electronic device that measures and reports a body's specific force, angular rate, and sometimes the magnetic field surrounding the body, using a combination of accelerometers and gyroscopes, sometimes also magnetometers.

- An IMU is built basically with 3 sensors in one. The readings for these 3 sensors are combined to have an accurate orientation of the Sense HAT module:

 a) gyroscope: measures momentum and rotation. 

b) accelerometer: measures acceleration forces and can be used to find the direction of gravity. 

c) magnetometer: measures the Earth's own magnetic field, so it's a bit like a compass.

- An IMU sensor is used on all manned and unmanned spacecraft to track movements and maintain an understanding of orientation.

- All objects in space have three axes around which they can rotate. The three axes are:

- Pitch, roll, yaw are terms used in aviation and airplane control to describe the movement around the 3 axes:

a) pitch: like a plane taking off

b) roll: the plane doing a victory roll

c) yaw: steering the plane like a car

- If you know how much rotation has happened on each axis, then you know which way the object is pointing.

This image shows where these axes are in relation to the Sense HAT:

2 - Programming Raspberry Pi and Sense Hat to determine its orientation

- The next program offers accurate information about the orientation of the Raspberry Pi and Sense Hat module.

- The function set_imu_config(True,True,True) sets the magnetometer, gyroscope and accelerometer (in that order) to make measurements about the position (determined by the pitch, roll and yaw output parameters):

- Giving permissions of execution:

- The initial position of the Raspberry Pi and Sense Hat is flat on a table:

- Running the program:

- Tilting up the Raspberry Pi and the Sense Hat modules:

- After tilting up the module a variation for the pitch is detected while roll and yaw remain almost equal: