0

Im currently trying to write a code that rotates 3D accelerometer data about the X, Y and Z axis. The accelerometer is off set by 10, 5 and 25 degrees from a GCS about the X, Y and Z axis respectively.

The trouble I am having is that the process is non commutative, so the results I am generating from the initial measurements are not correct. Once the accelerometer data is rotated by the first angle, the original angle measurements become incorrect (I believe).

Is it possible to calculate the new angle required after each rotation to update the code and continue rotating the data?

In the code below I have entered values into the function just to illustrate the point as the resultant output should all be of equal magnitude if the vector was equidistant from each axis.

Any help will be greatly appreciated. Thanks.

def rotation_matrix_3D(x_rotation_deg,y_rotation_deg,z_rotation_deg,acceleration_x_y_z):

    x_rotation_deg = np.radians(x_rotation_deg)
    y_rotation_deg = np.radians(y_rotation_deg)
    z_rotation_deg = np.radians(z_rotation_deg)

    ca,sa = np.cos(x_rotation_deg),np.sin(x_rotation_deg)
    cb,sb = np.cos(y_rotation_deg),np.sin(y_rotation_deg)
    cg,sg = np.cos(z_rotation_deg),np.sin(z_rotation_deg)

    R_x = ([[1,0,0],[0,ca,-sa],[0,sa,ca]])
    R_y = ([[cb,0,sb],[0,1,0],[-sb,0,cb]])
    R_z = ([[cg,-sg,0],[sg,cg,0],[0,0,1]])

    rotation_matrix = np.dot(np.dot(R_z,R_y),R_x)

    return np.round_(np.dot(acceleration_x_y_z,rotation_matrix),3)

rotation_matrix_3D(0,45,45,[10,0,0])

>>>> array([ 5.   , -7.071,  5.   ])
PowellD
  • 1
  • 1
  • Can I add any furthur detail incase what I am asking isn't clear? – PowellD Feb 11 '20 at 11:53
  • Maybe this helps https://stackoverflow.com/questions/3755059/3d-accelerometer-calculate-the-orientation – ferhen Feb 11 '20 at 12:43
  • Thanks for the reply, the link is interesting but I don't think it will apply fully as it doesn't include yawing of the accelrometers. – PowellD Feb 12 '20 at 10:37

0 Answers0