# Plotting Vehicle Path Based on Accelerometer Readings

1. Dec 18, 2008

### Pugio

There's a problem I've been working on for a few days that I can't seem to resolve:

There is a model train going around a set track with a 2-D accelerometer mounted along the axis of the train. The accelerometer provides the current x/y acceleration values at a frequency of about once every 0.01 seconds.

Using just those values, I am trying to recreate the path of the train. I thought I had understood the problem, and it's solution, but I seem to be getting stuck somewhere.

My strategy is first to assume initial position and velocity to be 0. I then keep track of a velocity vector. For each line of data I first:

1. Perform a coordinate translation to translate the given acceleration vector from coordinates local to the train/accelerometer to a global coordinate system.
2. Modify my velocity by the new accel vector * delta t.
3. Modify my position by the velocity * delta t.

Since the velocity vector encodes the current orientation of the train, I can use that value to translate the local acceleration vectors into the global coordinate frame.

Ideally, by plotting each position point I should get a graph illustrating the path of the train.

This seems to work at first, but at some point the train looks like it almost jumps the tracks and sails off in a straight direction. Somehow, despite the fact that the acceleration vectors indicate some form of curve/turn, the velocity supersedes this and the train heads straight off to nowhere.

I've checked my code/algorithm many times, and I don't think this is a simple programming error. It seems as if I am not understanding an aspect of this problem. Maybe something to do with propagated error in the acceleration readings?

An example of the data:
Code (Text):

t   x   y
0.01    -0.008  -0.002
0.02    -0.015  -0.003
0.03    -0.02   -0.003
0.04    -0.022  -0.003
0.05    -0.027  -0.002
0.06    -0.032  -0.001
0.07    -0.038  0
0.08    -0.042  0
0.09    -0.045  0

Any insight into this would be appreciated.

2. Dec 18, 2008

### mgb_phys

You have the correct method but it's difficult to do in practice.
The problem is that you have to integrate the accelration to get velocity and then integrate velocity to get position. But the accelrometers are inaccurate and noisy.
The normal solution is to average them with a Kalman filter but it is difficult to get a good position for very long without an external re-sync.

3. Dec 18, 2008

### Pugio

Thanks for the info. I agree it may be impossible, given noise of the data, but I'd like to try.

