Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating quaternions from gyro + accelerometer data

I have gyroscope + accelerometer data at each time period T.

Using C++, I want to calculate the rotation of the object at each time - it can rotate on its axes. I've read that it is convenient to represent the rotation of the system in terms of quaternions (not in Euler angles).

How can I transform from angular velocity (from gyroscope) to the quaternions representation? I think in order to do it I need to solve the differential equation using numerical methods.

like image 443
maximus Avatar asked Sep 27 '10 01:09

maximus


People also ask

What is quaternion IMU?

A quaternion can be thought of as a four element vector. This vector is composed of two distinct components: a scalar and a 3 element unit vector. The scalar value, w, corresponds to an angle of rotation. The vector term, [x y z], corresponds to an axis of rotation, about which the angle or rotation is performed.

What is XYZW quaternion?

A quaternion is a set of 4 numbers, [x y z w], which represents rotations the following way: // RotationAngle is in radians x = RotationAxis. x * sin(RotationAngle / 2) y = RotationAxis. y * sin(RotationAngle / 2) z = RotationAxis. z * sin(RotationAngle / 2) w = cos(RotationAngle / 2)


2 Answers

I'm not sure which language you're looking for, but the C++ Boost library has a working Quaternion class (quaternion.hpp). I've used this library to create a simple rotation class for computing the results or rotating points about arbitrary vectors with very little difficulty.

UPDATE: Based on your comment, I don't think you necessarily need to use a quaternion library to figure out your angular position at a given time, given either a constant angular velocity or angular acceleration. All you need to do is to figure out what that angle is, and then use the quaternion class to compute the position of vectors when rotated about your rotation vector by the angle you've computed.

Given a constant angular acceleration α, an initial angular velocity ω(t0) and initial angular position θ(t0) in the range [0, 2π) the angular position at some time t > t0, θ(t) is given by:

θ(t) = [θ(t0) + ω(t0)*(t-t0) + α*(t-t0)2/2] mod 2π

Here the mod 2π operation is simply the residual when subtracting n2π where n is the integer required to ensure the residual is in the range [0, 2π). For a constant angular velocity (i.e. α=0) the last term drops out.

That said, all you really need to do is to keep track of the angle over some interval of time under constant acceleration (or determine the average acceleration over that time if it's not constant) and update the angle. You then apply the resulting rotation about your rotation vector to the quaternion you're using to accumulate your rotations. This can be easily implemented as a C++ class.

Still, if you're looking for an open source tool to do this, I expect that any of the game physics modeling libraries will be more than adequate. A couple of open source ones are Bullet and the Open Dynamics Library.

like image 74
andand Avatar answered Sep 21 '22 05:09

andand


Would you be talking about a Slerp? (Spherical Linear Interpolation)

See Jonathan Blow's article "Understanding Slerp, Then Not Using It" which has example source in C++...

http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/

like image 30
Allbite Avatar answered Sep 19 '22 05:09

Allbite