Google+ Followers

Thursday, October 1, 2015

69. The Sense HAT's Inertial Measurement Unit

45,000 page views!!
I described this HAT (Hardware Attached on Top) for the Raspberry Pi a couple of posts ago (HERE).  Among its many goodies are a gyroscope, which measures momentum and rotation, an accelerometer which measures acceleration forces including that due to gravity, and a magnetometer, which measures the earth's magnetic field.

These three sensors make up what is collectively described as an Inertial Measurement Unit (IMU).  I have described the operation of the IMU in a previous post (No 53 HERE).  Three orthogonal axes are chosen, and rotational directions around these axes are known as rollpitch and yaw.  Here is an illustration of the roll, pitch and yaw rotations of the Pi with the HAT fitted:

To further illustrate this, take as an example an aircraft, where roll describes the rotation about the direction of travel.  For example, when the wings go up on one side and down on the other: pitch is the motion when the nose of the plane goes up or down, and yaw describes a left or right turn.  They are the three orthogonal axes about which rotation of any object can be made, and combined rotations around all three axes give all the possible orientations that any body can have.  Here's a useful video to describe this:



So when the Raspberry Pi with its HAT on is tilted in various directions, the IMU can detect this and send the orientation data to the Raspberry Pi which can run software to represent this on a display.

I wrote a little Python script to make use of the 8 x 8 RGB LED display to indicate two of the rotations, pitch and roll.  Trying to represent yaw as well as pitch and roll on a 2D display is too difficult!  Here's the video:

video

You can see that my Pi 2B has the Raspberry Pi Camera Board attached, even though that's not needed for this project.

Here's my code:

While I was at it, I thought I would load up the 3D Apollo-Soyuz Demo, and it works well.  Here's the video (watch out for my thumb!):
video

You will have seen that I also have the 8 x 8 RGB LED array lit up, even though this also is not part of this project.

At the later part of the above video, I used the keyboard key " = " to rotate (yaw) the spacecraft in a clockwise direction.  I could equally have used the " - " key to offset the yaw of the spacecraft in a counter-clockwise direction.  Other keys that can be used are " a " which will toggle the accelerometer on and off, " g " to toggle the gyroscope on and off, and " m " to toggle the magnetometer on and off.  See how this facility is included in the code below (lines 62 to 74) by Ben Nuttall of the Raspberry Pi Foundation:
The code uses a file apollo-soyuz.obj which has all the necessary details of the spacecraft model to generate the display. Apparently it's possible to use Sketchup or Blender to make models and use them like this.  I must have a go at that!

Here is a depiction of the 1975 spacecraft of the first joint Soviet-USA space flight - Apollo /Soyuz  (and also the last Apollo mission, the Space Shuttle taking over after that):

Note that the diagram refers to Apollo 18.  Apollo 18 was actually cancelled, and in this joint mission it was simply referred to as Apollo.  This Apollo-Soyuz Test Project was successful, but Apollo got into a spot of bother on re-entry.  You can read about it HERE.

The 3D Apollo-Soyuz Demo is supplied as part of the Sense HAT (Astro Pi) software repository on GitHub.  See HERE.

Thanks Ben!

No comments:

Post a Comment