create readme.md and fix issue on recovery data array from file and adaptative array size frome the number of captors
This commit is contained in:
parent
a8c235bc65
commit
70e01e558f
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
void averageCalculation(long **p, double averageArray[])
|
||||
{
|
||||
printArrayData(p, nRowRawData, nCol);
|
||||
// printArrayData(p, nRowRawData, nCol);
|
||||
printf("\n");
|
||||
for (int i = 1; i < nCol; i++)
|
||||
{
|
||||
|
@ -19,9 +19,7 @@ void averageCalculation(long **p, double averageArray[])
|
|||
averageArray[i] = 0;
|
||||
while (j < nRowRawData)
|
||||
{
|
||||
printf("pij = %ld\n", p[i][j]);
|
||||
averageArray[i - 1] += (double)p[i][j];
|
||||
// printf("%f , %ld\n", averageArray[i], p[i][j]);
|
||||
j++;
|
||||
}
|
||||
averageArray[i] /= nRowRawData;
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
#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
|
||||
*
|
||||
* @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];
|
||||
FILE *f = fopen("newFile.csv","w+");
|
||||
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
|
||||
fgets(buffer , sizeof buffer , g);
|
||||
FILE *f = fopen("newFile.csv", "w+");
|
||||
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
|
||||
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
|
||||
if(!fgets(buffer,sizeof buffer , g)) break;
|
||||
fprintf(f,"%s",buffer);
|
||||
while (1)
|
||||
{ // then, till the end of the csv file it copy the lign to a new csv : newFile.csv
|
||||
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
|
||||
fclose(f); fclose(g);
|
||||
remove("rawData.csv");
|
||||
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"
|
||||
|
@ -26,12 +31,17 @@ void clearRawData(int nRow){
|
|||
* @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)
|
||||
*/
|
||||
void appendDataInFile(char* fileName , double array[], int nCol){
|
||||
FILE *f = fopen(fileName,"a+");
|
||||
for(int i = 0 ; i < nCol ; i++){
|
||||
if( i < nCol-1){
|
||||
void appendDataInFile(char *fileName, double array[], int nCol)
|
||||
{
|
||||
FILE *f = fopen(fileName, "a+");
|
||||
for (int i = 0; i < nCol; i++)
|
||||
{
|
||||
if (i < nCol - 1)
|
||||
{
|
||||
fprintf(f, "%f , ", array[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(f, "%f\n", array[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ double **getDoubleArray(int N, int M) /* Allocate the array */
|
|||
|
||||
void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M)
|
||||
{
|
||||
int i, j;
|
||||
int i = 0, j;
|
||||
char *buffer;
|
||||
size_t bufsize = 200;
|
||||
buffer = (char *)malloc(bufsize * sizeof(char));
|
||||
|
@ -35,20 +35,118 @@ void fillArrayWithRawData(char *rawDataFileName, long **p, int N, int M)
|
|||
|
||||
FILE *f = fopen(rawDataFileName, "r");
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
long t, c1, c2, c3, c4, c5, c6, c7, c8;
|
||||
switch (M)
|
||||
{
|
||||
long t, c1, c2, c3;
|
||||
while (fscanf(f, "%ld,%ld,%ld,%ld\n", &t, &c1, &c2, &c3) != EOF)
|
||||
{ // séparation valeur par virgule initiale : csv
|
||||
// printf("%ld,%ld,%ld,%ld\n", t, c1, c2, c3);
|
||||
case 2:
|
||||
while (fscanf(f, "%ld,%ld[^\n] ", &t, &c1) != EOF)
|
||||
{
|
||||
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][1] = c1;
|
||||
p[i][2] = c2;
|
||||
p[i][3] = c3;
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -104,7 +104,7 @@ void *threadCalculGrowthRate(void *vargp)
|
|||
powerFunction(fileName, dataLignPw);
|
||||
averageFunction(fileName, dataLignAv);
|
||||
growthRateFunction(dataLignPw, "growthRatePw.csv");
|
||||
growthRateFunction(dataLignPw, "growthRateAv.csv");
|
||||
growthRateFunction(dataLignAv, "growthRateAv.csv");
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -126,7 +126,7 @@ void *threadCalculGrowthRate(void *vargp)
|
|||
growthRateFunction(dataLignPw, "growthRatePw.csv");
|
||||
growthRateFunction(dataLignPw, "growthRateAv.csv");
|
||||
}
|
||||
// remove(fileName);
|
||||
remove(fileName);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -176,7 +176,7 @@ bool writeOneRawData(FILE *rawDataFile)
|
|||
}
|
||||
cptData++;
|
||||
|
||||
// simul freq here
|
||||
/************** simul freq here **************/
|
||||
// struct timespec ts;
|
||||
// ts.tv_sec = 0;
|
||||
// ts.tv_nsec = 4 * 1000000;
|
||||
|
|
13
README.md
Normal file
13
README.md
Normal 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
BIN
chaien.PNG
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
Loading…
Reference in a new issue