Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of Giroscopio_timer_fast by
Revision 19:ba121767de70, committed 2017-03-07
- Comitter:
- vidica94
- Date:
- Tue Mar 07 14:45:59 2017 +0000
- Parent:
- 18:da0744a1b128
- Commit message:
- versione veloce
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r da0744a1b128 -r ba121767de70 main.cpp
--- a/main.cpp Sat Feb 18 14:05:50 2017 +0000
+++ b/main.cpp Tue Mar 07 14:45:59 2017 +0000
@@ -14,86 +14,86 @@
Timer t;
/* Simple main function */
-int main() {
- uint8_t id;
- int32_t mdps[3];
- int32_t acc[3];
- int32_t off[3];
- float parziale[3];
- float angolo[3];
- float dt=0;
-
-
-parziale[2]=0;
+int main()
+{
+ uint8_t id;
+ int32_t mdps[3];
+ int32_t acc[3];
+ int32_t off[3];
+ float parziale[3];
+ float angolo[3];
+ float dt=0;
+
+
+ parziale[2]=0;
+
+
+ angolo [2]=0;
+ /* Enable sensors */
+
+
+ acc_gyro->Enable_G();
+
+ pc.printf("\r\n--- Starting new run ---\r\n");
+ acc_gyro->ReadID(&id);
+ pc.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
+ acc_gyro->Get_G_Axes(mdps);
+ pc.printf("LSM6DSL [gyro/mdps]: %6ld\r\n", mdps[2]);
+
-
-angolo [2]=0;
- /* Enable all sensors */
-
- acc_gyro->Enable_X();
- acc_gyro->Enable_G();
-
- pc.printf("\r\n--- Starting new run ---\r\n");
- acc_gyro->ReadID(&id);
- pc.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
- acc_gyro->Get_G_Axes(mdps);
- pc.printf("LSM6DSL [gyro/mdps]: %6ld\r\n", mdps[2]);
-
-
-off[2]=mdps[2];
+ off[2]=mdps[2];
+
+ pc.printf("off [gyro/mdps]: %6ld\r\n", off[2]);
+
+ while(1) {
+
+ pc.printf("\r\n");
+
+
+ t.stop();
+ dt= t.read();
+ pc.printf("The time taken was %d milliseconds\n", t.read_ms());
+ t.reset();
+ acc_gyro->Get_G_Axes(mdps);
- pc.printf("off [gyro/mdps]: %6ld\r\n", off[2]);
-
- while(1) {
-
- pc.printf("\r\n");
-
-
- t.stop();
- dt= t.read();
- pc.printf("The time taken was %d milliseconds\n", t.read_ms());
-
- acc_gyro->Get_G_Axes(mdps);
-
- t.reset();
- t.start();
-
- //pc.printf("LSM6DSLrow [gyro/mdps]: %6ld\r\n", mdps[2]);
-
- // sottraggo l'offset
+ t.start();
+
+ //pc.printf("LSM6DSLrow [gyro/mdps]: %6ld\r\n", mdps[2]);
+
+ // sottraggo l'offset
-mdps[2]=mdps[2]-off[2];
- pc.printf("LSM6DSLfine [gyro/mdps]: %6ld\r\n",mdps[2]);
+ mdps[2]=mdps[2]-off[2];
+ pc.printf("LSM6DSLfine [gyro/mdps]: %6ld\r\n",mdps[2]);
+
+ //wait_ms(1);
- //wait_ms(1);
-
-
- // ricavo il parziale dalla velocità angolare
-
-
+
+ // ricavo il parziale dalla velocità angolare
+
+
// passo da mdps a dpLSB
- parziale[2]=(mdps[2]*sens)/1000;
-
+ parziale[2]=(mdps[2]*sens)/1000;
+
// levo la correzione per poter sommare i dati parziali off 19 coeff 2.84
-angolo[2]=(angolo[2]-(0.724005))/0.0226195;
-// moltiplico per il dt
- parziale[2]*=(dt);
-
- if (mdps[2]>70 ||mdps[2]<-70)// ci si puo mettere anche 70 come soglia non cambia molto
- angolo[2] += parziale[2]; // integro
-
+ angolo[2]=(angolo[2]-(0.724005))/0.0226195;
+// moltiplico per il dt
+ parziale[2]*=(dt);
+
+ if (mdps[2]>70 ||mdps[2]<-70)// ci si puo mettere anche 70 come soglia non cambia molto
+ angolo[2] += parziale[2]; // integro
+
// correggo offset e guadagno che ho ricavato da una "taratura" (ricavo la best fit line )
-
- angolo[2]=(angolo[2]*0.0226195)+(0.724005);
+
+ angolo[2]=(angolo[2]*0.0226195)+(0.724005);
- pc.printf("angolo [gyro/d]: %6f\r\n", angolo[2]);//angolo
- }
+ pc.printf("angolo [gyro/d]: %6f\r\n", angolo[2]);//angolo
+ }
}
