calib tutorial for giroscope

Dependencies:   X_NUCLEO_IKS01A2 mbed

Fork of AccpiuGiroscopio_timer by duckietownhsunina

Files at this revision

API Documentation at this revision

Comitter:
vidica94
Date:
Mon Feb 20 09:40:43 2017 +0000
Parent:
16:553a1c68d606
Commit message:
calibration tutorial

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 553a1c68d606 -r 9d70e41ec8bc main.cpp
--- a/main.cpp	Thu Feb 16 11:23:33 2017 +0000
+++ b/main.cpp	Mon Feb 20 09:40:43 2017 +0000
@@ -1,3 +1,14 @@
+/* this program acquires the acceleration and the angular speed  on the 3 axes
+the angular speed acquired in mdps( milli degree por second) is converrted in angular position 
+using a simple algoritm of  discret integration.
+To have clean and right position it's necessary to calibrate the giroscope.
+To calibrate we read row position( comment the correctionoperation  of off and slope at line 97 and 106)
+at specific and known angles and using a linear fit algoritm it's possible to know the 
+slope and the offset that have to be correc.
+The angles used are 90°,180°270°,360° because they are the easiest to reach whitout specific tools.
+after the calibration it's possible uncomment line 97 and 106
+WARNING:offset and slope depends by the dt of integration !!
+*/
 
 /* Includes */
 #include "mbed.h"
@@ -7,7 +18,7 @@
 static X_NUCLEO_IKS01A2 *mems_expansion_board = X_NUCLEO_IKS01A2::Instance(D14, D15, D4, D5);
 
 
-#define  sens 70 // sensibilità presa dal datasheet per il fondo scala utilizzato 
+#define  sens 70 // sensibility for the range that  we are using  
 
 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
 Timer t;
@@ -35,13 +46,14 @@
   printf("\r\n--- Starting new run ---\r\n");
   acc_gyro->ReadID(&id);
   printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);
-  // attendo l' inzializzazione
-  wait(1.5);    
-  
-  // effettuo una prima acquisizione del giroscopio per ottenere l'offset delle velocità angolari
+  // wait for inizialization 
+  wait(1.5); 
+     
+  //first acquisition to know the offset of the angular speeds
  acc_gyro->Get_G_Axes(mdps);   
  printf("LSM6DSL [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);
  
+ //print the offset
  for(int i=0;i<3;i++){ 
 off[i]=mdps[i];}
 
@@ -51,52 +63,50 @@
     
     printf("\r\n");
 
-    acc_gyro->Get_X_Axes(acc);
+    acc_gyro->Get_X_Axes(acc);// acquire the acceleration 
   
-    printf("LSM6DSL [acc/mg]:      %6ld, %6ld, %6ld\r\n", acc[0], acc[1], acc[2]);
-    
+    printf("LSM6DSL [acc/mg]:      %6ld, %6ld, %6ld\r\n", acc[0], acc[1], acc[2]); //print the acceleration
+    // stop the timer used to estimate the dt(=time between  2 acquisitions) used in the integration
  t.stop();
-   dt= t.read();
-       //printf("The time taken was %d milliseconds\n", t.read_ms());
+   dt= t.read(); 
+    printf("The time taken was %d milliseconds\n", t.read_ms());// this prinft it's not necessary it's just to know the time of integration 
         
-        
+        // acquire the angular speeds in mdps
     acc_gyro->Get_G_Axes(mdps);
-    
+    // reset the timer and restart it
     t.reset();
     t.start();
     
-    printf("LSM6DSLrow [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);
+    printf("LSM6DSLrow [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);// print the angular speeds before the offset correction  
     
-    // sottraggo l'offset
+    // ssubtract the offset at the angulas speeds
 for(int i=0;i<3;i++)
 {mdps[i]=mdps[i]-off[i];}
-       printf("LSM6DSLfine [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);
-
-    //wait_ms(1);
+       printf("LSM6DSLfine [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);// print the angular speeds after the offset correction 
     
     
-    // ricavo il parziale dalla velocità angolare
+
     
     for(int i=0;i<3;i++)
 {
-// passo da mdps a dpLSB
+// convert the angular speeds from  mdps to dpLSB
 
     parziale[i]=(mdps[i]*sens)/1000;
     
-// levo la correzione per poter sommare i dati parziali off 19 coeff 2.84
+// delete the coerrection of offset and slope to integrate beacuse they are correction on the angle not on  the angular speed 
 angolo[i]=(angolo[i]-(-3.19211))/0.0140888;
-// moltiplico per il dt 
+// multiply for dt 
     parziale[i]*=(dt);
     
-   if (mdps[i]>140 ||mdps[i]<-140)// ci si puo mettere anche 70 come soglia non cambia molto
-    angolo[i] += parziale[i];     // integro 
+   if (mdps[i]>70 ||mdps[i]<-70)// 
+    angolo[i] += parziale[i];     // summ to ultimate the integration 
     
-// correggo offset e guadagno che ho ricavato da una "taratura" (ricavo la best fit line  )
+// correction of offset and  slope obtained aftera a "taratura" ( best fit line  )
   
    angolo[i]=(angolo[i]*0.0140888)+(-3.19211);
 }
 
 
-    printf("angolo  [gyro/d]:   %6f, %6f, %6f\r\n", angolo[0], angolo[1], angolo[2]);//angolo
+    printf("angolo  [gyro/d]:   %6f, %6f, %6f\r\n", angolo[0], angolo[1], angolo[2]);//print angoles
   }
 }