Tutorial Explains The Concepts Behind An IMU

[Anilm3] wrote in to share the IMU tutorial series he is working on. An Inertial Measurement Unit is most often found in self-balancing robots and quadcopters, providing enough high-speed sensor data to keep up with the effects of gravity.  He previously used some all-in-one IMU devices in school which did most of the work for him. But he wanted to grind down and look at what each sensor spits out and how those measurements are used. The first installment deals with the accelerometer, using its data to calculate pitch and roll. For these demonstrations [Anilm3] is using this ADXL345 sensor board, an Arduino, and some processing sketches for testing.

Whenever working with sensors you need to take noise into consideration. The post shows how to implement a low-pass filter in the code which will help smooth out the readings. The filtered data is then fed to a couple of mostly-painless formulas which calculate the movement of the accelerometer in degrees. The demonstration sketch is mapped to a 3D cube to give you an idea of how accurate the accelerometer is. There’s a little bit of lag which would let a self-balancing robot have a nasty fall. The solution to this issue will be discussed in upcoming parts of the series. The next installment tackles the gyroscope sensor.

12 thoughts on “Tutorial Explains The Concepts Behind An IMU

  1. On the side, are there any good tutorials for programming simple applications to interface with your serial/USB devices without having to use some silly IDE, just basic command line stuff for Windows (or Linux).

    I just want to write an app that offloads some of the heavier calculation out of the MCU and handles user input sanitation.

    1. libusbdotnet has an example file, you dont even need a visual studio (dotnet libraries installed as a standard come with a compiler environment
      something like letter:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild will trigger a build process

      1. I do a lot of prototyping in powershell using libusb. There’s no compilation, so it’s an easy way to try things out. Example:


        # This is used in powershell v3 (windows 8).
        # Use [Reflection.Assembly]::LoadFile or something in powershell v2
        Add-Type -Path "C:\Program Files\LibUsbDotNet\LibUsbDotNet.dll"

        $finder = new-object -typename LibUsbDotNet.Main.UsbDeviceFinder -args 0x03EB,0x2045 #VID,PID

        # read http://www.beyondlogic.org/usbnutshell for an intro
        # to configs, interfaces and endpoints
        $device = [LibUsbDotNet.UsbDevice]::OpenUsbDevice($finder)
        $wholeDevice = $device -as [LibUsbDotNet.IUsbDevice]
        $wholeDevice.SetConfiguration(1)
        $wholeDevice.ClaimInterface(0)

        $writer = $device.OpenEndpointWriter([LibUsbDotNet.Main.WriteEndpointID]::Ep04)
        $reader = $device.OpenEndpointReader([LibUsbDotNet.Main.ReadEndpointID]::Ep03)

        #write [1,2,3,4,5,6,7,8]
        [int]$bytesWritten = 0
        [byte[]] $message = 1,2,3,4,5,6,7,8 | %{[System.BitConverter]::GetBytes($_)}
        writer.Write($message, 2000, [ref]$bytesWritten)

        #read
        [int]$bytesRead = 0
        $readBuf = new-object -typename byte[] -args 512
        $result = $reader.Read($readBuf, 500, [ref]$bytesRead)
        if($result -eq "Success")
        {
        #Do something. $readBuf contrains the read bytes
        }

      2. powershell and libusb is actually a pretty good pipeline for prototyping.. I’ve never used powershell but it’s basically a text editor and a dll..

        On the topic of this article, even high-speed robots don’t need fast buses for sensor data. The magic is all in the code, simple polling is plenty fast in my experience though over common PIC I/O..

  2. It’s a neat, well-written tutorial, but I wonder if the author knows that his equations for computing roll and pitch are only valid while the sensor board that is travelling at a constant velocity (ie, moving in a straight line or motionless)?

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.