This course will introduce you to C++ 11 and teach you about syntax fundamentals.

I am writing an iPhone/iPad app. I need to compute the acceleration and deceleration in the direction of travel of a vehicle traveling in close to a straight horizontal line with erratic acceleration and deceleration. I have the sequence of 3 readings from the X,Y,Z orthogonal accelerometers. But the orientation of the iphone/ipad is arbitrary and the accelerometer readings include vehicle motion and the effect of gravity. The result should be a sequence single acceleration readings which are positive or negative depending on whether the vehicle is decelerating or accelerating. The positive and negative direction is arbitrary so long as acceleration has the opposite sign to deceleration. Gravity should be factored out of the result. Some amount of variable smoothing of the result would be useful.

The solution should be as simple as possible and must be computationally efficient. The answer should be some kind of pseudo-code algorithm, C code or a sequence of equations which could easily be converted to C code. An iPhone specific solution in Objective C would be fine too.

Thanks Martin

The solution should be as simple as possible and must be computationally efficient. The answer should be some kind of pseudo-code algorithm, C code or a sequence of equations which could easily be converted to C code. An iPhone specific solution in Objective C would be fine too.

Thanks Martin

Assume the vehicle is not moving.

Sum the signals from the A, B, and C accelerometers to get a 3D vector.

The magnitude of the vector must be g = 9.8 m/s²

The direction gives the orientation of the sensor.

Now assume the vehicle is accelerating and decelerating arbitrarily along a straight horizontal line. Call it the X-axis.

Sum the signals from the A, B, C accelerometers to get another 3D vector.

The magnitude of the vector M must be GT or EQ to g.

This vector can only have two components: Az = g and the vehicle acceleration Ax.

Ax = sqrt( M² - g²) the sign is ambiguous.

Align the

The sensor measures acceleration along three orthogonal axes --

Since the vehicle and the sensor accelerate together:

Therefore (

Yes the iphone is sitting in the vehicle. But it's orientation is arbitrary. If I could insist the phone were known and fixed in it's orientation there would really be no problem at all. But it is not known and may change periodically. So none of the accelerometer figures necessarily corresponds to vertical (g), forward or sideways.

The solution must include specific equations for the vector and or filter math etc.. How do I rotate the X,Y,Z accelerometer data if that is the solution?

Thanks Martin

A moving average would probably be appropriate for the filtering. What are the sample rate of the accelerometer and the required response time of the signal?

http://en.wikipedia.org/wiki/Moving_average

The only problem is that acceleration has no direction. You want to know when the car is travelling backwards. You can do this by comparing the directions of the vectors, a dot product should be enough. The problem is that you don't have a reference direction. You could assume that the car starts moving forwards, but that's not 100% safe. You could use the compass to establish the direction of the device if you know which way the car will be travelling, if it's following a road map for example.

The real issue is that you can't be sure of the orientation of the phone inside the car. Being able to move the phone around would also cause distortion, rattling of the car and many other factors would interfere. Depending on the distance involved you could try using GPS readings instead.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

the orientation of the cell phone in the vehicle does not matter.Really.

There is only one unknown -- the magnitude (and sign) of the acceleration along the x-axis.

The complete solution to the problem is: |Ax| = SQRT( Aa² + Ab² + Ac² - g² )

where Aa, Ab,and Ac are the accelerometer readings.

This is the first time you have mentioned filtering.

But please try some calculations with real data.