# IMU and Magnetometer Conventions in ROS: Sanity check

I am trying to use a system that integrates one IMU and one Magnetometer for an outdoors vehicle, but I am struggling to fully understand some of the conventions used by ROS. I would like for this to be a sanity check to make sure that the assumptions I have are correct and to, hopefully, help any future users.

As far as I understand, ROS and robot_localisation (r_l) expects data to be in the East-North-Up (ENU) frame of reference, as shown in the following figure:

Lets assume that our sensor is in a flat neutral position with the X axis pointing East. In this case the previous diagram indicates that:

• X points towards East
• Y points towards North
• Z points towards Up.

As for orientation, the sensor should indicate:

• roll = 0
• pitch = 0
• yaw = 0

From this neutral position the following motions should generate the specified information:

• If the sensor were to rotate from X to Y, that should generate a positive reading in yaw. From Y to X should generate a negative reading.
• If the sensors were to rotate from X to Z that should generate a positive reading in pitch. From Z to X should generate a negative reading.
• If the sensor were to rotate from Y to Z that should generate a positive reading in roll. From Z to Y should generate a negative reading.

As for the accelerometer, it should indicate:

• x = 0
• y = 0
• z = +9.81 m/s^2

And the following motions should register the specified information:

• If the sensor is displaced in the X axis (towards East) then it will register a +X acceleration.
• If the sensor is displaced in the Y axis (towards North) then it will register a +Y acceleration.
• If the sensor is displaced in the Z axis (towards UP) then it will register a +Z acceleration, This would be in addition to acceleration due to gravity, so if I accelerated at 1 m/s^2 straight up, the IMU should read +10.81 m/s^2. More information here.

As for the gyroscope, it should indicate:

• x = 0

• y = 0

• z = 0

• If the sensor were to rotate from X to Y, that should generate a positive reading in the Z axis. From Y to X should generate a negative reading.

• If the sensors were to rotate from X to Z that should generate a positive reading in the y components. From Z to X should generate a negative reading.

• If the sensor were to rotate from Y to Z that should generate a positive reading in the X component. From Z to Y should generate a negative reading.

As for the magnetometer.

Since it is pointing East, the sensor should read, in XYZ, (0, +0.00005, -z). The Z component is used to indicate the hemisphere, so negative is north hemisphere, while position is south hemisphere.

If the sensors was rotated so that X is now facing North, then the sensor should read, in XYZ, (+0.00005, 0, -z). Again, the Z component is used to indicate the hemisphere. More information here.

Are these assumptions correct?

If the sensors were to rotate from X to Z that should generate a positive reading in pitch. From Z to X should generate a negative reading.

If the sensors were to rotate from X to Z that should generate a positive reading in the y components. From Z to X should generate a negative reading.

These are backwards. The coordinate frame is right-handed, so you need to follow the right hand rule: point your thumb in the direction of the Y axis. Now close your other fingers. That should be positive pitch (downward direction).

The magnetometer should conform to the coordinate frame. If you rotate the sensor counter-clockwise, the Z component should increase. If you rotate it clockwise, the Z component should decrease. navsat_transform_node assumes this standard, but the sensor doesn't have to read 0 when facing geographic east. Most IMUs report 0 yaw at magnetic north, not geographic east. So you need two parameters: the magnetic declination for your location (this will let navsat_transform_node see 0 at geographic north) and the yaw offset (this will let navsat_transform_node see 0 at geographic east). navsat_transform_node has parameters for both for this reason. Or you can make the sensor output the right values and ignore those parameters.

https://docs.ros.org/en/noetic/api/robot_localization/html/integrating_gps.html