ITG3200 library with multiple configurable full-scale ranges. Based on the Sensor_test by Bo Carøe.

Dependents:   KalmanFilter

Fork of ITG3200 by Claudio Donate

Revision:
1:1208ffc3ace9
Parent:
0:a3a0caa8e802
Child:
2:044664f2cc01
diff -r a3a0caa8e802 -r 1208ffc3ace9 ITG3200.cpp
--- a/ITG3200.cpp	Wed May 30 10:42:14 2012 +0000
+++ b/ITG3200.cpp	Wed Aug 15 01:33:01 2012 +0000
@@ -4,7 +4,7 @@
 #define I2CADR_W(ADR)           (ADR<<1&0xFE)
 #define I2CADR_R(ADR)           (ADR<<1|0x01)
 
-//Initialisieren
+//Initialization
 ITG3200::ITG3200(I2C & I2CBus_, Timer & GlobalTime_)
     : I2CBus(I2CBus_),
       GlobalTime(GlobalTime_)
@@ -12,7 +12,7 @@
 
 void ITG3200::Init()
 {
-    //Nullsetzen
+    //Zeroing
     for(int i= 0; i < 3; i++)
     {
         RawRate[i]= 0;
@@ -21,33 +21,46 @@
     }
     
        
-    //ITG3200 initialisieren
+    //ITG3200 initialization
     char tx[2];
         
-    //Full-Scale (2000deg/sec) nutzen
-    //Digitalen Low Pass Filter auf 10 Hz setzen
-    //Intern mit 1 kHz sampeln
+    //Full-scale use (250 deg/sec)
+    //Digital low-pass filter set at 10 Hz
+    //Internal resample at 1 kHz
     tx[0]= 0x16;
-    tx[1]= 0x1D;
+    tx[1]= 0x05;//0x0D(500 dg/s) - 0x1D(2000 deg/sec)
     I2CBus.write(I2CADR_W(ITG3200_ADRESS), tx, 2);
     
-    //Einen internen Taktgeber verwenden (X-Gyro)
+    //Use the internal clock from (X-gyro)
     tx[0]= 0x3E;
     tx[1]= 0x01;
     I2CBus.write(I2CADR_W(ITG3200_ADRESS), tx, 2);
     
-    //kurz warten
+    //Initial wait
     wait_ms(100);
     
-    //erste Werte abholen  
+    //Pick first value
     Update();
 }
 
+//Get Full-scale range, Low Pass Filter Bandwidth and Internal Sample Rate
+// 5: +-250deg/sec, 10Hz, 1kHz - 13: +- 500deg/sec, 10Hz, 1kHz
+char ITG3200::getInfo(void){ 
 
-//Rohdaten lesen
+    char tx = 0x16;
+    char rx;
+    
+    I2CBus.write(I2CADR_W(ITG3200_ADRESS), &tx, 1);
+    I2CBus.read (I2CADR_R(ITG3200_ADRESS), &rx, 1);
+
+    return rx;
+
+}
+
+//Read raw data
 void ITG3200::ReadRawData()
 {
-    //Drehrate aller Axen abholen
+    //Getting rotation rate of all axes
     char tx[1];
     char rx[6];
      
@@ -55,40 +68,40 @@
     I2CBus.write(I2CADR_W(ITG3200_ADRESS), tx, 1);
     I2CBus.read (I2CADR_R(ITG3200_ADRESS), rx, 6); 
     
-    //Aus den einzelnen Bytes den 16-Bit-Wert zusammenbauen
+    //Assemble the individual bytes of the 16-bit value
     RawRate[0]= rx[0]<<8|rx[1];
     RawRate[1]= rx[2]<<8|rx[3];
     RawRate[2]= rx[4]<<8|rx[5];
 }
 
 
-//Update-Methode
+//Update-Method
 void ITG3200::Update()
 {
-    //Rohdaten lesen
+    //Read raw data
     ReadRawData();    
    
-    //Drehrate berechnen
+    //Calculating rotation rate
     Rate[0]= fConvRPS * ((float)RawRate[0] + Offset[0]);
     Rate[1]= fConvRPS * ((float)RawRate[1] + Offset[1]);
     Rate[2]= fConvRPS * ((float)RawRate[2] + Offset[2]);
 }
 
-//Kalibrieren
+//Calibration
 void ITG3200::Calibrate(int ms)
 {
     float AvgCalibRate[3]= {0.0, 0.0, 0.0};    
     float AvgCalibSampels= 0.0;
     
-    //Ende der Kalibrierung in ms Millisekunden berechnen
+    //End of calibration calculated in milliseconds
     int CalibEnd= GlobalTime.read_ms() + ms;
     
     while(GlobalTime.read_ms() < CalibEnd)
     {    
-        //Rohdaten lesen
+        //Read raw data
         ReadRawData();
         
-        //Durchschnitt bilden
+        //Averaging
         AvgCalibRate[0]+= (float)RawRate[0];
         AvgCalibRate[1]+= (float)RawRate[1];
         AvgCalibRate[2]+= (float)RawRate[2];
@@ -97,8 +110,8 @@
         wait_ms(2);    
     }
     
-    //Genug Daten gesammelt, jetzt den Durchschnitt bilden
+    //Collected enough data now form the average
     Offset[0]= -(AvgCalibRate[0] / AvgCalibSampels);
     Offset[1]= -(AvgCalibRate[1] / AvgCalibSampels);
     Offset[2]= -(AvgCalibRate[2] / AvgCalibSampels);
-}
+}
\ No newline at end of file