Compare commits

..

2 commits

Author SHA1 Message Date
Aurélien Gauthier 6b9de5f457 rebase merge 2022-06-27 16:39:21 +02:00
Aurélien Gauthier 70e01e558f create readme.md and fix issue on recovery data array from file and adaptative array size frome the number of captors 2022-06-27 16:35:30 +02:00
7 changed files with 167 additions and 31 deletions

View file

@ -19,9 +19,7 @@ void averageCalculation(long **p, double averageArray[])
averageArray[i] = 0; averageArray[i] = 0;
while (j < nRowRawData) while (j < nRowRawData)
{ {
//printf("pij = %ld\n", p[i][j]);
averageArray[i - 1] += (double)p[i][j]; averageArray[i - 1] += (double)p[i][j];
// printf("%f , %ld\n", averageArray[i], p[i][j]);
j++; j++;
} }
averageArray[i] /= nRowRawData; averageArray[i] /= nRowRawData;

View file

@ -1,37 +1,47 @@
#include "fileGestion.h" #include "fileGestion.h"
/** /**
* @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over * @brief function that delete nRow lign in the beginning of the file rawData.csv . This function is necessary to not deal with the same ligns over and over
* *
* @param nRow number of lign in the beginning of the file rawData.csv that has to be delete * @param nRow number of lign in the beginning of the file rawData.csv that has to be delete
*/ */
void clearRawData(int nRow){ void clearRawData(int nRow)
{
char buffer[256]; char buffer[256];
FILE *f = fopen("newFile.csv","w+"); FILE *f = fopen("newFile.csv", "w+");
FILE *g = fopen("rawData.csv","r"); FILE *g = fopen("rawData.csv", "r");
for(int i = 0; i < nRow; i++){ //first the program read the first nRow ligns of the csv file but do nothing for (int i = 0; i < nRow; i++)
fgets(buffer , sizeof buffer , g); { // first the program read the first nRow ligns of the csv file but do nothing
fgets(buffer, sizeof buffer, g);
} }
while(1){ //then, till the end of the csv file it copy the lign to a new csv : newFile.csv while (1)
if(!fgets(buffer,sizeof buffer , g)) break; { // then, till the end of the csv file it copy the lign to a new csv : newFile.csv
fprintf(f,"%s",buffer); if (!fgets(buffer, sizeof buffer, g))
break;
fprintf(f, "%s", buffer);
} }
remove("rawData.csv"); rename("newFile.csv", "rawData.csv"); //finally we remove the original file and rename the new one to replace rawData.csv remove("rawData.csv");
fclose(f); fclose(g); rename("newFile.csv", "rawData.csv"); // finally we remove the original file and rename the new one to replace rawData.csv
fclose(f);
fclose(g);
} }
/** /**
* @brief use to write one lign in the file "fileName" * @brief use to write one lign in the file "fileName"
* *
* @param array array that contaign all the values to write in the file * @param array array that contaign all the values to write in the file
* @param nCol size of the array (correspond to the number of captor used) * @param nCol size of the array (correspond to the number of captor used)
*/ */
void appendDataInFile(char* fileName , double array[], int nCol){ void appendDataInFile(char *fileName, double array[], int nCol)
FILE *f = fopen(fileName,"a+"); {
for(int i = 0 ; i < nCol ; i++){ FILE *f = fopen(fileName, "a+");
if( i < nCol-1){ for (int i = 0; i < nCol; i++)
{
if (i < nCol - 1)
{
fprintf(f, "%f , ", array[i]); fprintf(f, "%f , ", array[i]);
} else { }
else
{
fprintf(f, "%f\n", array[i]); fprintf(f, "%f\n", array[i]);
} }
} }

View file

@ -42,6 +42,10 @@ void printArrayData(long **p)
} }
void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M) void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M)
{ {
<<<<<<< HEAD
int i = 0, j;
=======
>>>>>>> 1c7d7edaaed0245806ce2b0f5538935709632a03
char *buffer; char *buffer;
size_t bufsize = 200; size_t bufsize = 200;
buffer = (char *)malloc(bufsize * sizeof(char)); buffer = (char *)malloc(bufsize * sizeof(char));
@ -49,20 +53,131 @@ void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M)
FILE *f = fopen(rawDataFileName, "r"); FILE *f = fopen(rawDataFileName, "r");
for (int i = 0; i < N; i++) long t, c1, c2, c3, c4, c5, c6, c7, c8;
switch (M)
{ {
long t, c1, c2, c3; case 2:
while (fscanf(f, "%ld,%ld,%ld,%ld\n", &t, &c1, &c2, &c3) != EOF) while (fscanf(f, "%ld,%ld[^\n] ", &t, &c1) != EOF)
{ // séparation valeur par virgule initiale : csv {
//printf("%ld,%ld,%ld,%ld\n", t, c1, c2, c3); p[i][0] = t;
p[i][1] = c1;
i++;
}
break;
case 3:
while (fscanf(f, "%ld,%ld,%ld[^\n] ", &t, &c1, &c2) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
i++;
}
break;
case 4:
while (fscanf(f, "%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3) != EOF)
{
p[i][0] = t; p[i][0] = t;
p[i][1] = c1; p[i][1] = c1;
p[i][2] = c2; p[i][2] = c2;
p[i][3] = c3; p[i][3] = c3;
i++;
} }
printf("%ld,%ld,%ld,%ld,\n",p[0][0],p[0][1],p[0][2],p[0][3]); break;
for(int j = 0; j < nCol; j++){ case 5:
printf("p[%d][%d] : %ld\n",i,j,p[i][j]); while (fscanf(f, "%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
i++;
}
break;
case 6:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
i++;
}
break;
case 7:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5, &c6) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
p[i][6] = c6;
i++;
}
break;
case 8:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5, &c6, &c7) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
p[i][6] = c6;
p[i][7] = c7;
i++;
}
break;
case 9:
while (fscanf(f, "%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld[^\n] ", &t, &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8) != EOF)
{
p[i][0] = t;
p[i][1] = c1;
p[i][2] = c2;
p[i][3] = c3;
p[i][4] = c4;
p[i][5] = c5;
p[i][6] = c6;
p[i][7] = c7;
p[i][8] = c8;
i++;
}
break;
default:
printf("bad column size -> time + nbr captor\n");
}
/************** Debug part **************/
// for (int ii = 0; ii < nRowRawData; ii++)
// {
// for (int y = 0; y < nCol; y++)
// {
// printf("%ld,", p[ii][y]);
// if (y == nCol - 1)
// printf("lol\n");
// }
// }
fclose(f);
}
/**
* @brief print all the element of a bidimensionnal array p of shape : N x M
*/
void printArrayData(long **p, int N, int M)
{
for (int i = 0; i < N; i++)
{
printf("line n°%d : ", i);
for (int j = 0; j < M; j++)
{
printf("%ld , ", p[i][j]);
if (j == (M - 1))
printf("\n");
} }
} }
printArrayData(p); printArrayData(p);

