Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix temperature readout for Invensense IMUs #9054

Closed
wants to merge 2 commits into from
Closed

Conversation

mhkabir
Copy link
Member

@mhkabir mhkabir commented Mar 10, 2018

This fixes the temperature readout for the MPU/ICM IMUs. The sensitivity parameters were originally incorrect. This is needed for enabling the Pixhawk 2.1 IMU heater and holding a temperature set-point.

@mhkabir
Copy link
Member Author

mhkabir commented Mar 11, 2018

TODO : other drivers also seem to have incorrect parameters.

@LorenzMeier
Copy link
Member

Generally a great initiative, but we need to take into consideration what the side effect will be to boards that are already calibrated.

Copy link
Contributor

@ksschwabe ksschwabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhkabir : I think your temp sensitivity changes aren't correct. Please see my individual line comments.

//
// Sensitivity (in degC/LSB) is from the Invensense datasheet for the specific sensor
// Zero offset (in degC) varies from part to part, and this value is a good default
_last_temperature = (report.temp) / 340.0f + 21.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do these numbers come from? Is the temp sensitivity not 333.87LSB/degC?
mpu9250_temp_sensitivity

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you're right. Thanks!

if (is_icm_device()) { // if it is an ICM20608
_last_temperature = (report.temp) / 326.8f + 25.0f;

} else { // If it is an MPU6000
_last_temperature = (report.temp) / 361.0f + 35.0f;
_last_temperature = (report.temp) / 340.0f + 36.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the temp offset not 35 degC for the MPU6000?

mpu6000_temp_sensitivity

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you are indeed right. I believe I had been looking at an older version of the datasheet. Will fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know whether this sensitivity is related to a particular MPU6000 silicon revision (as in we will have to handle the temp conversion based on the silicon revision)? Or is it that there was a typo in the previous data sheets and they corrected it in the later version.

I am also not sure if I have the latest datasheets. These were the ones that I downloaded from the Invensense website, so as long as those are the most recent, then it should be alright.

// We calculate sensor temperature as :
// temperature_real = temperature_raw * temperature_sensitivity + zero_offset
//
// Sensitivity (in degC/LSB) is from the Invensense datasheet for the specific sensor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the units of sensitivity not be LSB/degC?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the datasheet, yes. However, I defined it here as 1/(LSB/degC). Will make it clearer. Thanks.

@mhkabir mhkabir force-pushed the pr-invensense-temp branch from b0a4b57 to 7f0becb Compare March 13, 2018 15:16
@mhkabir
Copy link
Member Author

mhkabir commented Mar 13, 2018

@ksschwabe All addressed! Thanks for the corrections!

@mhkabir
Copy link
Member Author

mhkabir commented Mar 15, 2018

@LorenzMeier @dagar Options for merging this? People with current tempcal will need to recalibrate. Wish we had some form of parameter versioning so that we could reset the TC_* parameters from older versions and force a recalibration.

@dagar
Copy link
Member

dagar commented Mar 15, 2018

This is a tough one, especially because of how annoying it will be to redo. I suppose we could explain the correction to apply per param with release notes. I'm not sure that anyone would actually do that, but somehow it still seems better than force resetting these valuable parameters.

@dagar
Copy link
Member

dagar commented Mar 15, 2018

This isn't great, but I have 2 ideas for making the transition acceptable.

  1. python script that reads your ulog, and based on PX4 version and existing TC parameters will shift the curve and provide updated TC parameters. We can note this in the release.

  2. We could add a new param directly in mpu6000 and mpu9250 to handle this change. Anyone with affected TC parameters could fall back to using the existing incorrect temperature calculation, but get a mavlink error message (and logged) every startup. Doing a fresh TC would set the new parameter, use the correct temperature, and give no warning. We could drop it after one full release cycle (v1.8.0 -> v1.9.0).

Typically I don't think we should be trying to handle every migration, but in this case performing TC yet again is time consuming and becomes an expensive mistake.

Thoughts?

@dagar dagar added the bug label Mar 15, 2018
@dagar dagar requested a review from thomasgubler March 15, 2018 17:40
@dagar dagar added this to the Release v1.8.0 milestone Mar 15, 2018
@priseborough
Copy link
Contributor

Is the effect on temperature an offset only or offset plus scale factor? If only an offset then only the *_TREF parameters for that sensor need to be adjusted by the amount of the temperature shift.

@mhkabir
Copy link
Member Author

mhkabir commented Mar 16, 2018 via email

@mhkabir
Copy link
Member Author

mhkabir commented May 14, 2018

@dagar Any updates here?

@mhkabir mhkabir mentioned this pull request May 14, 2018
@dagar dagar added the devcall label May 14, 2018
@dagar
Copy link
Member

dagar commented May 14, 2018

At an absolute minimum we'd need to ensure incorrect temperature calibrations aren't used. Changing the device id might be an option.

@mcsauder
Copy link
Contributor

@bkueng, @priseborough,
I am interested in gathering your feedback on @mhkabir's merge request as well, (as you are primary authors/maintainers in the thermal calibration routines). This PR, if merged, does necessitate a recalibration, however the bad data currently being propagated by the incorrect values is actively impacting current users as well. Any additional thoughts on how this could proceed?

Thanks!

-Mark

@priseborough
Copy link
Contributor

My view in the short term is that we give it a new device ID and and provide users with a python script they can run that reads in the polynomial coefficients and recalculates them so that the correction is the same as suggested by @dagar

However something to consider is that if the user is calibrating the sensor, then it makes more sense to apply the calibration to the data before the manufacturers compensation is applied. This is because the compensation curve provided by the manufacturer has steps in the slope which makes curve fitting harder and is likely responsible for the higher order polynomial required.

I would like to see a comparison of the fit achieved with and without the manufacturers compensation.

@proficnc
Copy link

Device ID and Bus?
I agree with Paul, dump the manufacturer calibration and do it all in PX4

@mhkabir
Copy link
Member Author

mhkabir commented May 15, 2018

Do the IMUs even have a manufacturer compensation?

@mcsauder
Copy link
Contributor

mcsauder commented May 15, 2018

The manufacturer's don't provide compensation, they only provide the conversion for the ADC counts LSB to deg C... Unfortunately, the initial implementation of the driver was incorrect because the data sheet was incorrect, (@mhkabir wasn't the only one affected by data sheet revisions. :) ).

In this case, I know the bug fix has a negative impact, but it feels like the bug should still simply be squashed and that it somehow feels wrong to correct the driver bug by giving it the device a new ID.

Is there any way to quantify how many users this would impact and if there is a way to coordinate a fix with them?

@dagar
Copy link
Member

dagar commented May 15, 2018

Do the IMUs even have a manufacturer compensation?

Not that I've seen in our currently supported IMUs, but it wouldn't surprise me. I believe Paul's referring to the ms5611 (applies to the ms5525 as well). #9267

@mcsauder
Copy link
Contributor

As far as I can see reading through the temp calibration code, each routine is querying the respective (correct) temperature sensor for the sensor being calibrated, so although the mpu9250 accel/gyro would require recal, for factory calibrated baro/dynamic pressure sensors this pull request would have no impact.

(Are there any imu's or magnetometers similar to the mpu9250/mpu6500 that have a factory cal?)

@mcsauder
Copy link
Contributor

mcsauder commented May 16, 2018

5 days enough to resolve this issue? Let's set a goal. :)

@LorenzMeier
Copy link
Member

@mcsauder That's fair - we are better off setting expectations and timelines.

@mcsauder
Copy link
Contributor

mcsauder commented May 19, 2018

Hi Everyone,

I think I have a proposal. The 2.0.0 release appears to be coming soon, and the implication for Major version increments in the Major.Minor.Patch version methodology is the suggestion that Major version increments may/will cause backward compatibility breakage... (e.g. Python2 to Python3.)

Can we introduce this fix into the 2.0.0 release understanding that it causes breakage, (and perhaps other changes will cause breakage), and everyone can understand the implications?

Also, are there other backward compatibility issues that could be slated for 2.0.0?

Let me know your thoughts.

-Mark

@dagar dagar removed the devcall label May 23, 2018
@dagar dagar added this to the Release v2.0.0 milestone May 23, 2018
@mhkabir mhkabir force-pushed the pr-invensense-temp branch from 7f0becb to 2b241de Compare June 5, 2018 04:12
@mcsauder
Copy link
Contributor

@mhkabir, @dagar, do you think we should revisit this PR and get this bugfix slated into an upcoming release?

@dakejahl
Copy link
Contributor

@mcsauder
Copy link
Contributor

thanks @dakejahl !

@mcsauder
Copy link
Contributor

mcsauder commented Jan 14, 2019

@dakejahl, it looks like the mpu6000 fix from this PR hasn't been applied yet. (https://github.com/PX4/Firmware/blob/29a0950753854223d144de0b7335bbcbe40ea1d4/src/drivers/imu/mpu6000/mpu6000.cpp#L1804)

@mhkabir, would you be interested in rebasing/updating this PR? Let me know if I can help.

@mhkabir
Copy link
Member Author

mhkabir commented Jan 28, 2019

On master.

@mhkabir mhkabir closed this Jan 28, 2019
@LorenzMeier LorenzMeier deleted the pr-invensense-temp branch January 18, 2021 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants