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.

Comments

  1. Dax says:

    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.

    • rasz says:

      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

      • Anonymous says:

        maybe you mean libusb.org, seeing as how .com and .net are just serving ads.

      • sibeko says:

        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
        }

      • Elias says:

        I would be guessing he meant this: http://sourceforge.net/projects/libusbdotnet/

      • xorpunk says:

        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. danoverholt says:

    StickOS: http://www.cpustick.com — the ‘IDE’ & compiler is installed onto the micro.

  3. LineKernel says:

    you can find this same board for 20 bucks on Dx.com (dealextreme look for SKU: 145912) if you are interested .
    but i dont know if they still take paypal .

    That s cool that now i have a tutorial for my sensor .

  4. gustav says:

    Looks like a good introduction, I look forward to future posts :)

    If you’re interested in IMUs also be sure to check out the FreeIMU open source project:

    http://www.varesano.net/projects/hardware/FreeIMU

    The board uses similar sensors (depending on iteration) and the code library supports sensor fusion.

  5. hat says:

    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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,693 other followers