Use IMUs for Precise Location Data When GPS Won’t Suffice

著者 Steve Leibson氏

Digi-Keyの北米担当編集者 の提供

The ability to locate the position of any suitably enabled system anywhere on Earth using the Global Navigation Satellite Systems (GNSS) is useful, but there are a few problems associated with using only GNSS receivers for positioning. These problems can be overcome by using inertial measurement units (IMUs) to complement GNSS.

This article discusses the embedded use of IMUs, which employ gyroscopes, accelerometers, and magnetometers to measure location based on an initial starting point. It then introduces suitable example solutions and how to use them.

How IMUs complement GNSS

The problems with GNSS are fourfold. Firstly, GNSS signals are very directional and so can be blocked by buildings. Secondly, receivers have warm and cold startup times measured in the tens of seconds and stretching to one minute or more. This startup time is needed for the receiver to acquire and lock onto the multiple satellite signals required for a position fix.

Thirdly, the GNSS position update rate is limited to once per second. That’s fine for tracking large, slow moving objects, but the startup time is far too long and the update rate is far too slow for many embedded applications. Fourthly, GNSS accuracy is measured in meters, which is too coarse for use in most embedded applications. These applications are as diverse as robotics and virtual reality, which do not involve ground transportation.

IMUs provide the finer positioning resolution and faster update rates that are required by many embedded applications. Also, IMUs provide relative position data from a known starting point as opposed to the absolute positioning information from a GNSS receiver, so the two types of position sensors are complementary.

Modern electronic IMUs available as board mountable components are based on microelectromechanical systems (MEMS) technology, making them small, light, and relatively rugged. They come with varying capabilities in terms of degrees of freedom (DOF), and unlike GNSS receivers, IMUs do not depend upon radio signals. They also consume very little power, and they’re available from a variety of sources with a wide range of resolution and accuracy.

With these characteristics IMUs can be used to augment positioning information from GNSS receivers. (See “Design Location Tracking Systems Quickly Using GNSS Modules.”)

Anatomy of an IMU

Motion sensors react to and detect physical motion, including parameters such as acceleration, movement rate, or distance. Inertial sensors are a special class of motion sensor. IMUs integrate a number of motion sensors into one device and can provide high accuracy positioning information. They react to the motion of the sensor itself.

IMUs incorporate one or more of the following motion sensor types:

  • Gyroscope sensors measure angular position changes, usually expressed in degrees per second. Integrating angular rate over time results in a measured angle of travel which can be used to track changes in orientation. Gyroscope sensors are available with one, two, or three axes corresponding to pitch, roll, and yaw angles. Gyroscopes track relative movement independently from gravity, so errors from sensor bias or integration result in a position error called “drift.”
  • Accelerometer sensors measure linear acceleration, including acceleration components caused by device motion and acceleration due to gravity. The acceleration is measured in Gs, which are multiples of the earth’s gravitational force (1 G = 9.8 meters/second2). Accelerometers are available with one, two, or three axes, which define an X, Y, Z coordinate system. Accelerometer data can be used to measure static device orientation by computing the measured angle of the device and compensating for gravitational force. Periods of complex motion can complicate the orientation calculation.
  • Magnetic sensors measure magnetic field strength, typically in units of microTeslas (µT) or Gauss (100 µT = 1 Gauss).The most common magnetic sensor used for mobile electronics is a three-axis Hall-effect magnetometer. The magnitude of the Earth’s magnetic field varies between 25 and 65 µT, and in angle of inclination depending on geographic location. For the continental United States, the intensity varies between 45 and 55 µT, at an angle between 50 and 80 degrees. By computing the angle of the detected earth’s magnetic field, and comparing that measured angle to gravity as measured by an accelerometer, it is possible to measure a device’s heading with respect to magnetic north with high accuracy. An adjustment based on the current latitude and longitude is needed to get a true north heading.
  • Pressure sensors measure differential or absolute pressure with units typically in hectopascal (hPa) or milliBar (mbar), which are equivalent. Standard atmospheric pressure at sea level is defined as 1013.25 hPa. Changes in altitude cause corresponding changes in detected ambient air pressure and can be used to track vertical motion.

Motion tracking using IMUs employs sensor fusion to derive a single, high accuracy estimate of relative device orientation and position from a known starting point and orientation. Sensor fusion involves combining the IMU’s various motion sensor outputs using complex mathematical algorithms developed either by the IMU manufacturer or the application developer. Position calculations using sensor fusion can produce the following measurements:

  • Gravity – specifically the earth’s gravity and excludes the acceleration caused by the motion being experienced by the device. An accelerometer measures the gravity vector when the IMU is stationary. When the IMU is in motion, the gravity measurement requires fusing data from an accelerometer and a gyroscope and subtracting out the acceleration caused by motion. Applications that require orientation detection with respect to the earth can use gravity measurements.
  • Linear acceleration – equivalent to the acceleration of the device as measured by the accelerometer, but with the gravity vector subtracted. IMU linear acceleration can be used to measure movement in three-dimensional space. The accuracy of this value depends on the tracking accuracy of the gravity vector.
  • Orientation (attitude) – the set of Euler angles including yaw (azimuth), pitch, and roll, as measured in units of degrees.
  • Rotation vector – derived from a combination of data from accelerometer, gyroscope, and magnetometer sensors. The rotation vector represents a rotation angle around a specified axis.

