Jump to content


Thermistor and gyro drift


  • Please log in to reply
7 replies to this topic

#1 Cossacs

Cossacs

    Key Member

  • Members
  • PipPipPip
  • 81 posts
  • Country: flag of Ukraine Ukraine


Posted 29 December 2011 - 08:27 AM

Hi guys, what about to add thermistor near the gyros to calculate compesation for gyro drift? I played with CC gyros and i think it could be good idea to add drift compensations using optional 3-4 temperature points calibration. It is easy to make calibration (you need only 3+ temperature points) or even we could use autocalibration with autosaving and interpolation drift/C curve.

#2 peabody124

peabody124

    Crash Dummy

  • Administrators
  • 4112 posts
  • LocationHouston, TX
  • Country: flag of United States United States


Posted 29 December 2011 - 08:40 AM

It could help.  I'm not sure which pins you could use for the ADC.

However you might want to try the accelKi values for that.  Try accelKp = 0.05 and accelKi = 0.005 and that should help track gyro bias better for X & Y.  If you aren't doing a lot of spinning around there is a yawBiasTau or something which you can try increasing as well.

#3 D-Lite

D-Lite

    Core Team

  • Members
  • PipPipPip
  • 968 posts
  • Country: flag of Germany Germany


Posted 29 December 2011 - 11:25 AM

Brian's battery module branch uses PWM input channel 5 & 6 as ADC inputs. Seems to work well. Another possibility would be to use an digital temperature sensor that can be connected via I2C. And someone brought up the idea some time ago to use the STM32's internal temperature sensor for that purpose. It fails on reporting aboslute temperature but the relative temperature accuracy should be fine and that's enough for gyro compensation I think.

#4 Crash

Crash

    Key Member

  • Members
  • PipPipPip
  • 286 posts
  • LocationVirginia
  • Country: flag of United States United States


Posted 29 December 2011 - 02:30 PM

Here is the link:

http://forums.openpi...h__1#entry21003

#5 A*Morale

A*Morale

    Core Developer

  • Members
  • PipPipPip
  • 190 posts
  • LocationRome/Italy
  • Country: flag of Italy Italy


Posted 29 December 2011 - 09:44 PM

It's a bit tricky but you may find a way to connect to pin 23 of the gyro(same pin for idg or isz), that goes to the internal temperature sensor.
here is an extract from the datasheet:

Quote

8.2.4 Temperature Sensor
A built-in Proportional-To-Absolute-Temperature (PTAT) sensor provides temperature information on
Pin 23 (PTATS). The temperature sensor output signal is analog, and has a bias of approximately
1.25V at room temperature, and increases at a rate of 4mV/ºC. The output impedance is nominally
12kΩ and is therefore not designed to drive low impedance loads. If necessary, the output can be
externally buffered with a low offset-drift buffer, and optionally a low-pass filter to minimize noise.

Edited by A*Morale, 29 December 2011 - 09:45 PM.

Alessio my Blog
Posted Image

#6 Cossacs

Cossacs

    Key Member

  • Members
  • PipPipPip
  • 81 posts
  • Country: flag of Ukraine Ukraine


Posted 30 December 2011 - 08:43 AM

It will not work to use internal CPU sensor to compensate gyro drift which depends on the external temperature. In my case CPU temp is 42С, air temperature is 20С. CPU temp will depends from CPU load, external pins connection and many other factors. I did not used absolute CPU temp sensor value to calculate drift conpensation, only delta, it does not vary linearly with changes in air temperature. I tested it for Yaw drift and it is very easy:

#if defined(PIOS_INCLUDE_ADC) && defined(PIOS_ADC_USE_TEMP_SENSOR)
	AttitudeSettingsData attitudeSettings;
	AttitudeSettingsGet(&attitudeSettings);
	float temp_voltage = 3.3 * PIOS_ADC_PinGet(0) / ((1 << 12) - 1);
	const float STM32_TEMP_V25 = 1.43; /* V */
	const float STM32_TEMP_AVG_SLOPE = 4.3; /* mV/C */
	float CPUTemp = (STM32_TEMP_V25-temp_voltage) * 1000 / STM32_TEMP_AVG_SLOPE + 25;
	attitudeRaw->gyros[ATTITUDERAW_GYROS_Z] += (attitudeSettings.GyroTempBiasZero - CPUTemp) * attitudeSettings.GyroTempBiasDelta;
