Skip to content

Magnetometer system publishes field strength in incorrect units #2312

Open
@gilborty

Description

@gilborty

Environment

  • OS Version:
$ lsb_release -a                 
LSB Version:	core-11.1.0ubuntu4-noarch:security-11.1.0ubuntu4-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.3 LTS
Release:	22.04
Codename:	jammy
---
$ uname -a                
Linux <> 6.5.0-17-generic #17~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 16 14:32:32 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
  • Source or binary build?
Binary
---
$ gz sim --version                                         
Gazebo Sim, version 8.0.0
Copyright (C) 2018 Open Source Robotics Foundation.
Released under the Apache 2.0 License.
---
$ ls /usr/include/gz
cmake3   fuel_tools9  launch7  msgs10    plugin2     sdformat14  sim8         utils2
common5  gui8         math7    physics7  rendering8  sensors8    transport13

Description

Expected behavior

According to the gz::msgs::Magnetometer proto message, the field_tesla is reported in units of Tesla.

However, consider the following minimal world file (see attached) using the Bay Area, California as the origin for the spherical_coordinates.

Using this website, I would expect the local magnetic field to be something like this:

Horizontal Intensity North Comp East Comp Vertical Comp Total Field
23,071.9 nT 22,485.8 nT 5,167.1 nT 41,506.4 nT 47,487.8 nT
2.3072×10^-5 T 2.2486×10^-5 T 5.1671×10^-6 T 4.15064×10^-5 T 4.74878×10^-5 T

However, when I start up the simulation and echo the /magnetometer topic

gz sim simple_mag.world
gz topic -e -t /magnetometer

I get the following:

header {
  stamp {
    sec: 67
    nsec: 230000000
  }
  data {
    key: "frame_id"
    value: "sensors_box::link::magnetometer"
  }
  data {
    key: "seq"
    value: "86"
  }
}
field_tesla {
  x: -0.32109555007132251
  y: -0.14981328784703124
  z: 0.40261160054926087
}

which is a few orders of magnitude off from what I was expecting.

I did some digging, and it looks like the tables that were used to estimate the field vector were added to gz-sim in this PR which actually use the field strength table from the old PX4 Sim.

However, I believe this line is incorrectly calculating the magnetic field in Tesla as I would expect the field to be measured in. Instead, it calculates it as a gauss and never converts it back to teslas.

I can demonstrate that this is the case using the previous message.

field_tesla {
  x: -0.32109555007132251
  y: -0.14981328784703124
  z: 0.40261160054926087 <--- Assume we are looking at the Z component only for this
}
---
Assume that it is actually gauss
0.40261160054926087 g = 4.0261160054926087×10^-5 T
4.0261160054926087×10^-5 T = 40261.160054926087 nT
40,261.2 nT ~= 41,506.4 nT (vertical component from NOAA website)

Steps to reproduce

  1. gz sim simple_mag.world
  2. gz topic -e -t /magnetometer
  3. Observe a very high magnetic field strength (assuming field_tesla is in Teslas)

Unless I am mistaken, I think this is the case. My recommendation would be to fix the conversion in systems/magnetometer/Magnetometer.cc since we assume that the noise in the SDF file is measured in teslas. I think people would be okay with reporting it in tesla, not nT, even though that is what most sensors are reporting.

As an aside, I'm actually surprised this seems like it was incorrect all the way back to the PX4 days. Was it originally reporting the field as Gauss? It isn't clear from the message signature

I can put up a PR if you'd all like and agree with the approach. Please let me know if I missed anything.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions