# Correctly calculating free acceleration given NED referenced orientation quaternion and sensor referenced acceleration data

I have a sensor outputting correct, calibrated North-East-Down referenced quaternions describing the orientation of the sensor. It also outputs raw, sensor referenced acceleration data, inclusive of gravity. I want NED free acceleration, without gravity.

What I have been doing is rotating the acceleration data by the quaternion, and subtracting gravity from the z axis. this doesnt really make sense to me.

I think it should be something more like

1. Rotate acceleration data by the quaternion (brings data to some strange frame?
2. Subtract gravity from z axis
3. Inverse rotation (back to sensor frame?)
4. Second inverse rotation? (goes to NED frame??)

Any explanation would be appreciated

I think you have the concept down. I'm not sure what the "some strange frame" would be, or how you would have a transform to that frame.

You know, by physics, that gravity points down in the world frame. You know, by your sensor's orientation quaternion, how the sensor is oriented relative to the world.

So, as you mention:

1. Rotate acceleration data by the quaternion from the sensor frame to the world frame.
2. Subtract gravity from the down axis (typically z or y - be sure to read the sensor's data sheet!)
3. Rotate the acceleration data from the world frame to the sensor frame.

I'm not positive why you would want that last step though, unless you were doing something strictly in the local frame. Generally you would care about how an object is oriented or how it moves with regards to an arbitrary start location in the world frame.

That is, once you rotate the acceleration data to the world frame, you can remove gravity, and then perform your single and double integrations to get speed and position with respect to the world frame. I'm not sure what you get by going back to the sensor frame after removing gravity.

Maybe this is your fourth point?

Second inverse rotation? (goes to NED frame??)

Right, because again you care about how the object moves with respect to the world. If you don't care about that relationship then you're in a pretty small minority of IMU applications, and I personally can't really imagine the scenario you're working with.

But, if you look, your points three and four cancel and you're left with one and two - rotate to world frames, remove gravity.

• Thanks for answering, but im still not quite getting this - if i have sensor frame accelerometer data to start, and i do a forward rotation by the quaternion, how does that bring it to the world frame? in my mind that would bring it further from the world frame. – Mauvai Jul 20 '17 at 13:13
• @Mauvai - It depends on how the quaternion is defined, and you should check the data sheet for the sensor to be sure. It might be that the quaternion is the sensor's orientation with respect to the world frame, in which case you do want the inverse, or it could be that it's the orientation with respect to the starting orientation, which is dangerous because your starting orientation is not necessarily (is not normally) aligned with the world frame, so you need to know the relationship between starting and world frames, and again you need to use an inverse transform. – Chuck Jul 20 '17 at 13:17
• So assuming I do have a world frame referenced quaternion, what is my procedure? Inverse rotation subtract gravity, and finished? Could you explain why most papers seem to only do a forward rotation, but also have a world frame quaternion? – Mauvai Jul 20 '17 at 14:42
• @Mauvai - Most papers seem to - Can you link one of the papers? I'll point out too that generally I've seen quaternions get converted to rotation matrices to do the actual transforming of coordinates. There's a trick to that, too - the inverse of a 3x3 rotation matrix is the same as the transpose of the same 3x3 rotation matrix. So, where you might expect an inverse transform to be more explicitly signaled, like $R^{-1}$, it might be "hidden" with the transpose apostrophe $R'$ - the end result is the same. Again, please link a paper that shows what you're talking about. – Chuck Jul 20 '17 at 15:01
• By hidden I mean that it's easy to overlook the apostrophe there on the rotation matrix. Depending on the font type and size it tends to run together with the R notation: Compare $R$ and $R'$. – Chuck Jul 20 '17 at 15:03

Accelerometer frames are kind of tricky. They treat the sign differently for gravity and regular accelerations. This is the equation they use: $$a_{accelerometer} = a_{sensorFrame} - g$$

See this question for more info: Why do 3-axis accelerometers seemingly have a left-handed coordinate system?

• This doesnt really answer my question in any way.... – Mauvai Jul 20 '17 at 14:43