con timer
Dependencies: X_NUCLEO_IKS01A2 mbed
Fork of HelloWorld_IKS01A2 by
main.cpp@14:de30b189c5ec, 2017-02-10 (annotated)
- Committer:
- vidica94
- Date:
- Fri Feb 10 18:52:39 2017 +0000
- Revision:
- 14:de30b189c5ec
- Parent:
- 13:2e809b3e6ea9
- Child:
- 15:25999e71b22d
acquisizioni con accelerometro e giroscopio
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cparata | 0:69566eea0fba | 1 | |
cparata | 0:69566eea0fba | 2 | /* Includes */ |
cparata | 0:69566eea0fba | 3 | #include "mbed.h" |
cparata | 0:69566eea0fba | 4 | #include "x_nucleo_iks01a2.h" |
cparata | 0:69566eea0fba | 5 | |
cparata | 0:69566eea0fba | 6 | /* Instantiate the expansion board */ |
cparata | 8:8f495e604424 | 7 | static X_NUCLEO_IKS01A2 *mems_expansion_board = X_NUCLEO_IKS01A2::Instance(D14, D15, D4, D5); |
cparata | 0:69566eea0fba | 8 | |
cparata | 0:69566eea0fba | 9 | |
vidica94 | 13:2e809b3e6ea9 | 10 | #define sens 70 |
cparata | 0:69566eea0fba | 11 | |
vidica94 | 13:2e809b3e6ea9 | 12 | static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; |
cparata | 0:69566eea0fba | 13 | |
cparata | 0:69566eea0fba | 14 | |
cparata | 0:69566eea0fba | 15 | /* Simple main function */ |
cparata | 0:69566eea0fba | 16 | int main() { |
cparata | 0:69566eea0fba | 17 | uint8_t id; |
cparata | 0:69566eea0fba | 18 | int32_t axes[3]; |
vidica94 | 13:2e809b3e6ea9 | 19 | int32_t off[3]; |
vidica94 | 13:2e809b3e6ea9 | 20 | float parziale[3]; |
vidica94 | 13:2e809b3e6ea9 | 21 | float finale[3]; |
vidica94 | 13:2e809b3e6ea9 | 22 | int32_t k=0; |
vidica94 | 13:2e809b3e6ea9 | 23 | for(int i=0;i<3;i++) |
vidica94 | 13:2e809b3e6ea9 | 24 | {parziale[i]=0;} |
vidica94 | 13:2e809b3e6ea9 | 25 | |
vidica94 | 13:2e809b3e6ea9 | 26 | for(int i=0;i<3;i++) |
vidica94 | 13:2e809b3e6ea9 | 27 | {finale [i]=0;} |
cparata | 0:69566eea0fba | 28 | /* Enable all sensors */ |
vidica94 | 13:2e809b3e6ea9 | 29 | |
cparata | 0:69566eea0fba | 30 | acc_gyro->Enable_X(); |
cparata | 0:69566eea0fba | 31 | acc_gyro->Enable_G(); |
cparata | 0:69566eea0fba | 32 | |
cparata | 0:69566eea0fba | 33 | printf("\r\n--- Starting new run ---\r\n"); |
cparata | 0:69566eea0fba | 34 | acc_gyro->ReadID(&id); |
cparata | 0:69566eea0fba | 35 | printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); |
vidica94 | 13:2e809b3e6ea9 | 36 | wait(1.5); |
vidica94 | 13:2e809b3e6ea9 | 37 | acc_gyro->Get_G_Axes(axes); |
vidica94 | 13:2e809b3e6ea9 | 38 | printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); |
vidica94 | 13:2e809b3e6ea9 | 39 | for(int i=0;i<3;i++){ |
vidica94 | 13:2e809b3e6ea9 | 40 | off[i]=axes[i];} |
vidica94 | 13:2e809b3e6ea9 | 41 | printf("off [gyro/mdps]: %6ld, %6ld, %6ld\r\n", off[0], off[1], off[2]); |
cparata | 0:69566eea0fba | 42 | while(1) { |
cparata | 0:69566eea0fba | 43 | printf("\r\n"); |
cparata | 0:69566eea0fba | 44 | |
cparata | 0:69566eea0fba | 45 | acc_gyro->Get_X_Axes(axes); |
cparata | 0:69566eea0fba | 46 | printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); |
cparata | 0:69566eea0fba | 47 | |
cparata | 0:69566eea0fba | 48 | acc_gyro->Get_G_Axes(axes); |
vidica94 | 13:2e809b3e6ea9 | 49 | printf("LSM6DSLrow [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); |
vidica94 | 13:2e809b3e6ea9 | 50 | for(int i=0;i<3;i++) |
vidica94 | 13:2e809b3e6ea9 | 51 | {axes[i]=axes[i]-off[i];} |
vidica94 | 13:2e809b3e6ea9 | 52 | printf("LSM6DSLfine [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); |
vidica94 | 13:2e809b3e6ea9 | 53 | k=k+1; |
vidica94 | 14:de30b189c5ec | 54 | wait_m(1); |
vidica94 | 13:2e809b3e6ea9 | 55 | |
vidica94 | 13:2e809b3e6ea9 | 56 | // ricavo l'parziale dalla velocità angolare |
vidica94 | 13:2e809b3e6ea9 | 57 | |
vidica94 | 13:2e809b3e6ea9 | 58 | for(int i=0;i<3;i++) |
vidica94 | 14:de30b189c5ec | 59 | { |
vidica94 | 14:de30b189c5ec | 60 | parziale[i]=(axes[i]*sens)/1000; |
cparata | 0:69566eea0fba | 61 | |
vidica94 | 14:de30b189c5ec | 62 | |
vidica94 | 14:de30b189c5ec | 63 | parziale[i]/= 1000; |
vidica94 | 14:de30b189c5ec | 64 | if (axes[i]>150 ||axes[i]<-150) |
vidica94 | 13:2e809b3e6ea9 | 65 | finale[i] += parziale[i]; |
vidica94 | 14:de30b189c5ec | 66 | |
vidica94 | 13:2e809b3e6ea9 | 67 | } |
vidica94 | 13:2e809b3e6ea9 | 68 | printf("finale [gyro/d]: %6f, %6f, %6f\r\n", finale[0], finale[1], finale[2]);//angolo |
cparata | 0:69566eea0fba | 69 | } |
cparata | 0:69566eea0fba | 70 | } |