I've never used a Kalman filter before, so I'm unsure how I would go about applying one to my data (there isn't some simple set of steps I can encode into a computer function, is there?)

I guess I've got my work cut out for me.

4. Dec 18, 2008

### mgb_phys

Kalman filter is a technique for getting a smooth running average from constantly changing data.
It is either built into a library or you can write it from the description in wiki etc.
A cheap and simple version of a running average is to combine the new answer with the current value with sum weighting.

So if your new reading is xn and your current value is xc then you do, xc = (xc * 0.1) + (xn * 0.9)
You can choose the factor to adjust how much of the new value to use.
xc*0.9, xn*0.1 would only change the value a maximum of 10% on each reading so would give a very smooth result but it only changes slowly as you change direction.
xc*0.1, xn*0.9 would change more quickly but noisy values of xn would give you spikes.

You pick the ratio to give you the smoothing scale appropriate to how quickly your data should change. Obviously they have to add to 1.0 !

5. Dec 23, 2008

### Pugio

Thanks for all of your help. You're right, the data is very noisy - even with continuous smoothing. I'm currently tinkering with a method whereby I reduce the magnitude of the velocity vector at certain intervals to correct for some of the drift. We'll see how it goes.

Thanks again.

6. Dec 23, 2008

### GoldPheonix

More or less, yeah, this is just the lack of stability with changing values. It's for the same reason that Euler's Method isn't very good at solving differential equations, and that's data drifting. When you do the Riemann sums, especially twice over, your data is going to drift crazily. Also, there may be some error when you convert from the Frenet frames to the global Euclidean frame. Especially considering that the Frenet frame is based on the approximation of the global Euclidean frame, no?

I'd have to see your coding, but yes, there's going to be a lot of forms of error that will creep in. Like mbg said though, there exists several smoothing and counter-error methods for numerical analysis. I'm not very familiar with numerical analysis, but it may be worthwhile picking up a copy of a tutorial or a textbook on it.

7. Feb 21, 2010

### wirefree

Greetings.

I would appreciate if someone could demonstrate how the acceleration vector is calculated from the accelerometer's xyz-component readings, as in the first post above.

Look forward to a prompt response.

Best regards,
wirefree

8. Feb 21, 2010

### Phrak

Without knowing the shape of the track you would also need directional information that the accelerometers do not provide. Although you might get clever and place accelerometers in two cars or at opposite ends of one car.

9. Feb 21, 2010

### Phrak

I see you dug up an old thread from two years ago.

For each axis, x = x0 + v0t + (1/2)at2

This is the instantaneous equation for displacement from an initial position x0 at time t=0, where the velocity at t=0 is v0.

In practical application, one would take acceleration readings at equal time intervals (if possible). The averaged acceleration over the time interval gives you a velocity change that you add to the old velocity value. The averaged velocity gives you a displacement change that you add to the old position.

In the real world, depending upon application, you would want to filter-out accelerometer noise, do curve fitting and compensate for all other real world effects on the instrumentation that introduce error.

This could take a lot of computational horse power depending on how long you can go with polynomial increasing positional error and how far off you can be.

10. Feb 23, 2010

### wirefree

I seek a clarification with regards to the sample script available in the sensor framework documentation.

For every line of output from the accelerometer (e.g. X:3,Y:51,Z:8), this vector is with reference to an origin situated at which coordinate?

Look forward to prompt advise.

Best regards,
wirefree101

11. Feb 23, 2010

### Phrak

As I'm aware from a brief education some smart phones contain a single three axis, "3D", accelerometer.

From physics class you might recall that for something sitting stationary on the earth, it is subject to an acceleration of about 32 feet per second^2.

What this accelerometer is good for is sensing tilt direction and small displacments.

For instance, for the phone sitting still and tilted, it can tell which way is down.

For motion involving revolution around the vertical-axis it will get lost.
It doesn't know which direction north is even if told.

Last edited: Feb 23, 2010
12. Feb 23, 2010

### D H

Staff Emeritus
That would be the case frame of the accelerometer. In this example the accelerometer is affixed to a train. That accelerometer case frame can easily be transformed to a structural frame based on the train.

13. Feb 23, 2010

### Phrak

I give up. What's a sensor framework? I thought it was some proprietary software advanced by one organization for use in smartphones.

14. Feb 23, 2010

### D H

Staff Emeritus
I don't know what "sensor framework" wirefree was referring to. The original post was about accelerometers mounted on a train. wirefree also asked about the frame of reference in which accelerometer readings are referenced. That is the "case frame" of the accelerometer.

15. Feb 24, 2010

### Phrak

oh, OK. That's what I'd thought maybe.

I'd considered this problem driving home, running several red lights in the process.

It doesn't seem possible, using 3 orthogonal accelerators, alone, to obtain positional information without sever presumptions on the motion of the object.

Even constrained to motion in two dimensions on the Earth, where one is vertical so that one dimension has an acceleration bias, it can be fooled: It's possible to always keep the object under a constant 1g acceleration while rotating it in the xz-plane.

It may think that it's standing still, say, but it's dropping and accelerating in the y direction.

16. Feb 24, 2010

### wirefree

Do apologize. The sensor framework reference was out of context for this forum. It may nonetheless be found http://library.forum.nokia.com/inde...ID-D803F300-88E0-4A46-90E6-C540BA123ADF.html".

Unfortunately, my query remains explicitly unanswered. I will attempt to state it simply below using the train example.

Given:
1) Equation of a completely flat floor plane on which the train tracks rest
2) Normal to the floor plane
3) Accelerometer readings in the format "X:3,Y:51", generated periodically

Question:
For each reading of the accelerometer, would, or would not, it's dot product with the normal to the floor plane be zero?

Please feel free to answer in a binary yes/no. Look forward to a prompt response.

Best regards,
wirefree

Last edited by a moderator: Apr 24, 2017
17. Feb 24, 2010

### mgb_phys

Except for the original heading it is.

Imagine you set off and accelerate 0-60 in 20seconds, the accelerometer can measure this and assuming no noise there is only one position and velocity you can end up at after this time. You then coast at 60mph for 60 secs, again this is sensed by 0 acceleration, and you must be 1 mile along the start direction, you then brake at a certain acceleration back to rest.[/QUOTE]

18. Feb 25, 2010

### Phrak

It would, of course.

19. Feb 25, 2010

### Phrak

I don't know what you're getting at. If you constantly accelerate in the x direction with a spinning accelerometer where the normal axis includes the x axis, it's useless for positional information.

To, at least theoretically, get positional information using accelerometers alone, you would need at least 3 individual 3 axis accelerometers.

Last edited: Feb 25, 2010
20. Mar 7, 2010

### Holmz

If you have the accelerometers on rails (so you know the heading) then you can figure out where you are.

I think you either need gyros or magnetometers with it if you have more than 1 direction you could go as well as more than one orientation of the device.