FreeSix IMU library Patch for ITG3200/ADXL345

Hi everybody, I made a project where I need to stabilize a camera. It looks like a platform with a linear actuator at one end for changing the pitch of the platform.
To achieve this I got an ITG3200/ADXL345 breakout board from Sparkfun (SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 - SEN-10121 - SparkFun Electronics)
Here is what the program does:

1-Get the angle of the Y axis of the IMU (using FreeSixIMU library, which calculates the absolute angle with the acc and gyroscope data)
2-Pass it through a function to determine how much juice I need to send over the motor and in which direction to keep the platform stable
3-Output this value to a Polulu motor controller

I achieved all the above easily, but I got stuck with one issue:
I use only one measured axis (X) of the IMU. Whenever I put the IMU sensor at an angle (say 45 degrees X) and I rotate it along the Z axis, the value read by the X axis (which is at 45 degrees) is not 45 degrees anymore.

I made this animation to show which angle I want to read. But in practice, the value changes and goes from -45 to 0 to 45 degrees when it spins on Z axis. I want the reading to always be -45 like in the video.

I tried to modify the FreeSix IMU library to delete every references to the Z axis, which I don't need in the project, but I don't have much knowledge of the formulas used. Here are the basic lines of the library, it seems to use a quaternion system, which I don't fully understand :
(FreeSixIMU.cpp)

void FreeSixIMU::getEuler(float * angles) {
float q[4]; // quaternion
  getQ(q);
  angles[0] = atan2(2 * q[1] * q[2] - 2 * q[0] * q[3], 2 * q[0]*q[0] + 2 * q[1] * q[1] - 1) * 180/M_PI; // psi
  angles[1] = -asin(2 * q[1] * q[3] + 2 * q[0] * q[2]) * 180/M_PI; // theta
  angles[2] = atan2(2 * q[2] * q[3] - 2 * q[0] * q[1], 2 * q[0] * q[0] + 2 * q[3] * q[3] - 1) * 180/M_PI; // phi
}

Where angles[0] corresponds to Z axis,
angles[1] to X axis and
angles[2] to Y axis.

The entire library is avalaible at: http://code.bildr.org/project/6dof/Arduino and for download at http://code.bildr.org/download/985.zip.

What I want is someone who could patch the library for me so it would exclude Z axis when measuring angle. It would apply to X and Y measurements. I need to get it working as soon as possible, so I am willing to pay 15$ paypal to whoever will supply me a working patched library.

If you have additional questions, feel free to ask me!

Thank you very much for your time!
Charles

If you want to ignore the Z axis, the only way you can safely do that is to constrain the platform so that it can only rotate about the Z axis.

Any other setup needs to have two servos to stabilize the platform - one dealing with rotations about the X axis and one dealing with rotations about the Y axis.

That function that you show gets the rotation about each axis. What YOU need to do is to compare the current angles to the previous angles. The delta X and delta Y values should then be small.

Hi guys, can anyone guide me on how to connect the adxl345 to the arduino if im using itg3200 as well? im hooking it onto arduino uno. how's the sda and scl pins gona connect to and the cs and sdo pins? thanks for any help!!! :blush: