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:
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.
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.