CCNYRoboticsLab / imu_tools

ROS tools for IMU devices
Other
913 stars 428 forks source link

Confused about filtered orientation #92

Closed yumixx closed 5 years ago

yumixx commented 5 years ago

Hello,

I'd like to integrate imu_filter_madgwick into my own code for getting change of yaw from imu, but I'm a little confused about the reference frame of orientation after filtering. I thought the orientation in filtered imu data means coordination of imu frame relative to world frame, the source code in imu_filter_ros.cpp accords with my understanding. However I'm totally confused after comparing the source code with conference paper of the algorithm while in paper it's said the estimation means the orientation of earth frame relative to sensor frame.

Could you please explain it a little for me? Thanks!

titanproger commented 5 years ago

http://x-io.co.uk/res/doc/madgwick_internal_report.pdf for thouse who have no account at https://ieeexplore.ieee.org

yumixx commented 5 years ago

@titanproger Thanks for your help and links to peper. After reading that report I've found that I misunderstood the representation of orientation, which is detailed described in internal report Section 2.

titanproger commented 5 years ago

As I understend you get it right. The orientation in article is the orientation of earth frame relative to sensor frame.
To get the orientation of sensor frame - you need get conjection quaternion. (w, -x,-y,-z) Or for example you can modify the angle getting formula. for example

 T roll  = atan2f(w*x + y*z, 0.5f - x*x - y*y); // roll
 T pitch = asinf(-2.0f * (x*z - w*y));
 T yaw   = atan2f(x*y + w*z, 0.5f - y*y - z*z);

as you can see this is same formula as Madgwik wrote at section 2 , but x y and z is inverted.

mintar commented 5 years ago

No, it's the other way around. The imu_filter_madgwick outputs the orientation of the sensor frame relative to the earth frame. This agrees with Section 3.3 of the Madgwick report:

An estimated orientation of the sensor frame relative to the earth frame, ...

More documentation on this package: http://wiki.ros.org/imu_filter_madgwick

This driver complies with REP 145, which states:

The IMU sensor may provide a fused orientation estimate. This data is output from the driver in the form of a quaternion, which represents the orientation of the sensor frame w.r.t. the world frame.

titanproger commented 5 years ago

Ok. now i am confused. Lets look at Madgwik report section 3.3

madjwik33

and look at section 2 madjwik2

All formulas are for Quaternion describes orientation of frame (E)Earth relative to frame (S)Sensor

So never mind, to switch relativeness we only need multiply -1 to x, y, z . I am sure the code is right.

titanproger commented 5 years ago

madjwik31

yumixx commented 5 years ago

As far as I understand, the different notation in Section2 and Section3 in Madgwik report is the point as you mentioned. I used to think if the orientation of frame B relative to frame A is mentioned, it means, the frame B is achieved by a rotation from alignment with frame A, of angle theta around the axis r in frame A, and the quaternion which represents this rotation also represents orientation of frame B relative to frame A, but in Section2 it shows in another way. I've tested code in my own project according to @mintar and it's right.

titanproger commented 5 years ago

I used to think this way too. Please show me where you see another way at section 2? I double read the section and see exactly same notation.

An arbitrary orientation of frame B relative to frame A can be achieved through a rotation of angle θ around an axis Arˆ defined in frame A.

yumixx commented 5 years ago

I mean hier: madgwick3 madgwick2 If I want to use quaternion to show rotation of angle θ around an axis r defined in frame A, I would write it like this:

q = (cosθ/2, rx*sinθ/2, ry*sinθ/2, rz*sinθ/2)

and it also means the orientation of frame B relative to frame A. But in Section 2 it's exactly the conjugate.

titanproger commented 5 years ago

Thanks