gz-sensors icon indicating copy to clipboard operation
gz-sensors copied to clipboard

Magnetometer not taking into account the initial global heading

Open 5p00kk opened this issue 10 months ago • 1 comments

The magnetometer sensor/system ignores the initial heading set from spherical coordinates.

As seen in the lines below the world frame magnetic field vector is rotated from the world frame into local frame, however the spherical coordinates also hold information about the heading of the world coordinate system in regards to NED/ENU. The initial heading is not taken into account:

https://github.com/gazebosim/gz-sensors/blob/27239b4ac9877d87273a18010a307172899dd7a6/src/MagnetometerSensor.cc#L162C3-L166C1

This is incorrect and not consistent with the approach taken for the IMU sensor, where the system checks the initial heading and passes it to the sensor to take it into account. The issue makes it impossible to sync align and magnetometer sensors if the world coordinate heading is non-zero: https://github.com/gazebosim/gz-sim/blob/c158287d6f8556112d86d6e4188c39784364bd40/src/systems/imu/Imu.cc#L228C2-L248C4

It seems like an issue that would require changes in both: gz-sim (system) and gz-sensor (sensor) side if following the approach taken for the IMU sensor.

5p00kk avatar Apr 09 '24 07:04 5p00kk

Thanks @5p00kk. I've added the "help wanted" tag on this. Let me know if you'd like to work on it.

azeey avatar Jul 15 '24 16:07 azeey