# How to calculate orientation representation from raw sensor data?

I'm using the Madgwick Filter to calculate estimates of velocity and position for some testing. The simulated data I'm comparing it to has ground truth values of the position, velocity, Euler angles, and direction cosine matrices.

The Madgwick Filter works by updating it's quaternion each iteration based on the data's rate of change. However, it's initial value is [1 0 0 0] unless I manually set it. I want the initial value to be as close as possible to the ground truth so I can get accurate drift values.

The library I'm using has functions to change representations between quaternions, DCMs, rotation matrices, and Euler angles. I can manage once I have accurate values in one of these forms.

The data with initial conditions is from this site at the bottom: Data

tl;dr - How can raw sensor data from an Accelerometer, Gyrometer, and Magnetometer be combined to calculate the initial quaternion, DCM, rotation matrix, or Euler angles?

I asked the question, though I figured it out so I might as well answer.

Turns out, using the sensor data doesn't provide enough information. You need to know the starting configuration before any data comes in. Lucky for me, this was given by the provided data set.

The IMU is simulated rotated with 5.01620 (0.0875 rad) of roll and 33.17520 (0.5790 rad) of pitch like the picture.

Well-defined functions are then able to convert this set to any of the needed forms.

This can be tested using the acceleration data:

RotatedAcceeration * RotationMatrix = OriginalAcceleration

Therefore,

RotatedAcceleration = OriginalAcceleration * RotationMatrix-1

After this operation, the RotatedAcceleration data at rest reads [0 0 9.8760], which is the amount of gravity listed on the spec sheet. Convert the Rotation Matrix into a quaternion and use that as the initial orientation.

• Do you have any sources on the steps to do this? Im stuck on the same problem – DJK Oct 19 '17 at 0:39
• I don't have sources, but it is quite simple actually. I used the Madgwick filter to update my quaternion, and the library that came with it to convert it to different forms (DCM, Euler, etc). The filter and library can be downloaded from link in C, C#, and Matlab. – Kaleb Burnham Oct 20 '17 at 1:31
• @djk47463 Forgot to tag you. – Kaleb Burnham Oct 20 '17 at 1:53