IMUs can be used for a variety of applications including consumer (mobile phones), medical (imaging), industrial (robotics), and military (head tracking). The required IMU accuracy depends on the application requirements.

Six degrees of freedom

DOF refers to the possible movements of a rigid body within three-dimensional space. There are only six DOF in 3D space: three DOF for linear translation (forward/back, up/down, left/right) and three DOF for rotations (pitch, yaw, and roll). No matter how complex the motion, any possible movement of a rigid body in space can be expressed as a combination of the six basic DOF.

However, in the world of IMUs, there are numerous references to 9 DOF and even 10 DOF sensors. This nomenclature can be rather confusing given that there are only six total DOFs used to describe movement. The nine DOF number comes from adding up the DOF for each type of sensor contained inside the IMU. So, if an IMU has a 3 DOF accelerometer, a 3 DOF gyroscope, and a 3 DOF magnetometer, then it’s called a 9 DOF IMU. Adding an atmospheric pressure sensor to the mix for measuring altitude creates a 10 DOF IMU.

IMUs are available in a wide range of prices and capabilities. For example, DFRobot's SEN0140 10 DOF MEMS IMU sensor board is a compact IMU board that integrates an Analog Devices ADXL345 accelerometer, a magnetometer from Honeywell Microelectronics & Precision Sensors, a TDK Invensense gyroscope, and a Bosch Sensortec barometric pressure sensor.

Image of DFRobot’s SEN0140 10 DOF MEMS IMU sensor board

Figure 1: DFRobot’s SEN0140 10 DOF MEMS IMU sensor board integrates an accelerometer, a magnetometer, a gyroscope, and a barometric pressure sensor. (Image source: DFRobot)

The measurement specifications for the main SEN0140 sensors are:

  • ADXL345 accelerometer: 13-bit resolution at ±16 g (maintaining 4 mg/LSB scale factor in all g ranges)
  • Honeywell Microelectronics & Precision Sensors magnetometer: ±8 gauss magnetic full scale
  • TDK Invensense gyroscope: full-scale range of ±2000°/second
  • Bosch Sensortec barometric pressure sensor: 4.35 PSI to 15.95 PSI (30 kPa to 110 kPa)

All four of these sensors are wired to the board’s single SPI serial port, which means that the embedded processor must address and query each sensor separately. DFRobot’s SEN0140 also incorporates a low noise LDO for supplying regulated power to the sensors from a 3 to 8 volt supply.

DFRobot’s 10 DOF IMU is directly compatible with Arduino development boards using an existing Arduino library. It can also be used with any microprocessor or microcontroller system that has an SPI port.

The following is sample Arduino code to extract the sensor data from DFRobot’s SEN0140 10 DOF board (Listing 1):