View file

@ -104,7 +104,7 @@ void *threadCalculGrowthRate(void *vargp)
powerFunction(fileName, dataLignPw); powerFunction(fileName, dataLignPw);
averageFunction(fileName, dataLignAv); averageFunction(fileName, dataLignAv);
growthRateFunction(dataLignPw, "growthRatePw.csv"); growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv"); growthRateFunction(dataLignAv, "growthRateAv.csv");
} }
else else
@ -126,7 +126,7 @@ void *threadCalculGrowthRate(void *vargp)
growthRateFunction(dataLignPw, "growthRatePw.csv"); growthRateFunction(dataLignPw, "growthRatePw.csv");
growthRateFunction(dataLignPw, "growthRateAv.csv"); growthRateFunction(dataLignPw, "growthRateAv.csv");
} }
// remove(fileName); remove(fileName);
} }
} }
return NULL; return NULL;

View file

@ -176,7 +176,7 @@ bool writeOneRawData(FILE *rawDataFile)
} }
cptData++; cptData++;
// simul freq here /************** simul freq here **************/
// struct timespec ts; // struct timespec ts;
// ts.tv_sec = 0; // ts.tv_sec = 0;
// ts.tv_nsec = 4 * 1000000; // ts.tv_nsec = 4 * 1000000;

13
README.md Normal file
View file

@ -0,0 +1,13 @@
# [Robot Go West](https://projets.cohabit.fr/redmine/projects/communication-racinaire/wiki/Robot_Go-West)
### Introduction
This projet is a part of larger projet [_Communication Racinaire_](https://projets.cohabit.fr/redmine/projects/communication-racinaire/wiki/Wiki#section-8) which aims to drive plante into the direction of the sun.
When a plant received the solar radiation, a **difference of potential** will be created inside the plant. This physical reaction interest us to **measure** it and **interpret** the signal to drive the robot.
## Embedded C sources
## Graphic visualization Python script

BIN
chaien.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB