Commits

Jody McAdams committed 2bdfebf

small temperature update

Comments (0)

Files changed (1)

Sensors/Gyro/Gyro.ino

 // L3G4200D data sheet: http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00265057.pdf
 
 #include <Wire.h>
+#include <MathUtil.h>
 
 #define ENABLE_CALIBRATION true
 
+//Temporarily made up numbers
+//TODO: do some measurements to figure these numbers out
+const float temperature_Min = 35.0f;
+const float temperature_Max = 100.0f;
+
 float calibrationTimer = 2.0f; //seconds
 
 #if ENABLE_CALIBRATION
 
-float calibrationScale = 32.0f; //hacky way to adjust the calibration effect (32 works well for me)
+const float calibrationScale = 32.0f; //hacky way to adjust the calibration effect (32 works well for me)
 
 enum CalibrationState
 {
 void getGyroValues(){
 
   tVal = readRegister(L3G4200D_Address, 0x26);
-  //NOTE: this seems wrong currently as the number goes up when I put the gyro in the freezer
-  temperature = 35.0f + ((tVal + 13200.0f)/280.0f);
+  
+  //Convert temp reading into a 0 to 1 float value
+  float tempT = 1.0f - ((float)tVal+128.0f)/255.0f;
+  
+  //Interpolate from min to max temperature based on tempT
+  temperature = Lerp(temperature_Min,temperature_Max,tempT);
   
   byte xMSB = readRegister(L3G4200D_Address, 0x29);
   byte xLSB = readRegister(L3G4200D_Address, 0x28);