Temperature compensation for gyroscope drift L3GD20

I encountered the problem of increasing drift at rest.

At an ambient temperature of 25 degrees, the raw values of the drift along the axes are as follows:

x 3
y 0
z 5

in terms of angular speeds, at 2000 range (gyro_Deg = gyro_xRaw * 0.07; // deg/s)

x 0.21 dps
y 0.0 dps
z 0.35 dps

When the ambient temperature decreases, then at -9 degrees the drift values along the axes are as follows:

x -22
y 13
z 57

in terms of angular speeds, at 2000 range (gyro_Deg = gyro_xRaw * 0.07; // deg/s)

x 1.54 dps
y 0.91 dps
z 3.99 dps

Moreover, my board is not oriented horizontally, as usual, but vertically - the Y axis points upward.

In the screenshots, the green line is the X-axis, the light blue line is the Y-axis, the blue line is the Z-axis, and the orange line is the temperature.

Temp.: +25

Temp.: -9

The Y-axis remains almost at the center(about zero), and the Z-axis goes up, and the X-axis goes down.
As the temperature decreases, not only the median part of the angular velocity shifts, but also the drift amplitude increases.
In general, the zero offset has two components - the initial zero offset and the zero drift. The physical cause of zero drift is a change in the size of the silicon elements and pressure inside the sensor case due to temperature changes
I can’t imagine how to compensate for this.
UPD: Looks like there is a problem with the sensor.
Now I conducted a temperature experiment with another BMI160 sensor and the drift and median component are more stable with decreasing and increasing temperatures.
Apparently the sensor software from Bosch Sensortec contains temperature correction.

Temp.: +26

Temp.: -10


At sub-zero temperatures there is even less noise and drift.

You have already computed the correct values for the device and the values when the temperature changes. Put the two in an array and when the temp is near a table temp, adjust the sensor value by the value in the array.

As far a axes, make the "Y" axis of the board your "Z" axis.

2 Likes

Measure the gyro offsets at several different temperatures, fit curves to the data, and use the curves to estimate offsets at any temperature within the range.

2 Likes

Measuring the values gyro offsets is the simplest thing.
Correcting the drift when it is linear is also not difficult.
Using the measured points, I wrote a function to extrapolate values over other ranges, and it even worked.

float interpolate(float x1, float y1, float x2, float y2, float x) {
return y1 + (x - x1) * (y2 - y1) / (x2 - x1);
}

void calculateGyroValues(float temperature, float& Gx, float& Gy, float& Gz, float Gx_meas, float Gy_meas, float Gz_meas) {
if (temperature >= -10 && temperature <= 25) {
	if (temperature == -10) {
	Gx -= -22;
	Gy -= 10;
	Gz -= 54;
	} else if (temperature == 25) {
	Gx -= -9;
	Gy -= 1;
	Gz -= 7;
	} else {
	float x1 = -10;
	float y1_Gx = -22;
	float y1_Gy = 10;
	float y1_Gz = 54;

	float x2 = 25;
	float y2_Gx = -9;
	float y2_Gy = 1;
	float y2_Gz = 7;

	Gx = Gx_meas - interpolate(x1, y1_Gx, x2, y2_Gx, temperature);
	Gy = Gy_meas - interpolate(x1, y1_Gy, x2, y2_Gy, temperature);
	Gz = Gz_meas - interpolate(x1, y1_Gz, x2, y2_Gz, temperature);
	}
} else {
        // Error output if temperature is out of range
        Serial.println("Error: incorrect temperature!");
}

But, as it turns out, the LSM303 and L3GD20 sensors are still good and their temperature drift can be corrected.

But when I started testing the LSM6DS3 sensor, it seemed to me that it was miracles and magic.

Everything started out fine, as the temperature dropped, the sensor slightly changed the initial offset (median component) and stayed there from +25 degrees to -13 degrees.
Miracles began when the sensor was placed from a cold environment into a room environment, the drift suddenly jumped upward, and all the axes seemed to go crazy.
Cooling is slower than heating, and due to the heating of the sensor from minus to room temperature, an avalanche-like drift occurred, which could only be established when the sensor temperature reached +23 ... +25
Moreover, I measured the temperature with a third-party BMP280 sensor, standing next to the LSM6DS3 gyroscope sensors, and I also get the temperature from the LSM6DS3 sensor itself.
But if at +24 degrees, the temperatures from the LSM6DS3 and BMP280 sensors are almost the same, then at 0 degrees, the difference becomes significant and the LSM6DS3 temperature sensor begins to critically lie with its readings.
Moreover, the temperature from the LSM6DS3 sensor drops much faster.
When heating occurs, the temperature from the LSM6DS3 sensor begins to rise much faster and is probably also the problem with such an “avalanche-like” drift of the angular velocity of the LSM6DS3 sensor.
So try to compensate for such an extraordinary drift, here interpolation won’t help, here you need to use Lagrange polynomials, the only thing I know about is the name.

The LSM6DS3 sensor was very surprising, because the manifestation of drift is not like other sensors; with this sensor, drift begins when heated.
If other sensors behave more or less the same during cooling and heating, then LSM6DS3 is simply the king of unpredictability!

In the code where I define the orientation, the Y axis faces up and is the Z axis.

Non-comensated drift

Here are the results of the correction function using the interpolation method.
I separated the axes to make clear screenshots.



This is the simplest case of temperature drift of offset and zero.
Of course, the compensation function does its job, and the output angular velocities of the gyroscopes at rest are much stable and close to zero, while their linearity is observed, in contrast to the drifting angular velocity values.

But it also does not fully cope with some drift emissions, in the range from +6 to + 12 degrees when heated.
It’s as if it is necessary to introduce a second correction function for the temperature range from +14 to +18 as this temperature increases.
Probably the problem of such emissions and a surge in increased drift is associated with a sharper change in temperature when the sensor is heated than when cooled.
I'm afraid that drift can be compensated using the Lagrange polynomial

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.