
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
Revision 1:e1f3b4b8b99b, committed 2016-02-13
- Comitter:
- flowh
- Date:
- Sat Feb 13 14:29:40 2016 +0000
- Parent:
- 0:0861bf46efe4
- Child:
- 2:f53340e49cc0
- Commit message:
- Version 2.1 ; log acc, omega, compass and 5 AI
Changed in this revision
--- a/DataFile/DataFile.cpp Fri Feb 12 20:54:38 2016 +0000 +++ b/DataFile/DataFile.cpp Sat Feb 13 14:29:40 2016 +0000 @@ -30,7 +30,7 @@ } cfg.getValue(keyIndex, &value[0], sizeof(value)); Index=atoi(value); - printf("Index=%d\r\n", Index); + //printf("Index=%d\r\n", Index); //crèe le non de fichier à créer // printf("OpenDataFile\n\r"); @@ -41,21 +41,21 @@ strcat (DataFileName,NumFich); // printf("DataFileName=%s\n\r",DataFileName); strcat (DataFileName,".txt"); - printf("DataFileName=%s\n\r",DataFileName); + printf("New Data file opened : %s\n\r",DataFileName); //met à jour l'index itoa(Index+1,NumFich); - printf("Prochain fichier a ecrire=%s\n\r",NumFich); + //printf("Prochain fichier a ecrire=%s\n\r",NumFich); cfg.setValue(keyIndex, NumFich); cfg.write("/sd/index.txt","index",cfg.DOS); //ouvre le fichier fp= fopen(DataFileName, "a"); // Open "xxx.txt" on the local file system for writing - fprintf(fp, "Gx\tGy\tGz\tWx\tWy\tWz\tMx\tMy\tMz\n"); + fprintf(fp, "Gx\tGy\tGz\tWx\tWy\tWz\tMx\tMy\tMz\tI0\tAI1\tAI2\tAI3\tAI4\n"); Opened=1; - printf("DataFile opened\n\r"); + // printf("DataFile opened\n\r"); } @@ -76,7 +76,7 @@ if (Opened==1) { - printf("sauvegarde en cours\r\n"); + // printf("sauvegarde en cours\r\n"); apMesure->Save(fp); } }
--- a/DefinitionIO.h Fri Feb 12 20:54:38 2016 +0000 +++ b/DefinitionIO.h Sat Feb 13 14:29:40 2016 +0000 @@ -3,66 +3,101 @@ #include "SDFileSystem.h" #include "COMPASS_DISCO_L476VG.h" +#include "GYRO_DISCO_L476VG.h" +#define NbDAC 5 +#define SavePeriod 0.1 // 1/frequency of log : default 0.1 (tested OK at 0.01 (100Hz)) DigitalOut LedEnreg(LED1); DigitalIn InterEnreg(PD_0,PullDown); +Ticker TickUpdate; +COMPASS_DISCO_L476VG compass ; //declaration must be before SDFile system declaration +GYRO_DISCO_L476VG gyro; -COMPASS_DISCO_L476VG compass ; + + +AnalogIn AIn0(PA_0); +AnalogIn AIn1(PA_1); +AnalogIn AIn2(PA_2); +AnalogIn AIn3(PA_3); +AnalogIn AIn4(PA_5); + +AnalogIn * TabpAIn[NbDAC]= {&AIn0,&AIn1,&AIn2,&AIn3,&AIn4}; +//AnalogIn * AIn [5]; //Create an SDFileSystem object - SDFileSystem sd(PE_15, PE_14, PE_13, PE_12, "sd"); - tDataFile DataFile; - bool EnregistrementEnCours; - - //COMPASS_DISCO_L476VG compass ;//=new COMPASS_DISCO_L476VG(); - - tMesure Mesures(&compass); +SDFileSystem sd(PE_15, PE_14, PE_13, PE_12, "sd"); + +tDataFile DataFile; //used to manage data savings +bool EnregistrementEnCours; -void Init() -{ - printf("avant Compass created\n"); - //pcompass =new COMPASS_DISCO_L476VG(); - printf("Compass created\n"); - // delete pcompass; - EnregistrementEnCours=false; - LedEnreg=0; - printf("Compass started\n"); - - //Mount the filesystem - sd.mount(); - printf("mounted\n\r"); -} +tMesure Mesures(&compass,&gyro,TabpAIn); + + +//------------------------ +// manage log switch void CheckEnreg() { if (InterEnreg.read()==1) { - //printf("InterEnreg\n\r"); if (!EnregistrementEnCours) { EnregistrementEnCours=true; DataFile.New(); - printf("enregistrement started\n\r"); + printf("log started\n\r"); } else { DataFile.SaveMesures(&Mesures); - //printf("Enregistrement\n\r"); } LedEnreg=!LedEnreg; } else - { - //printf("Not InterEnreg\n\r"); - if (EnregistrementEnCours) + { + if (EnregistrementEnCours) { EnregistrementEnCours=false; DataFile.Close(); - printf("enregistrement stopped\n\r"); + printf("Log stopped\n\r"); } LedEnreg=0; } +} + +/*********************** +Main function in loop +************************/ +void Update() +{ + CheckEnreg(); + Mesures.Update(); +} + +//------------------------ +// initialization of logger + +void Init() +{ + TickUpdate.attach(&Update, SavePeriod); //starting the infinit loop + printf("\n\r"); + printf("Moth logger V2.0\n\r"); + printf("----------------\n\r\n\r"); + + EnregistrementEnCours=false; + LedEnreg=0; + + printf("sensors started\n\r"); + + //Mount the filesystem + sd.mount(); + printf("File system mounted\n\r"); + + /* AIn[0]=&AIn0; + AIn[1]=&AIn1; + AIn[2]=&AIn2; + AIn[3]=&AIn3; + AIn[4]=&AIn4;*/ } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GYRO_DISCO_L476VG.lib Sat Feb 13 14:29:40 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/GYRO_DISCO_L476VG/#504155ed5862
--- a/Mesure/Mesure.h Fri Feb 12 20:54:38 2016 +0000 +++ b/Mesure/Mesure.h Sat Feb 13 14:29:40 2016 +0000 @@ -1,33 +1,48 @@ #include "mbed.h" #include "COMPASS_DISCO_L476VG.h" +#include "GYRO_DISCO_L476VG.h" #ifndef MESURE_H #define MESURE_H +#define NbDAC 5 +/*--------------------------------------------- +Manage acquisitions + Compass + Acceleration + Gyroscope + + !!! calibration to be defined in the constructor !!! - +*/ class tMesure { public: -tMesure(COMPASS_DISCO_L476VG * apCompass); +tMesure(COMPASS_DISCO_L476VG * apCompass, GYRO_DISCO_L476VG * apGyro, AnalogIn * apAIn[NbDAC]); void Update(); void Save(FILE * apFile); private: COMPASS_DISCO_L476VG * pCompass; + GYRO_DISCO_L476VG * pGyro; double Mag[3]; double Acc[3]; - + double Omega[3]; + double AIO[NbDAC]; double OffsetMag[3]; double OffsetAcc[3]; + double OffsetOmega[3]; + double OffsetAIO[NbDAC]; double GainMag[3]; double GainAcc[3]; + double GainOmega[3]; + double GainAIO[NbDAC]; - + AnalogIn * pAIn[NbDAC]; }; #endif \ No newline at end of file
--- a/Mesure/mesure.cpp Fri Feb 12 20:54:38 2016 +0000 +++ b/Mesure/mesure.cpp Sat Feb 13 14:29:40 2016 +0000 @@ -1,8 +1,16 @@ #include "Mesure.h" -tMesure::tMesure(COMPASS_DISCO_L476VG * apCompass) +tMesure::tMesure(COMPASS_DISCO_L476VG * apCompass, GYRO_DISCO_L476VG * apGyro,AnalogIn * apAIn[NbDAC]) { pCompass=apCompass; + pGyro=apGyro; + for(int i=0; i<NbDAC;i++) + { + pAIn[i]=apAIn[i]; + } + +//Offset and gains to be updated after calibration + GainMag[0]=1.0; GainMag[1]=1.0; GainMag[2]=1.0; @@ -10,12 +18,27 @@ OffsetMag[1]=0.0; OffsetMag[2]=0.0; - GainAcc[0]=1.0; - GainAcc[1]=1.0; - GainAcc[2]=1.0; - OffsetAcc[0]=0.0; - OffsetAcc[1]=0.0; - OffsetAcc[2]=0.0; + + GainAcc[0]=0.0005995; + GainAcc[1]=0.0005934; + GainAcc[2]=0.0006065; + OffsetAcc[0]=-0.666; + OffsetAcc[1]=-0.164; + OffsetAcc[2]=0.177; + + GainOmega[0]=1.0; + GainOmega[1]=1.0; + GainOmega[2]=1.0; + OffsetOmega[0]=-316.0; + OffsetOmega[1]=1196.0; + OffsetOmega[2]=385.0; + + for (int i=0;i<NbDAC;i++) + { + GainAIO[i]=3.3; + OffsetAIO[i]=0.0; + } + } @@ -23,26 +46,48 @@ { int16_t lMag[3]; int16_t lAcc[3]; + float lGyroBuffer[3]; + pCompass->AccGetXYZ(lAcc); pCompass->MagGetXYZ(lMag); + pGyro->GetXYZ(lGyroBuffer); + //calibration for (int i = 0;i<3;i++) { Mag[i]= (lMag[i]*GainMag[i])+ OffsetMag[i]; Acc[i]= (lAcc[i]*GainAcc[i])+ OffsetAcc[i]; + Omega[i]= (lGyroBuffer[i]*GainOmega[i])+ OffsetOmega[i]; + } + + for(int i=0; i<NbDAC;i++) + { + AIO[i]=(pAIn[i]->read()*GainAIO[i])+OffsetAIO[i]; } } void tMesure::Save(FILE * apFile) { + fprintf(apFile,"%f\t",Acc[0]); fprintf(apFile,"%f\t",Acc[1]); fprintf(apFile,"%f\t",Acc[2]); + fprintf(apFile,"%f\t",Omega[0]); + fprintf(apFile,"%f\t",Omega[1]); + fprintf(apFile,"%f\t",Omega[2]); + fprintf(apFile,"%f\t",Mag[0]); fprintf(apFile,"%f\t",Mag[1]); fprintf(apFile,"%f\t",Mag[2]); + for (int i=0; i<NbDAC ; i++) + { + fprintf(apFile,"%f\t",AIO[i]); + } + + + fprintf(apFile,"\n"); } \ No newline at end of file
--- a/main.cpp Fri Feb 12 20:54:38 2016 +0000 +++ b/main.cpp Sat Feb 13 14:29:40 2016 +0000 @@ -1,35 +1,53 @@ + +/* -------------------------------------------------------- + + MothLogger + +Version 2.0 February 12th 2016 Florent HADDAD + + +Save on SD card + Acceleration, + Gyroscope, + Compass + 5 Analog input (PA_0..PA_5 except PA_4) + +SdCard connected on : + PE_12 to PE_15 for SPI + 3.3V + +Start/Stop switch between 3V and PD_0 + +Green led blinks during log + +tested up to 100Hz acquisition frequency +For any unknown reason, may need to be downloaded twice to run properly ! + + +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +-------------------------------------------------------*/ + + #include "mbed.h" - #include "DefinitionIO.h" - - int main() { - Init(); - - - - - while(1) { - Mesures.Update(); + Init(); //initialization of I/O + Mesures.Update(); //required to start safely IOs - CheckEnreg(); - // Read acceleremoter and magnetometer values - - // Display values - /* printf("Acc X = %d\n", lAcc[0]); - printf("Acc Y = %d\n", lAcc[1]); - printf("Acc Z = %d\n", lAcc[2]); - printf("Mag X = %d\n", lMag[0]); - printf("Mag Y = %d\n", lMag[1]); - printf("Mag Z = %d\n", lMag[2]); - printf("\n\r"); */ - - - wait(1); + + while(1) + { + //main loop is actually performed in a ticker defined in "DefinitionIO/Init()" } -} +} \ No newline at end of file