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 AccpiuGiroscopio_timer by
Diff: main.cpp
- Revision:
- 17:a8d332cc6cad
- Parent:
- 16:553a1c68d606
diff -r 553a1c68d606 -r a8d332cc6cad main.cpp
--- a/main.cpp Thu Feb 16 11:23:33 2017 +0000
+++ b/main.cpp Fri Feb 17 10:03:58 2017 +0000
@@ -6,6 +6,7 @@
/* Instantiate the expansion board */
static X_NUCLEO_IKS01A2 *mems_expansion_board = X_NUCLEO_IKS01A2::Instance(D14, D15, D4, D5);
+Serial pc(SERIAL_TX, SERIAL_RX);
#define sens 70 // sensibilità presa dal datasheet per il fondo scala utilizzato
@@ -22,42 +23,39 @@
float angolo[3];
float dt=0;
- for(int i=0;i<3;i++)
-{parziale[i]=0;}
+
+parziale[2]=0;
- for(int i=0;i<3;i++)
-{angolo [i]=0;}
+
+angolo [2]=0;
/* Enable all sensors */
acc_gyro->Enable_X();
acc_gyro->Enable_G();
- printf("\r\n--- Starting new run ---\r\n");
+ pc.printf("\r\n--- Starting new run ---\r\n");
acc_gyro->ReadID(&id);
- printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", 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);
- printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);
+ pc.printf("LSM6DSL [gyro/mdps]: %6ld\r\n", mdps[2]);
+
- for(int i=0;i<3;i++){
-off[i]=mdps[i];}
+off[2]=mdps[2];
- printf("off [gyro/mdps]: %6ld, %6ld, %6ld\r\n", off[0], off[1], off[2]);
+ pc.printf("off [gyro/mdps]: %6ld\r\n", off[2]);
while(1) {
- printf("\r\n");
-
- acc_gyro->Get_X_Axes(acc);
+ pc.printf("\r\n");
- printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", acc[0], acc[1], acc[2]);
t.stop();
dt= t.read();
- //printf("The time taken was %d milliseconds\n", t.read_ms());
+ pc.printf("The time taken was %d milliseconds\n", t.read_ms());
acc_gyro->Get_G_Axes(mdps);
@@ -65,38 +63,37 @@
t.reset();
t.start();
- printf("LSM6DSLrow [gyro/mdps]: %6ld, %6ld, %6ld\r\n", mdps[0], mdps[1], mdps[2]);
+ //pc.printf("LSM6DSLrow [gyro/mdps]: %6ld\r\n", mdps[2]);
// sottraggo l'offset
-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]);
+
+mdps[2]=mdps[2]-off[2];
+ pc.printf("LSM6DSLfine [gyro/mdps]: %6ld\r\n",mdps[2]);
//wait_ms(1);
// ricavo il parziale dalla velocità angolare
- for(int i=0;i<3;i++)
-{
+
// passo da mdps a dpLSB
- parziale[i]=(mdps[i]*sens)/1000;
+ parziale[2]=(mdps[2]*sens)/1000;
// levo la correzione per poter sommare i dati parziali off 19 coeff 2.84
-angolo[i]=(angolo[i]-(-3.19211))/0.0140888;
+angolo[2]=(angolo[2]-(-3.19211))/0.0140888;
// moltiplico per il dt
- parziale[i]*=(dt);
+ parziale[2]*=(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[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[i]=(angolo[i]*0.0140888)+(-3.19211);
-}
+ angolo[2]=(angolo[2]*0.0140888)+(-3.19211);
+
- printf("angolo [gyro/d]: %6f, %6f, %6f\r\n", angolo[0], angolo[1], angolo[2]);//angolo
+ pc.printf("angolo [gyro/d]: %6f\r\n", angolo[2]);//angolo
}
}
