In this video, we'll be learning about sensors that measure inertial movement (IMUs), how they work, how to choose the right IMU for your next project, and how to use sensor fusion to get the most out of their readings.

Transcript

IMUs, or Inertial Measurement Units, are a type of device that detect and measure their own movement in 3D space. These measurements can be read from a microcontroller, like a Raspberry Pi Pico, to respond to movements of a device in real time, like this self-balancing platform I've hacked out of a robot arm.

As I move the robot arm around, the IMU reads the motions and the servos then counteract to make sure it self-balances. IMUs are more common than you might think. They're in everyday things like smartphones, modern TV remotes, and gaming controllers. They're also critical in the operation of sophisticated hardware, such as drones, robots, aeroplanes, and spacecraft.

Sounds like pretty advanced stuff to try and use, doesn't it? Well, no, not really. IMUs can actually be quite affordable and easy to use, even for beginners. I will admit though, with the different types and lots of terminology, it can all be a bit daunting at first. So let's break it all down, starting with the different types of IMUs.

We're really just looking at different combinations of three common sensors. Accelerometers, Gyrometers, or Gyros for short, and Magnetometers. Fortunately for us, these three sensors are pretty much always in the same three combinations. With just an accelerometer, which is a 3-DOF IMU, we'll get to what a DOF is in a minute, an accelerometer and gyro combined, which is a 6-DOF IMU, and an accelerometer, gyro, and magnetometer all combined, which is a 9-DOF IMU.

So that's our three types of IMUs, but what the heck is a DOF? Well, DOF stands for Degrees of Freedom, and it means how many different ways something can move in 3D space. Imagine you have a basketball. You can move the basketball up and down, left and right, and forward and backward. That's three different ways it can move, so it has three degrees of freedom.Right, and forwards and backwards. These are three degrees of freedom of movement, also referred to as translation.

Now, you can also rotate the same basketball, left and right, forwards and backwards, or spin it on your finger. These are three degrees of freedom of rotation.

Combined with the 3-DOF of translation, we find that the basketball has a total of six degrees of freedom.

Finally, you can also track these movements and rotations in relation to Earth. Move north and south, east and west, up and down. These are the three degrees of freedom of direction, which when all combined, makes a total of nine degrees of freedom.

Imagine you have a friend that lives on the opposite side of the world. You and your friend, who are on the other side of Earth, both have basketballs, and you both lift them straight upwards. To each of you individually, the basketball has moved upwards, but in 3D space, they have actually moved in opposite directions.

The last three degrees of freedom, tracking direction in relation to Earth, simply allows us to anchor the other six degrees of freedom to the real world.

Great! So now we know about three, six, and nine degrees of freedom. The more we can measure at the same time, the more accurately we can track the orientation of an object in 3D space.

Let's look at this in practice, starting with the first type of IMU, the accelerometer. An accelerometer measures acceleration, or changes in velocity, of an object in 3D space. Accelerometers track movement in three directions. And if we think back to our basketball, tracking movement in three directions makes the accelerometer a 3DOF IMU.

While they are limited to only three degrees of freedom, accelerometers are still very useful devices.They can be used to detect tapping and shaking, which can be useful for interacting with things like smartphones. But they can also be used to measure rotation, thanks to a side effect from the Earth's gravity. As you rotate an accelerometer, the acceleration force of gravity acts against each axis, which the accelerometer measures. Plug those readings into some math functions, and we can calculate the rotation of the accelerometer. Check out our guide on the PiicoDev accelerometer, which covers tapping and shaking as well as rotation. I've linked it as well.

So if an accelerometer can be used to measure both translation and rotation, doesn't that mean it has six degrees of freedom? Well unfortunately no, because measuring rotation from an accelerometer comes with some limitations. First, it only works if it is not moving. As soon as it moves, the new forces interfere and mess up the maths used for rotation. Second, we can't always measure rotation on all three axes at all times. For example, if two axes are perpendicular to gravity, so that they are reading zero, it becomes impossible to measure rotation on the third axis. And third, accelerometers are noisy, which in turn causes something called drift. This is when readings gradually become less accurate over time. On that note, while they can detect movement, they can't really be used for dead reckoning or GPS-like navigation. They are simply too noisy, so stick to GPS for that kind of thing.

