Answers checklist.
What is the expected behavior?
The icm20498 magnetometer should return values in a +/- 4900 uT range as indicated by the datasheet.
What is the actual behavior?
The magnetometer returns absurdly high values.
ex: -188374.5781 x 18856.1875 y 190086.9531 z
Steps to reproduce.
Call read_magnetometer(ec) from icm20948.cpp component
Build or installation Logs.
More Information.
It seems like the scaling for the magnetometer in the icm20948 component is applied incorrectly at line 699 in icm20948.cpp:
template <espp::icm20948::Interface I>
Icm20948<I>::Value Icm20948<I>::read_magnetometer(std::error_code &ec) {
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
RawValue raw = get_magnetometer_raw(ec);
if (ec) {
return {0.0f, 0.0f, 0.0f};
}
float sensitivity = get_magnetometer_sensitivity();
Value value = {
static_cast<float>(raw.x) / sensitivity,
static_cast<float>(raw.y) / sensitivity,
static_cast<float>(raw.z) / sensitivity,
};
// update values
mag_values_ = value;
return value;
}
get_magnetometer_sensitivity() returns the scaling factor in uT/LSB so should be applied by multiplying not dividing.
Changing this locally returns values in the expected range.
Answers checklist.
What is the expected behavior?
The icm20498 magnetometer should return values in a +/- 4900 uT range as indicated by the datasheet.
What is the actual behavior?
The magnetometer returns absurdly high values.
ex:
-188374.5781 x 18856.1875 y 190086.9531 zSteps to reproduce.
Call
read_magnetometer(ec)from icm20948.cpp componentBuild or installation Logs.
More Information.
It seems like the scaling for the magnetometer in the icm20948 component is applied incorrectly at line 699 in icm20948.cpp:
get_magnetometer_sensitivity()returns the scaling factor in uT/LSB so should be applied by multiplying not dividing.Changing this locally returns values in the expected range.