I am implementing a software that reads the raw data by an accelerometer (connected via USB port) and rotates a virtual object (for example a cube in unity3d environment). From the raw data given by the accelerometer I calculate the accelerator components:
Xg = raw_data[0]*range/pow(2,resolution-1) //for x accelerator component
Yg = raw_data[1]*range/pow(2,resolution-1) //for y accelerator component
Zg = raw_data[2]*range/pow(2,resolution-1) //for z accelerator component
where range and resolution are provided by accelerometer datasheet.
Then I calculate the pitch and roll angles by means these formulas:
roll = arctg(-Xg/Zg)*180/PI
pitch = arctg(Yg/sqrt(pow(Xg,2)+pow(Zg,2)))-180/PI
Finally I get the yaw angle from gyroscope.
In order to rotate an object in my scene I set its euler angles to these value but the object has a full rotation in x and z axis (roll angle and yaw angle), but not in y axis (pitch angle) where the object rotates only 180 degrees. The problem is that the pitch angle is in range [-90,90] degrees and the object cannot have a 360degrees rotation. Is there a formula for pitch angle to have a 360 degrees rotation also for the y axis? Thanks a lot.