Log measurements on SD card added on DISCO-L476VG board acceleration, omega, compass & 5 Analog values

Dependencies:   BSP_DISCO_L476VG COMPASS_DISCO_L476VG ConfigFile GYRO_DISCO_L476VG SDFileSystem mbed

Committer:
flowh
Date:
Sat Feb 13 14:29:40 2016 +0000
Revision:
1:e1f3b4b8b99b
Parent:
0:0861bf46efe4
Version  2.1 ; log acc, omega, compass and 5 AI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
flowh 0:0861bf46efe4 1 #include "Mesure.h"
flowh 0:0861bf46efe4 2
flowh 1:e1f3b4b8b99b 3 tMesure::tMesure(COMPASS_DISCO_L476VG * apCompass, GYRO_DISCO_L476VG * apGyro,AnalogIn * apAIn[NbDAC])
flowh 0:0861bf46efe4 4 {
flowh 0:0861bf46efe4 5 pCompass=apCompass;
flowh 1:e1f3b4b8b99b 6 pGyro=apGyro;
flowh 1:e1f3b4b8b99b 7 for(int i=0; i<NbDAC;i++)
flowh 1:e1f3b4b8b99b 8 {
flowh 1:e1f3b4b8b99b 9 pAIn[i]=apAIn[i];
flowh 1:e1f3b4b8b99b 10 }
flowh 1:e1f3b4b8b99b 11
flowh 1:e1f3b4b8b99b 12 //Offset and gains to be updated after calibration
flowh 1:e1f3b4b8b99b 13
flowh 0:0861bf46efe4 14 GainMag[0]=1.0;
flowh 0:0861bf46efe4 15 GainMag[1]=1.0;
flowh 0:0861bf46efe4 16 GainMag[2]=1.0;
flowh 0:0861bf46efe4 17 OffsetMag[0]=0.0;
flowh 0:0861bf46efe4 18 OffsetMag[1]=0.0;
flowh 0:0861bf46efe4 19 OffsetMag[2]=0.0;
flowh 0:0861bf46efe4 20
flowh 1:e1f3b4b8b99b 21
flowh 1:e1f3b4b8b99b 22 GainAcc[0]=0.0005995;
flowh 1:e1f3b4b8b99b 23 GainAcc[1]=0.0005934;
flowh 1:e1f3b4b8b99b 24 GainAcc[2]=0.0006065;
flowh 1:e1f3b4b8b99b 25 OffsetAcc[0]=-0.666;
flowh 1:e1f3b4b8b99b 26 OffsetAcc[1]=-0.164;
flowh 1:e1f3b4b8b99b 27 OffsetAcc[2]=0.177;
flowh 1:e1f3b4b8b99b 28
flowh 1:e1f3b4b8b99b 29 GainOmega[0]=1.0;
flowh 1:e1f3b4b8b99b 30 GainOmega[1]=1.0;
flowh 1:e1f3b4b8b99b 31 GainOmega[2]=1.0;
flowh 1:e1f3b4b8b99b 32 OffsetOmega[0]=-316.0;
flowh 1:e1f3b4b8b99b 33 OffsetOmega[1]=1196.0;
flowh 1:e1f3b4b8b99b 34 OffsetOmega[2]=385.0;
flowh 1:e1f3b4b8b99b 35
flowh 1:e1f3b4b8b99b 36 for (int i=0;i<NbDAC;i++)
flowh 1:e1f3b4b8b99b 37 {
flowh 1:e1f3b4b8b99b 38 GainAIO[i]=3.3;
flowh 1:e1f3b4b8b99b 39 OffsetAIO[i]=0.0;
flowh 1:e1f3b4b8b99b 40 }
flowh 1:e1f3b4b8b99b 41
flowh 0:0861bf46efe4 42
flowh 0:0861bf46efe4 43 }
flowh 0:0861bf46efe4 44
flowh 0:0861bf46efe4 45 void tMesure::Update()
flowh 0:0861bf46efe4 46 {
flowh 0:0861bf46efe4 47 int16_t lMag[3];
flowh 0:0861bf46efe4 48 int16_t lAcc[3];
flowh 1:e1f3b4b8b99b 49 float lGyroBuffer[3];
flowh 1:e1f3b4b8b99b 50
flowh 0:0861bf46efe4 51 pCompass->AccGetXYZ(lAcc);
flowh 0:0861bf46efe4 52 pCompass->MagGetXYZ(lMag);
flowh 1:e1f3b4b8b99b 53 pGyro->GetXYZ(lGyroBuffer);
flowh 0:0861bf46efe4 54
flowh 1:e1f3b4b8b99b 55 //calibration
flowh 0:0861bf46efe4 56 for (int i = 0;i<3;i++)
flowh 0:0861bf46efe4 57 {
flowh 0:0861bf46efe4 58 Mag[i]= (lMag[i]*GainMag[i])+ OffsetMag[i];
flowh 0:0861bf46efe4 59 Acc[i]= (lAcc[i]*GainAcc[i])+ OffsetAcc[i];
flowh 1:e1f3b4b8b99b 60 Omega[i]= (lGyroBuffer[i]*GainOmega[i])+ OffsetOmega[i];
flowh 1:e1f3b4b8b99b 61 }
flowh 1:e1f3b4b8b99b 62
flowh 1:e1f3b4b8b99b 63 for(int i=0; i<NbDAC;i++)
flowh 1:e1f3b4b8b99b 64 {
flowh 1:e1f3b4b8b99b 65 AIO[i]=(pAIn[i]->read()*GainAIO[i])+OffsetAIO[i];
flowh 0:0861bf46efe4 66 }
flowh 0:0861bf46efe4 67 }
flowh 0:0861bf46efe4 68
flowh 0:0861bf46efe4 69 void tMesure::Save(FILE * apFile)
flowh 0:0861bf46efe4 70 {
flowh 1:e1f3b4b8b99b 71
flowh 0:0861bf46efe4 72 fprintf(apFile,"%f\t",Acc[0]);
flowh 0:0861bf46efe4 73 fprintf(apFile,"%f\t",Acc[1]);
flowh 0:0861bf46efe4 74 fprintf(apFile,"%f\t",Acc[2]);
flowh 0:0861bf46efe4 75
flowh 1:e1f3b4b8b99b 76 fprintf(apFile,"%f\t",Omega[0]);
flowh 1:e1f3b4b8b99b 77 fprintf(apFile,"%f\t",Omega[1]);
flowh 1:e1f3b4b8b99b 78 fprintf(apFile,"%f\t",Omega[2]);
flowh 1:e1f3b4b8b99b 79
flowh 0:0861bf46efe4 80 fprintf(apFile,"%f\t",Mag[0]);
flowh 0:0861bf46efe4 81 fprintf(apFile,"%f\t",Mag[1]);
flowh 0:0861bf46efe4 82 fprintf(apFile,"%f\t",Mag[2]);
flowh 0:0861bf46efe4 83
flowh 1:e1f3b4b8b99b 84 for (int i=0; i<NbDAC ; i++)
flowh 1:e1f3b4b8b99b 85 {
flowh 1:e1f3b4b8b99b 86 fprintf(apFile,"%f\t",AIO[i]);
flowh 1:e1f3b4b8b99b 87 }
flowh 1:e1f3b4b8b99b 88
flowh 1:e1f3b4b8b99b 89
flowh 1:e1f3b4b8b99b 90
flowh 0:0861bf46efe4 91 fprintf(apFile,"\n");
flowh 0:0861bf46efe4 92
flowh 0:0861bf46efe4 93 }