MATLAB Answers

Why ,the quaternion values from sensor fusion toolbox are switched ?

22 views (last 30 days)
Hesham Safyeldin
Hesham Safyeldin on 29 Nov 2019
Commented: James Tursa on 7 Feb 2020
Hello everyone,
I am using the Sensor Fusion and Tracking Toolbox. I have raw data from accelerometer and gyroscope.. I imported them to matlab and logged them to imufilter in order to estimate the orientation. ( i want to compare the results of matlab with my own algorithm for gettting the orientation)
However, The quaternions estimated from the toolbox have an unexpected behavior.
the i (x-axis) values are switched with the w values (the real part). So for example , the initial quaternions are someting like 0.0023 + 0.99i -0.001k + 0.001j.
and going along the data set .. it seems they are so similar to my orientation output except that the values of i and w components are switched. I wanted to know why ? or what i am doing wrong. Thank you
Update: I have now transformed the quaternions to normal vectors using (compact) and I noticed the following when I compared the results from the toolbox and results from my alogrithm (assuming Q = [w,x,y,z]) :
  1. The scalar w component is at i (x) and has an inversed sign
  2. The x compnent is at w position with the same sign
  3. The y component is at the z position with an inversed sign
  4. The z component is at the y position with the same sign

Answers (3)

Jim Riggs
Jim Riggs on 29 Nov 2019
There are two different ways that are commonly used to represent quaternions.
Q = [a,b,c,d] with d being the scalar part, and a,b,c being the vector part.
or
Q = [a,b,c,d] where a is the scalar part and b,c,d represent the vector part.
Matlab currently uses the latter representation; a is the scalar, and b,c,d are the vector coponents. Make sure that your code is the same.
  3 Comments
Hesham Safyeldin
Hesham Safyeldin on 3 Dec 2019
@james, thanks for answering
input data are attached with some figures of the problem. However ,it is now solved. It was a reference frame problem.
But maybe I can ask you something else if you may.
Why always the quaternion results coming out from the toolbox are not initalized to [1,0,0,0] .. they are pretty close but not equal.

Sign in to comment.


Hesham Safyeldin
Hesham Safyeldin on 3 Dec 2019
It turned out to be a 'Reference Frame' problem.
I think my sensor gives data in 'ENU' while the default in Matlab is NED. Honestly I do not understand too much the impact of the difference from these 2 reference frames. but when I changed the reference frame, problem seemed to be solved.

Brian Fanous
Brian Fanous on 11 Dec 2019
Hensham
There are a few issues that might be going on. First, if you are using the NED convention of the imufilter, then you have to make sure that your input sensor data is also using that convention (i.e. on a flat surface your accelerometer z-axis gives a positive value, clockwise rotations give positive values from the gyroscope, etc). There’s a demo to illustrate that here:
The other thing to be aware of is what the quaternion output of imufilter means. The imufilter gives a quaternion q that will take a quantity in the parent (global) frame to the child (sensor) frame, when used with a frame rotation. That is
x_sensor = framerotate(q, x_global).
Ensure the library you are using is doing that as well.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!