# Can I “integrate” the data from an accelerometer to record a motion trajectory?

I would like use an accelerometer equipped device to record a motion trajectory, as high-resolution and low-noise as possible. For instance, let's say I run a jogging route of 6 kilometres, returning exactly back to the location I started from. So I have the idea that I could possibly do without a GPS module and just record at constant rate the data from an accelerometer, say an ADXL345.

My questions thus:

• can I use a 3-axis accelerometer to integrate twice, from acceleration to velocity to distances?
• if the constraint is that I return to the exact location from where I started, can I apply an error-correction to the trajectory that compensates for drift, so that the last (x,y,z) coordinate of the recorded and integrated data becomes identical to the first one?
• say I run from location A to B and back to A again. If I apply the mentioned drift-correction, do I still have a meaningful/correct position of spot B?

If not, how would I achieve this? Do I have to combine the accelerometer with a GPS?

## migrated from raspberrypi.stackexchange.comJul 3 '16 at 20:56

This question came from our site for users and developers of hardware and software for Raspberry Pi.

• Sadly, none of your questions are specific to the Raspberry Pi and are off topic here. Looking at your topics, I think you might find the most help on the Physics board. – goobering Jul 3 '16 at 19:43
• This appears quite broad and would probably require an essay for an answer. – joan Jul 3 '16 at 19:44
• Well, I would like to know if anyone did something like this, on the Raspberry Pi. The three questions can be answered as short as Yes/No or hopefully with a sentence or two. I don't see how this is a particularly broad question. Is it feasible or not? If not, which is a better approach? – 0__ Jul 3 '16 at 19:55
• As mkeith says, at a minimum you also need a gyro (and yu can buy ICs with both incorporated) BUT at anything like low cost the inertial navigation unit so formed has only short term accuracy due to various errors. – Russell McMahon Jul 3 '16 at 22:17
• Record the raw data from the accelerometer for a sample run (start with a short one). Load it into Matlab - or even a spreadsheet and double integrate. See where it ends up. – Brian Drummond Jul 3 '16 at 22:34

No, this won't work in theory or practice because you do not have sensors to capture rotational motion. When you rotate an accelerometer, it is unable to detect that its coordinate system has rotated with respect to the desired coordinate system. What you are trying to do is called inertial navigation. In principle, to do inertial navigation, you need a three-axis accelerometer as well as a three-axis gyro (or angular rate sensor) to capture rotational motion. Then the acceleration data can be converted to displacements in the frame of reference you are using.

In practice, even if you add a gyro, doing this accurately is very difficult because small constant errors in acceleration become very large position errors during the process of integration. The only saving grace in your case is that if you add the assumption that you start and stop in the same place, you may be able to leverage that to calibrate out the drift (again, assuming you add a 3-axis gyro). Although user CortAmmon expressed skepticism that this extra information would be sufficient for calibrating out any drift in the acceleration measurement.

CortAmmon points out that the Northrup Grumman LN200 inertial measurement unit costs US$90,000, and could be expected to have a position error measured in km after the time it takes to do a run. Items like this are not only very expensive, but likely "export controlled" if made in the US. The reason is that Inertial nav units are used in missiles. This gives them the ability to hit a target even when GPS is being jammed. • If you add a gyro and a GPS, you can use the sensor data to perform dead-reckoning (inertial navigation) between GPS fixes. That is your best bet. Dead reckoning is an old term dating back to the days of sailing ships. – mkeith Jul 3 '16 at 21:14 • An hour is a very very very long time for an IMU to dead-reckon by integration. Consider the example of a LN200, which is used in some high reliability military devices, and is incredibly pricey. I've seen estimates of$90k for one device. Even so, they will be off by kilometers by the end of your run, and its very hard to undo acceleration errors by simply declaring "I'm back where I started, go fix the rest of the path" – Cort Ammon Jul 4 '16 at 4:43
• @CortAmmon, thanks for the information. Do you think what the OP is trying to do is hopeless, even if various constraints/assumptions are factored in? – mkeith Jul 4 '16 at 4:59
• Inertial navigation over those timeframes with any useful precision is hopeless unless you fuse the data with some other source. An error propagation of a few hundred micro-gees over an hour is just too hard to get rid of if you only get two registration points, one at the beginning and one at the end. And any IMU which can get even remotely close to that sort of precision is going to be far more expensive than a GPS. A $20 Parallax GPS unit is going to provide much better results than integrating the data from a$200,000 IMU. – Cort Ammon Jul 4 '16 at 5:13
• The actual limits vary by country but internationally most countries follow the Missile Technology Control Regime treaty. The MTCR technical annex specifies a minimum accelerometer scale factor repeatability of better than 1250 ppm and a bias repeatability of better than 1250 uG. Gyros are limited to an RMS drift of less than 0.5 degrees RMS/hr. Perform better than these limits and your device is restricted by arms control. – Peter Oct 19 '17 at 22:49

Yes, you can integrate acceleration (at least in a straight line) to get distance.

As mkeith indicates, even if it did work, it would only be accurate for very short distances.

Even if combined with a GPS, you could not use this method to compensate for the GPS inaccuracies. It is possible to purchase a differential GPS, but they're out of reach for most hobbiests.

Don't know your application, but you might consider triangulation by IR LEDs.

• Of course, you're right! I'd have got there if I'd spent the extra millisecond on it!! Will edit that out. Hmmm. Now it's more of a comment than an answer! – KDM Jul 3 '16 at 21:53
• Thanks. "Don't know your application" - we'll it's an art project, so no car crashes when there is a calculation error. Given that the GPS is too expensive, I will probably just give a shot to a combination of accelerometer and gyroscope. – 0__ Jul 3 '16 at 22:49
• @0__, if you are able to also add an electronic compass (fluxgate compass) that can help calibrate out the gyro errors. In general, the more assumptions you can incorporate into the data processing stage, the more likely you are to have an acceptable result. – mkeith Jul 4 '16 at 0:26