# How do you implement an INS from an accelerometer and (optionally) gyros and a magnetometer?

I'm building a walking robot that will need to know when it moves forward. I'm using on-board intelligence and I plan on using accelerometers, gyros, and magnometers (if needed) to be able to detect if the robot moves forward. The problem is, I dont know how to program an Internal Navigation System or an IMU. What software algorithms are needed?

To clarify my problem, I need to know how to program the micro controller to read the sensors and be able to tell if the robot has displaced itself forward since a previous measurement. Also if I used this sensor board (or similar) could I use it to determine the displacement.

• Can you explain a bit more. Are you hoping to be able to calculate the robot's location in space using the IMU, or do you just want to be able to measure its tilt and detect when it lurches forward? Nov 14 '12 at 23:40
• Are you trying to make your own IMU or use the ArduIMU? Nov 19 '12 at 3:57
• The ArduIMU only provides the sensor information from the sensors, not the actual displacement, correct me if I'm wrong, but don't I need to manipulate the data from the ArduIMU to detect forward movement or is this a lot simpler than I think? Nov 19 '12 at 7:10
– Robz
Jun 20 '13 at 6:18

To get relative displacement between two time instants all you need to do is integrate the values given off by the accelerometer (twice for linear displacement) and gyro (once for angular displacement).

Due to measurement errors, which can many times be adequately modeled as Gaussian (you might have to estimate a bias and/or scale factor to the measurement), there will be drift in your estimate (i.e. errors accumulate and your estimate diverges). Because of that, if you plan to use the IMU to obtain position and orientation estimates relative to a fixed frame, you will also have to use more information to correct that estimate. These corrections can be made using a Kalman Filtering approach.

Many people use the accelerometer and magnetometer data to do that, assuming your robot isn't moving too fast (i.e. $g \gg a_{robot}$), there aren't many magnetic field disturbances (i.e. $m_{earth} \gg m_{other\_stuff}$), and both vectors are perpendicular and have fixed orientation with respect to the ground. See, for instance, the TRIAD algorithm.

But then again, back to your question, if what you mean by "robot has displaced itself forward since a previous measurement" is:

• Relative to his own body, regardless of his orientation in space, all you need to do is check the sign of the accelerometer output in the forward direction (you might want to set a minimum threshold or perform median filtering due to sensor noise)

• Relative to a fixed frame, you have to take everything I talked about into consideration

If you're looking for an inexpensive sensor, you could check out InvenSense's MPU-6000, which combines a 3-axis gyroscope and a 3-axis accelerometer. It communicates via an I2C or SPI bus with your main processor and is capable of estimating attitude when you add a magnetometer.