Electrical – IMU axis rotation, calculate values with respect to Earth plane

accelerometerembeddedgyroscope

I'm building a project that uses an IMU (Inertial Measurement Unit). The project involves the device to be mounted inside a vehicle and I should provide the acceleration, angular velocity and Euler angles of the vehicle (and not the device).
After a few reading I understand that I must rotate the 3D axis of acceleration from the device frame (reference frame) into the Earth frame. To do this I can use quaternion rotation as described here (SO Question). But what about angular velocity? Can the gyroscope axis rotations also be rotated using quaternions?
And as I'm a bit confused, once I rotate the axes, I can calculate the Euler angles from the quaternions. Am I right?
I have come across many algorithms that calculate the quaterions (Madwick's Algo). After the calculation of the quaternions can I use "SO question"'s approach to rotate the device frame into Earth frame?

In brief:
I need to get accelerometer, gyroscope, Euler angle data for the earth plane. I'm a bit confused and so this question is just to understand the best approach for this problem.

Best Answer

The IMU should have the same axes for the accelerometer, gyroscope and whatever else there is inside. Just look it up in the datasheet.

My approach to this would be to first make sure that the axes of your IMU are alligned with the axes of your vehicle since the IMU can only measure the velocity, euler angles and so on of itself.

To get the euler angles from your IMU you can use this:

https://robotics.stackexchange.com/questions/4511/euler-angles-from-9dof-imu

assuming your IMU has a Magnetometer. Otherwise there are many tutorials on how to get the roll, pitch and yaw angle from IMUs:

https://engineering.stackexchange.com/questions/3348/calculating-pitch-yaw-and-roll-from-mag-acc-and-gyro-data

After this, you already have the euler angles you need and you can rotate the vectors you want (acceleration and angular velocity) into the earth frame. This can be done with quaternions as you mentioned. For this there are also a lot of tutorials online. The madgwick paper where you got the algorithm from has a good explanation for this problem.

So to clarify: You calculate the orientation of your reference frame relative to your world frame (Euler angles) with your IMU. Then you can rotate whatever vectors your IMU gives you (acceleration, angular velocity, ...) from your reference frame into the earth frame and use them (calculate trajectory, compensate gravity, calculate movement etc.)