With these limitations in mind, accelerometers are still great for detecting small rotations on one or two axes, like rotating a screen or balancing a ball on a flat surface. They are also the cheapest of the different IMU types. Accelerometers are a great option if you areOn a budget and able to compromise on those limitations in rotation. The second type of IMU has a gyro to the mix, which adds in the three degrees of freedom of rotation.

Combining the 3-dof of a gyro with the 3-dof from an accelerometer gives us a 6-dof IMU. Most 6-dof IMUs, like this MPU6050, have both the accelerometer and gyro inside the same single chip. But under the hood, they are two still individual sensors, from which you can read up to six raw values. Three for acceleration and three for rotation.

This is great if you want to work with acceleration or rotation independently. But to get more bang for our buck, we can use a process called sensor fusion. Sensor fusion combines the raw readings from the last two different motion sensors and outputs pitch, roll, and heading. Check out the guide for more information on how to do sensor fusion in MicroPython.

With the pitch, roll, and heading of an object, we can understand its current orientation in 3D space. With sensor fusion on the 6-dof sensor, we can only move in two directions. We have pitch and roll, but since we are only fusing two sensors, accelerometer and gyro, the sensor fusion cannot calculate heading.

So what's the point of a 6-dof IMU if we can't have heading? Well, we still have two axes of orientation here, and they are far more reliable than if we just had a 3-dof accelerometer IMU. In some cases, you may only need two accurate axes of orientation, such as a pointing device or gaming controller, which can only actually move within two axes of a TV screen.

6-dof sensors are also significantly cheaper than 9-dof sensors, so if you only need those two axes, you can save yourself some money by going with a 6-dof IMU.

Okay, but what if the sensorFusion from a 6-dof isn't good enough and you need heading as well? Well, you're going to need the last three degrees of freedom, direction. Which brings us to our final type of IMU, which adds a magnetometer to the accelerometer and gyro combo.

A magnetometer is a sensor that measures the strength of its surrounding magnetic field along three axes of 3D space. A 9-dof IMU uses a magnetometer as a digital compass using the Earth's magnetic field for three axes of direction. You can check out our guide on the PiicoDev magnetometer to learn more about them on their own, which I've linked.

This 9-dof IMU has all three sensors on board, and even does full sensor fusion using all three sensors on board as well, meaning we don't need to do it in software. You don't have to get an all-in-one 9-dof IMU though. You can manually add a magnetometer with a 6-dof IMU to make a 9-dof system, like I've done here. I've added a PiicoDev magnetometer to the MPU6050 to make a 9-dof system. You then feed the MAG readings into software-based fusion along with the gyro and accelerometer readings, which I'm doing here on the Raspberry Pi Pico.

As you can see, I now have all three axes of rotation, pitch, roll, and heading. A full 9-dof IMU is the complete package, and if you're happy to pay a bit more, it will give you the most flexibility and accuracy out of the bunch. Likewise, if your project needs high-accuracy orientation tracking, or needs a true representation of all three axes, like a drone or similar, then you will need a 9-dof IMU.

On a side note, not all 9-dof IMUs do full sensor fusion on board, and instead leave it up to you to do it in software. Make sure you read the product description before buying if this is important for you.Your project. So that's the three different types of IMUs, 3, 6, and 9-degrees of freedom.

4-dof IMUs, which are typically accelerometers, are the cheapest, but also the least accurate.

6-dof IMUs usually don't cost all that much more than 3-dof IMUs, but can be used with sensor fusion to give two axes of orientation.

And 9-dof IMUs are the most accurate of the bunch. They can be used with sensor fusion to give three axes of orientation, but are also the most pricey.

If you're using IMUs in an interesting way, or if you have any questions about anything from this video, let us know about it in the comments or in the forums.

And until next time, happy making!

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.