gazebosim / gz-sensors

Provides numerous sensor models designed to generate realistic data from simulation environments.
https://gazebosim.org
Apache License 2.0
65 stars 58 forks source link

Magnetometer not taking into account the initial global heading #425

Open 5p00kk opened 7 months ago

5p00kk commented 7 months ago

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.

azeey commented 4 months ago

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