mavros icon indicating copy to clipboard operation
mavros copied to clipboard

Possible error in imu.cpp plugin code

Open Alvar007 opened this issue 1 year ago • 2 comments

Hello, I think there may be an error in the code that handles the scaled IMU message. In the mavlink website you can see that the scaled IMU message contains the magnetic field data in mgauss. But the code for the plugin uses a coeff of 1000.0 and it's called MILLIT_TO_TESLA, as it if was interpreting that the data was in mtesla instead of mgauss.

So naturally when I check the topic on ROS I get my magnetic field data in mgauss multiplied by 1000.0, which is clearly wrong as it's supposed to show in Tesla according to the ROS documentation.

Also I should mention that in the same code the publish_imu_data_raw function is used for the scaled IMU instead of the publish_imu_data one that is also there. So when I check my topics I have to go to /mavros/imu/data_raw when it should be /mavros/imu/data.

If this is indeed an error I would appreciate that it would get fixed in the source as we are trying to avoid to create our own package for the project I'm working on.

Thanks in advance for your consideration.

Alvar007 avatar Apr 22 '23 00:04 Alvar007

Second this, it appears to be converting the wrong way.

venabled avatar Mar 14 '24 14:03 venabled

Perhaps that's some ancient leftover or early RAW_IMU usage. Should be corrected to MILLIG_TO_TESLA = 1e-7.

On today's code APM presents mgauss:

  • https://github.com/ArduPilot/ardupilot/blob/533eb73622b11bc0d4841ae5268c05079bcb33dc/libraries/GCS_MAVLink/GCS_Common.cpp#L2098
  • https://github.com/ArduPilot/ardupilot/blob/533eb73622b11bc0d4841ae5268c05079bcb33dc/libraries/AP_Compass/AP_Compass.h#L158

As for use publish_imu_data_raw - it's correct. Your imu data should be combined from ATTITUDE/ATTITUDE_QUATERNION and *_IMU.

You're free to open a MR.

vooon avatar Mar 15 '24 17:03 vooon