#endif

1. I calibrated gyro bias and set attitudeSettings.GyroTempBiasZero = SystemStats.CPUTemp with zero drift, for example for 20.0C air temp.
2. I I found the value GyroTempBiasDelta for 18.0C air temp, something like 0.2 deg/s/C.
3. It doesn't work if i connected some external pins for 18.0C (CPU becomes warmer).

I think only external thermistor placed near gyros is the way.

View Postpeabody124, on 29 December 2011 - 08:40 AM, said:

It could help.  I'm not sure which pins you could use for the ADC.

However you might want to try the accelKi values for that.  Try accelKp = 0.05 and accelKi = 0.005 and that should help track gyro bias better for X & Y.  If you aren't doing a lot of spinning around there is a yawBiasTau or something which you can try increasing as well.

James, of course i could play with axels, but in some cases, for example for a lot of spinning or for Yaw axis axels will not help. As more precission gyro data we used, as much less help from axels we need.

I'll try to use external sensor and connect it to ADC next time.

#7 D-Lite

D-Lite

    Core Team

  • Members
  • PipPipPip
  • 968 posts
  • Country: flag of Germany Germany


Posted 30 December 2011 - 10:11 AM

View PostA*Morale, on 29 December 2011 - 09:44 PM, said:

It's a bit tricky but you may find a way to connect to pin 23 of the gyro(same pin for idg or isz), that goes to the internal temperature sensor.
here is an extract from the datasheet:

A real SMD wizard may be able to do it but personaly, I wouldn't dare :)

View PostCossacs, on 30 December 2011 - 08:43 AM, said:

It will not work to use internal CPU sensor to compensate gyro drift which depends on the external temperature. In my case CPU temp is 42С, air temperature is 20С. CPU temp will depends from CPU load, external pins connection and many other factors. I did not used absolute CPU temp sensor value to calculate drift conpensation, only delta, it does not vary linearly with changes in air temperature. I tested it for Yaw drift and it is very easy:


I haven't tried it myself but from hhrhhr's video, it looked like it works pretty well. 42C case temperature certainly is what the sensor reports, not the real temperature? I measures my CC with an infrared thermometer and the CPU is about 30C while the gyros are 28C - not so far off. I also don't understand the argument with connecting external pins - you not do that in flight :-). Nearly everything in CC happens periodically and at a high frequency so I don't see how this can cause much temperature change. This would certainly be different if we had a lot of pins driving high load and then switch them on and off once per minute or so.
About the code:


(attitudeSettings.GyroTempBiasZero - CPUTemp)



It would probably be better to use the "zero gyros while arming" feature and set the GyroTempBiasZero during that process instead of using a fixed bias. This should be more accurate in real use cases (I think).

#8 Cossacs

Cossacs

    Key Member

  • Members
  • PipPipPip
  • 81 posts
  • Country: flag of Ukraine Ukraine


Posted 30 December 2011 - 06:37 PM

Checked again, CPU temp measured with external thermometer was 38C, air temp here is 24C. Regarding to STM32F103C6 docs power consumption could be up to 3.3V/40ma = 0.13 Watts, so it should be warmer and power consumption depends from a lot of factors. CPU temp is CPU temp, it is not air or gyro temp. In some very limited cases it could compensate gyro drift, but generally it is bad idea.

View PostD-Lite, on 30 December 2011 - 10:11 AM, said:

It would probably be better to use the "zero gyros while arming" feature and set the GyroTempBiasZero during that process instead of using a fixed bias. This should be more accurate in real use cases (I think).

it doesn't really matter for testing purposes, i do the same manually.