#include <Wire.h> 
#include <FreeSixIMU.h> 
#include <FIMU_ADXL345.h> 
#include <FIMU_ITG3200.h> 
#include <HMC5883L.h> 
float angles[3]; // yaw pitch roll 
float heading; 
short temperature; 
long pressure; 
// Set the FreeSixIMU object 
FreeSixIMU sixDOF = FreeSixIMU(); 
HMC5883L compass; 
// Record any errors that may occur in the compass. 
int error = 0; 
void setup(){ 
  sixDOF.init(); //init the Acc and Gyro 
  compass = HMC5883L(); // init HMC5883 
  error = compass.SetScale(1.3); // Set the scale of the compass. 
  error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous   
  if(error != 0) // If there is an error, print it out. 
  bmp085Calibration(); // init barometric pressure sensor 
void loop(){ 
  temperature = bmp085GetTemperature(bmp085ReadUT()); 
  pressure = bmp085GetPressure(bmp085ReadUP()); 
void getHeading(){ 
  // Retrive the raw values from the compass (not scaled). 
  MagnetometerRaw raw = compass.ReadRawAxis(); 
  // Retrived the scaled values from the compass (scaled to the configured scale). 
  MagnetometerScaled scaled = compass.ReadScaledAxis(); 
  // Values are accessed like so: 
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis) 
  // Calculate heading when the magnetometer is level, then correct for signs of axis. 
  heading = atan2(scaled.YAxis, scaled.XAxis);   
  float declinationAngle = 0.0457; 
  heading += declinationAngle; 
  // Correct for when signs are reversed. 
  if(heading < 0) 
    heading += 2*PI; 
  // Check for wrap due to addition of declination. 
  if(heading > 2*PI) 
    heading -= 2*PI; 
  // Convert radians to degrees for readability. 
  heading = heading * 180/M_PI;  
void PrintData(){ 
  Serial.print("Eular Angle: "); 
  Serial.print("  ");   
  Serial.print("  "); 
  Serial.print("  "); 
  Serial.print("Heading: "); 
  Serial.print("  "); 
  Serial.print("Pressure: "); 
  Serial.print(pressure, DEC); 
  Serial.println(" Pa"); 

Listing 1: This sample Arduino code extracts the sensor data from DFRobot’s SEN0140 10DOF board. (Code source: DFRobot)

This Arduino code produces the output shown in Figure 2.

Image of Arduino code

Figure 2: The Arduino code listed above produces this output, showing the status of the SEN0140 sensors. (Image source: DFRobot)

Digilent’s 410-326 9-axis IMU/barometer is based on an STMicroelectronics’ LSM9DS1 iNEMU IMU which incorporates a 3D accelerometer, a 3D gyroscope, and a 3D magnetometer with the following specifications:

  • ±2/±4/±8/±16 g linear acceleration full scale (3D accelerometer)
  • ±245/±500/±2000°/second angular rate full scale (3D gyroscope)
  • ±4/±8/±12/±16 gauss magnetic full scale (3D magnetometer)

All three motion sensor types—accelerometer, gyroscope, and magnetometer—are integrated into one small package and connected though the LSM9DS1’s I2C interface.

Image of Digilent’s 410-326 9-axis IMU/barometer

Figure 3: Digilent’s 410-326 9-axis IMU/barometer uses an STMicroelectronics’ LSM9DS1 iNEMU IMU that combines a 3D accelerometer, a 3D gyroscope, and a 3D magnetometer into one package. (Image source: Digilent)

Thales Visionix's NavChip Precision 6-axis MEMS IMU is derived from military technology, performing positional data acquisition and processing at a 1 kHz rate. It then processes and integrates the data down to a 200 Hz (or lower) user selectable rate. It also performs compensation using factory calibration and embedded temperature sensors to correct the other sensors’ biases, scale factors, and misalignments. The specifications for its accelerometer and magnetometer are:

  • Accelerometer: Full-scale angular rate of 2000°/s
  • Magnetometer: Full-scale acceleration of ±16g

The NavChip module has both a TTL UART and an SPI port, and it has a 1 pulse/second input for synchronization with a GPS module. It’s available in the V14447-03-02 RS-422 evaluation kit for easier prototyping. The module has built-in test (BIT) modes for testing on command, along with continuous diagnostic monitoring. It is factory calibrated and temperature compensated over an operating temperature range of -40°C to +85°C.

The factory calibration and temperature compensation allows Thales to add a series of stability specifications to the NavChip module’s data sheet that are not to be found on most other commercial IMU data sheets:

  • Gyro bias in-run stability: 5°/hour
  • Angular random walk: 0.18°/√hour
  • Velocity random walk: 0.03 meters/second/√hour

The software angle

With all of the IMUs listed in this article, the software that extracts the raw sensor data is not difficult to write as demonstrated by the Arduino code listing above. However, the integration of these sensor readings into usable navigation data is a more complex task. There are some open source packages specifically designed to incorporate IMU data into an application.

ArduPilot Mega (APM) is one such program specifically developed for autonomous drones. It supports both piloted and unpiloted (fully autonomous) flight and includes hundreds of GPS waypoints, camera control, and autonomous takeoff and landing. Because it’s open source, the IMU code is open for inspection and can be repurposed for other types of applications.

The Robot Operating System (ROS) from the Open Source Robotics Foundation, is a flexible framework for writing robotics software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms. ROS contains interface code for several IMUs to inform its navigation modules.


Many embedded applications require the ability to locate the system’s position anywhere on earth. GNSS receivers alone are not sufficient, but when complemented by IMUs, finer positioning accuracy and faster update rates are attainable.

免責条項:このウェブサイト上で、さまざまな著者および/またはフォーラム参加者によって表明された意見、信念や視点は、Digi-Key Electronicsの意見、信念および視点またはDigi-Key Electronicsの公式な方針を必ずしも反映するものではありません。


Steve Leibson氏

Steve Leibson氏は、HPとCadnetixでシステムエンジニアを務め、EDNとMicroprocessor Reportで編集長として活躍し、XilinxとCadenceなどの企業では技術ブロガーを担当しました。また、同氏は、「The Next Wave with Leonard Nimoy」の2つのエピソードで技術専門家を務めました。同氏は、33年間にわたって、高速でかつ信頼性の高い優れたシステムを設計技術者が開発することを支援しています。