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

Onboard Temperature Calibration [WIP] #6413

Closed
wants to merge 5 commits into from

Conversation

bugobliterator
Copy link
Contributor

@bugobliterator bugobliterator commented Jan 21, 2017

Temperature Calibration Scheme for calibrating sensors. The module will be running onboard and processing data realtime.

TODOs:

Parameters for post and pre calibration stage not yet saved, add mechanism to store them.
Currently only gyro, include accel and baro.
Integrate with Events interface

Current Results:

Gyro Temperature Cal Temperature vs Gyro Bias plots (Temperature is on reference offset scale):
gyro0_x
gyro0_y
gyro0_z

tempcal start inside nsh will kick off temperature cal.

* @returns multiplied matrix i.e. A*B
*/

float *mat_mul(float *A, float *B, uint8_t n)
Copy link
Member

Choose a reason for hiding this comment

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

If we compare this to https://github.com/PX4/Matrix, what parts of this standalone Matrix implementation can be replaced by the standard? I would much prefer to extend Matrix with whatever is missing and not have any math classes in here.

Copy link
Member

@jgoppert jgoppert left a comment

Choose a reason for hiding this comment

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

Yeah this is all supported by matrix. see the temp cal doc for the math. All you need is pseudoinverse. I can add a convenience method if you need. This code is very clean so of you see anything in matrix you can improve, let me know/ submit a PR. This math only supports a standard y = f (T), if you look at the temp cal document the math is much more general, could add more info like gyro data. I will try to sketch up the math for this in matrix.

@jgoppert
Copy link
Member

Is anyone online to give me an overview of the online temp sampling strategy?

@bugobliterator
Copy link
Contributor Author

bugobliterator commented Jan 21, 2017 via email

@jgoppert
Copy link
Member

jgoppert commented Jan 21, 2017

@bugobliterator and I came up with a short term plan:

  1. Switch math over to matrix. He had it using matrix in the beginning but was unsure about the output and switched to known working code he had. If we can find any errors in the matrix inverse in Matrix through this process we will fix it.
  2. Implement interval averaging for data collection to avoid over weighting one section of the fit.
  3. We've determined that the algorithm is a recursive least squares solution, and I checked his derivation here: https://github.com/jgoppert/iekf_analysis/blob/master/Temperature%20Calibration.ipynb

Fit interface:

  1. User enters start deg C, the fit starts when start temp bin is reached
  2. Users enters stop deg C and the fit stops when stop bin is reached.
  3. User enters number of bins for fit or it is hard-coded to 100 etc.. The bins are allocated, and then initialized with the first value.

When a sample is received, the bin is updated. We could update by storing the number of samples and sum and calculating the mean, or by using a low pass filter. The disadvantage of the man is that the value will become very static if we use this for online adaptation. The disadvantage to the low pass filter is that we will need to initialize it when we get the first sample and set the cutoff frequency very low so it might get stuck on the initial value. Maybe when initializing the bin we wait for 10 samples or so and initialize with the mean of those 10 samples.

Long term support for online adaptation:
Fixed bins are created and each bin is initialized to pre-calibrated data. While the user flies, they are updating the temperature bin they are in. Temperature cal is updated using this data at start or at fixed time intervals. Some consideration for the gyro bias estimation in the IEKF/ EKF2 is needed here, maybe already addressed in temp calibration document.

@bugobliterator
Copy link
Contributor Author

bugobliterator commented Jan 22, 2017

@jgoppert @LorenzMeier I have changed to using Matrix functions in polyfit and converted it into a template with changeable order of polynomial, hence it can be used for anything relating to polynomial/curve/spline fitting. So do you think its a good idea to move it to the matrix library as well for anybody to use?

@LorenzMeier
Copy link
Member

Ok. Please integrate with this PR next: #6396 and enable the full operation. I would propose that:

  • user sends a temperature calibration command
  • calibrator stores an "enabled" param in memory
  • user cold-soaks the board
  • calibrator starts taking samples 2 seconds after boot if enabled param is set (we need eventually motion detection)
  • calibrator runs until reaching steady-state temperature (e.g. one minute within 0.5 deg or so)

This is a bit different from min and max as we likely need to work with what the user gives us (best effort). It would also be good to be able to set min and max as additional gates - if they are not reached, the calibration will be considered invalid.

We would set those to relatively small values though (e.g. -5 to 35) by default to users can reach them.

@jgoppert
Copy link
Member

@bugobliterator yes, I think we should add it to Matrix. Let's pull it in after we get this temp call stuff wrapped up.

@LorenzMeier
Copy link
Member

@bugobliterator Where is this standing?

@bugobliterator
Copy link
Contributor Author

Discussion and PR moved to #6425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants