1

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.

  • forget about Euler angles for this construct [4x4 homogenous transform matrix](http://stackoverflow.com/a/28084380/2521214) instead. For that you need 2 vectors. One is your mean gravity from acceleration (Down) so you still need second vector. May be `(1,0,0)` or `(0,1,0)` with some rotation from gyro but that needs experimenting otherwise the gimbal lock would glitching. then exploit cross product to construct 3 perpendicular unit vectors one for each axis. – Spektre Sep 02 '16 at 19:00
  • Ok thank you for your response. I built three matrices one for each axis Rx, Ry and Rx as explained in this link [link] https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm. My angles are the angles calculated from gyroscope. Now I want to know how to get the new position from these matrices and accelerometer data. Thanks a lot. – Luigi Biasi Sep 05 '16 at 13:53
  • That are still Euler angles implementation which is not usable for you as any rotation invalidate the others ... `M=Rx*Ry*Rz` or in any other order will not lead to the orientation you want. Btw what do you mean by "new position" ? To compute position from accelerometers and gyros is not that easy (because you need to filter out local force fields not affecting movement like gravity for ground based objects) see [Algorithm to Calculate Position of Smartphone - GPS and Sensors](http://stackoverflow.com/a/19764828/2521214) – Spektre Sep 05 '16 at 14:42
  • Ok I have a device with a IMU 6DOF (accelerometer 3DOF and gyroscope 3DOF), I want that an object(cube for example) in a unity3d scene follows that device, follows the IMU rotation. I tried to do this by means euler angles, calculating pitch, roll and yaw angles. But I don't have a full rotation of 360 degrees in pitch angle. How can I solve this problem? Thanks a lot. – Luigi Biasi Sep 05 '16 at 16:08

0 Answers0