From 300743296364b70fc660fbdbaffebade6cb8a5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Gauthier?= Date: Mon, 12 Jan 2026 11:10:24 +0100 Subject: [PATCH] readme changes and data traitement for training --- README.md | 2 +- exec/merge_photo_csv.r | 22 ++ exec/merged_photo_data | 568 ++++++++++++++++++++++++++++++++ exec/plot_measures.r | 23 +- exec/random_forest_predict.r | 34 +- exec/sun_pos.r | 2 +- lib/storage/storage_interface.h | 2 +- src/main.cpp | 10 +- 8 files changed, 649 insertions(+), 14 deletions(-) create mode 100644 exec/merge_photo_csv.r create mode 100644 exec/merged_photo_data diff --git a/README.md b/README.md index 4edb48b..aff47d9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Arduino-Photometrics -**Arduino-photometrics** is sub-module of **Robot Go West** project. +**Arduino-photometrics** is a sub-module of the [Robot Go West](LIEN_VERS_PROJET) project, developed as part of the projects at the [Cohabit Fablab](https://cohabit.fr). The goal of this project is to collect local lighting data to train a prediction model capable of estimating the sun's position. The system is structured as follows: diff --git a/exec/merge_photo_csv.r b/exec/merge_photo_csv.r new file mode 100644 index 0000000..a89626b --- /dev/null +++ b/exec/merge_photo_csv.r @@ -0,0 +1,22 @@ +# install.packages("ragg") +# install.packages("tidyverse") +# install.packages("ggplot2") + +library(ggplot2) +library(dplyr) + +setwd("~/Documents/PlatformIO/Projects/Robot_Go_West/arduino-photometrics/exec") + +chemin <- "../data/photo_measures/" +fichiers <- list.files(path = chemin, pattern = "\\.csv$", full.names = TRUE) + +liste_data <- lapply(fichiers, read.csv, header = TRUE) +partial_list_data <- liste_data[3:6] + +photo <- do.call(rbind, partial_list_data) + +csv_name <- "merged_photo_data.csv" +csv_path_name <- paste(c(chemin, csv_name), collapse = "") + +write.csv2(photo, file = "merged_photo_data", sep = ",", eol = "\n", col.names = TRUE,) +write.csv(photo, csv_path_name, row.names = FALSE) \ No newline at end of file diff --git a/exec/merged_photo_data b/exec/merged_photo_data new file mode 100644 index 0000000..ac98807 --- /dev/null +++ b/exec/merged_photo_data @@ -0,0 +1,568 @@ +"";"Epoch";"Photo_sensor0";"Photo_sensor1";"Photo_sensor2";"Photo_sensor3";"Photo_sensor4";"Photo_sensor5";"Temp_sensor0" +"1";1767614390;0;0;0;0;0;1;21 +"2";1767615290;0;0;0;0;0;1;23 +"3";1767616190;0;0;0;0;0;1;24 +"4";1767617090;0;0;0;0;0;1;24 +"5";1767617990;0;0;0;0;0;1;25 +"6";1767618890;0;0;0;0;0;1;25 +"7";1767619790;0;0;0;0;0;1;24 +"8";1767620690;0;0;0;0;0;1;25 +"9";1767621590;0;0;0;0;0;1;24 +"10";1767622490;0;0;0;0;0;1;24 +"11";1767623390;0;0;0;0;0;2;24 +"12";1767624290;0;0;0;0;0;2;24 +"13";1767625190;0;0;1;0;0;2;24 +"14";1767626303;0;0;2;0;0;3;58 +"15";1767627203;0;0;2;0;0;4;23 +"16";1767628103;1;0;2;0;1;5;23 +"17";1767629003;2;1;3;0;1;6;22 +"18";1767629903;3;1;3;0;1;8;22 +"19";1767630803;3;1;4;0;1;10;22 +"20";1767631703;4;1;4;0;2;12;21 +"21";1767632603;6;2;6;0;2;17;21 +"22";1767633503;9;4;8;1;4;25;21 +"23";1767634403;6;3;9;1;4;18;20 +"24";1767635303;8;4;13;2;7;22;20 +"25";1767636203;8;5;14;3;8;23;20 +"26";1767637103;8;5;14;3;8;23;20 +"27";1767638003;8;5;14;3;8;23;19 +"28";1767638903;8;5;14;3;8;23;19 +"29";1767639803;25;2;23;0;0;23;18 +"30";1767640703;0;0;23;0;0;23;18 +"31";1767641603;0;0;23;0;0;23;18 +"32";1767642503;0;0;23;0;0;23;17 +"33";1767643403;24;24;23;23;23;23;17 +"34";1767644303;23;23;23;23;23;23;17 +"35";1767645203;23;23;23;23;23;23;17 +"36";1767646103;23;19;23;11;23;23;16 +"37";1767647003;23;23;23;23;23;23;16 +"38";1767647903;23;23;23;23;23;23;16 +"39";1767648803;23;19;23;23;23;23;16 +"40";1767649703;23;24;23;13;23;23;16 +"41";1767650603;23;14;23;22;23;23;16 +"42";1767651503;23;8;23;21;23;23;16 +"43";1767652403;23;20;23;23;23;23;15 +"44";1767653303;23;25;23;23;23;23;15 +"45";1767654203;23;16;23;19;23;23;15 +"46";1767655103;23;23;23;23;23;23;15 +"47";1767656003;23;23;23;23;23;23;15 +"48";1767656903;23;21;23;23;23;23;15 +"49";1767657803;23;22;23;23;23;23;15 +"50";1767658703;23;23;23;23;23;23;15 +"51";1767659603;23;17;23;23;23;23;14 +"52";1767660503;23;5;23;10;23;23;14 +"53";1767661403;0;0;23;0;0;23;14 +"54";1767662303;23;23;23;23;23;23;14 +"55";1767663203;23;23;23;23;23;23;14 +"56";1767664103;23;23;23;23;23;23;14 +"57";1767665003;23;23;23;23;23;23;13 +"58";1767665903;23;23;23;23;23;23;13 +"59";1767666803;23;23;23;23;23;23;13 +"60";1767667703;25;0;23;0;25;23;13 +"61";1767668603;25;25;24;0;0;23;13 +"62";1767669503;25;0;23;0;0;23;13 +"63";1767670403;24;25;23;25;25;23;13 +"64";1767671303;23;23;23;23;23;23;13 +"65";1767672203;23;23;23;23;23;23;12 +"66";1767673103;23;23;23;23;23;23;12 +"67";1767674003;0;0;25;0;0;23;12 +"68";1767674903;8;17;0;22;16;0;12 +"69";1767675803;0;2;23;0;0;23;12 +"70";1767676703;0;2;23;0;0;23;12 +"71";1767677603;0;0;23;0;0;23;12 +"72";1767678503;0;0;23;0;0;23;12 +"73";1767679403;0;0;23;24;25;23;12 +"74";1767680303;0;0;23;24;24;23;12 +"75";1767681203;0;0;23;23;24;23;12 +"76";1767682103;0;0;23;25;0;23;12 +"77";1767683003;0;0;23;0;0;23;11 +"78";1767683903;0;0;23;25;0;23;11 +"79";1767684803;0;0;23;24;0;23;11 +"80";1767685703;0;0;23;24;25;23;11 +"81";1767686603;25;0;23;23;23;23;11 +"82";1767687503;23;21;23;20;23;23;11 +"83";1767688403;23;23;15;19;21;4;11 +"84";1767689303;20;14;0;5;14;23;11 +"85";1767690203;7;11;21;4;10;3;12 +"86";1767691103;18;6;13;2;6;11;12 +"87";1767692003;7;2;6;0;2;15;12 +"88";1767692903;2;1;2;0;1;6;12 +"89";1767693803;1;0;1;0;0;3;12 +"90";1767694703;1;0;1;0;0;3;13 +"91";1767695603;0;0;1;0;0;2;13 +"92";1767696503;0;0;1;0;0;3;14 +"93";1767697403;0;0;0;0;0;1;14 +"94";1767698303;0;0;0;0;0;0;16 +"95";1767699203;0;0;0;0;0;0;17 +"96";1767700103;0;0;0;0;0;1;18 +"97";1767701003;0;0;0;0;0;1;20 +"98";1767701903;0;0;0;0;0;0;22 +"99";1767702803;0;0;0;0;0;1;22 +"100";1767703703;0;0;0;0;0;1;23 +"101";1767704603;0;0;0;0;0;1;23 +"102";1767705503;0;0;0;0;0;1;24 +"103";1767706403;0;0;0;0;0;1;24 +"104";1767707303;0;0;0;0;0;1;24 +"105";1767708203;0;0;0;0;0;1;24 +"106";1767709103;0;0;0;0;0;2;24 +"107";1767710003;0;0;0;0;0;2;24 +"108";1767710903;0;0;1;0;0;2;23 +"109";1767711803;0;0;1;0;0;3;23 +"110";1767712703;0;0;1;0;0;3;23 +"111";1767713603;0;0;2;0;0;3;22 +"112";1767714503;1;0;2;0;1;4;22 +"113";1767715403;2;0;2;0;1;5;22 +"114";1767716303;2;1;3;0;1;6;21 +"115";1767717203;2;1;3;0;1;7;21 +"116";1767718103;3;1;4;0;1;8;20 +"117";1767719003;3;1;4;0;2;10;20 +"118";1767719903;4;2;6;0;2;12;20 +"119";1767720803;6;3;9;1;4;17;20 +"120";1767721703;7;4;12;2;6;21;19 +"121";1767722603;7;5;13;2;7;22;18 +"122";1767723503;7;4;13;2;7;22;18 +"123";1767724403;7;4;13;2;7;22;18 +"124";1767725303;7;5;13;2;7;22;18 +"125";1767726203;7;4;13;2;7;21;17 +"126";1767727103;7;4;13;2;7;21;17 +"127";1767728003;23;23;23;23;23;23;17 +"128";1767728903;24;25;23;23;24;23;16 +"129";1767729803;25;0;23;25;0;23;16 +"130";1767730703;0;0;23;25;0;23;16 +"131";1767731603;0;0;23;25;0;23;16 +"132";1767732503;25;25;23;24;24;23;16 +"133";1767733403;25;0;23;24;0;23;15 +"134";1767734303;0;0;23;0;0;23;15 +"135";1767735203;0;0;23;0;0;23;15 +"136";1767736103;0;0;23;0;0;23;15 +"137";1767737003;0;0;23;0;0;23;15 +"138";1767737903;0;0;23;0;0;23;15 +"139";1767738803;0;0;0;0;0;0;15 +"140";1767739703;0;0;0;0;0;0;14 +"141";1767740603;0;0;0;0;0;23;14 +"142";1767741503;0;0;0;0;0;0;14 +"143";1767742403;0;0;24;0;0;23;14 +"144";1767743303;24;25;24;25;25;23;14 +"145";1767744203;0;0;0;0;0;25;14 +"146";1767745103;0;0;0;0;0;0;14 +"147";1767746003;0;0;0;0;0;0;14 +"148";1767746903;0;0;0;0;0;0;14 +"149";1767747803;25;15;0;6;3;0;14 +"150";1767748703;2;0;0;18;5;0;13 +"151";1767749603;1;10;0;10;23;0;13 +"152";1767750503;23;24;0;11;0;0;13 +"153";1767751403;7;19;0;21;8;0;13 +"154";1767752303;3;23;0;16;16;0;13 +"155";1767753203;21;18;0;17;21;0;13 +"156";1767754103;14;20;0;7;12;0;13 +"157";1767755003;21;6;0;1;18;0;13 +"158";1767755903;23;1;0;6;17;0;13 +"159";1767756803;14;13;0;8;4;0;13 +"160";1767757703;7;3;25;10;14;0;13 +"161";1767758603;0;21;25;10;19;0;13 +"162";1767759503;7;22;19;3;19;0;13 +"163";1767760403;6;15;25;22;6;0;13 +"164";1767761303;19;16;19;22;19;0;12 +"165";1767762203;10;14;23;3;10;24;12 +"166";1767763103;6;11;23;0;0;23;12 +"167";1767764003;20;0;23;0;0;23;12 +"168";1767764903;21;11;23;0;0;23;12 +"169";1767765803;14;25;23;0;0;23;12 +"170";1767766703;19;6;23;0;0;23;12 +"171";1767767603;1;5;23;0;0;23;12 +"172";1767768503;1;11;23;0;0;23;12 +"173";1767769403;7;6;23;0;0;23;12 +"174";1767770303;0;5;23;0;0;23;12 +"175";1767771203;0;2;23;0;0;23;12 +"176";1767772103;0;2;23;0;0;23;12 +"177";1767773003;0;0;23;24;25;23;12 +"178";1767773903;23;22;23;13;23;23;12 +"179";1767774803;10;5;17;20;24;17;12 +"180";1767775703;24;19;4;7;17;8;12 +"181";1767776603;20;7;13;2;6;10;12 +"182";1767777503;13;4;9;1;4;24;12 +"183";1767778403;3;1;5;0;2;12;12 +"184";1767779303;1;18;4;0;2;7;13 +"185";1767780203;0;15;3;0;1;6;13 +"186";1767781103;1;0;2;0;1;6;13 +"187";1767782003;2;1;3;0;1;9;13 +"188";1767782903;1;0;2;0;1;6;13 +"189";1767783803;0;0;1;0;0;4;13 +"190";1767784703;1;0;2;0;1;6;14 +"191";1767785603;1;0;2;0;1;6;14 +"192";1767786503;1;0;2;0;1;6;14 +"193";1767787403;1;0;2;0;1;7;14 +"194";1767788303;1;0;3;0;1;8;14 +"195";1767789203;1;0;2;0;1;6;14 +"196";1767790103;1;0;3;0;1;8;14 +"197";1767791003;2;0;3;0;1;8;14 +"198";1767791903;2;1;4;0;1;10;14 +"199";1767792803;1;0;3;0;1;8;14 +"200";1767793703;2;1;4;0;1;9;14 +"201";1767794603;2;0;4;0;1;9;14 +"202";1767795503;3;1;6;0;2;12;14 +"203";1767626303;0;0;2;0;0;3;58 +"204";1767627203;0;0;2;0;0;4;23 +"205";1767628103;1;0;2;0;1;5;23 +"206";1767629003;2;1;3;0;1;6;22 +"207";1767629903;3;1;3;0;1;8;22 +"208";1767630803;3;1;4;0;1;10;22 +"209";1767631703;4;1;4;0;2;12;21 +"210";1767632603;6;2;6;0;2;17;21 +"211";1767633503;9;4;8;1;4;25;21 +"212";1767634403;6;3;9;1;4;18;20 +"213";1767635303;8;4;13;2;7;22;20 +"214";1767636203;8;5;14;3;8;23;20 +"215";1767637103;8;5;14;3;8;23;20 +"216";1767638003;8;5;14;3;8;23;19 +"217";1767638903;8;5;14;3;8;23;19 +"218";1767639803;25;2;23;0;0;23;18 +"219";1767640703;0;0;23;0;0;23;18 +"220";1767641603;0;0;23;0;0;23;18 +"221";1767642503;0;0;23;0;0;23;17 +"222";1767643403;24;24;23;23;23;23;17 +"223";1767644303;23;23;23;23;23;23;17 +"224";1767645203;23;23;23;23;23;23;17 +"225";1767646103;23;19;23;11;23;23;16 +"226";1767647003;23;23;23;23;23;23;16 +"227";1767647903;23;23;23;23;23;23;16 +"228";1767648803;23;19;23;23;23;23;16 +"229";1767649703;23;24;23;13;23;23;16 +"230";1767650603;23;14;23;22;23;23;16 +"231";1767651503;23;8;23;21;23;23;16 +"232";1767652403;23;20;23;23;23;23;15 +"233";1767653303;23;25;23;23;23;23;15 +"234";1767654203;23;16;23;19;23;23;15 +"235";1767655103;23;23;23;23;23;23;15 +"236";1767656003;23;23;23;23;23;23;15 +"237";1767656903;23;21;23;23;23;23;15 +"238";1767657803;23;22;23;23;23;23;15 +"239";1767658703;23;23;23;23;23;23;15 +"240";1767659603;23;17;23;23;23;23;14 +"241";1767660503;23;5;23;10;23;23;14 +"242";1767661403;0;0;23;0;0;23;14 +"243";1767662303;23;23;23;23;23;23;14 +"244";1767663203;23;23;23;23;23;23;14 +"245";1767664103;23;23;23;23;23;23;14 +"246";1767665003;23;23;23;23;23;23;13 +"247";1767665903;23;23;23;23;23;23;13 +"248";1767666803;23;23;23;23;23;23;13 +"249";1767667703;25;0;23;0;25;23;13 +"250";1767668603;25;25;24;0;0;23;13 +"251";1767669503;25;0;23;0;0;23;13 +"252";1767670403;24;25;23;25;25;23;13 +"253";1767671303;23;23;23;23;23;23;13 +"254";1767672203;23;23;23;23;23;23;12 +"255";1767673103;23;23;23;23;23;23;12 +"256";1767674003;0;0;25;0;0;23;12 +"257";1767674903;8;17;0;22;16;0;12 +"258";1767675803;0;2;23;0;0;23;12 +"259";1767676703;0;2;23;0;0;23;12 +"260";1767677603;0;0;23;0;0;23;12 +"261";1767678503;0;0;23;0;0;23;12 +"262";1767679403;0;0;23;24;25;23;12 +"263";1767680303;0;0;23;24;24;23;12 +"264";1767681203;0;0;23;23;24;23;12 +"265";1767682103;0;0;23;25;0;23;12 +"266";1767683003;0;0;23;0;0;23;11 +"267";1767683903;0;0;23;25;0;23;11 +"268";1767684803;0;0;23;24;0;23;11 +"269";1767685703;0;0;23;24;25;23;11 +"270";1767686603;25;0;23;23;23;23;11 +"271";1767687503;23;21;23;20;23;23;11 +"272";1767688403;23;23;15;19;21;4;11 +"273";1767689303;20;14;0;5;14;23;11 +"274";1767690203;7;11;21;4;10;3;12 +"275";1767691103;18;6;13;2;6;11;12 +"276";1767692003;7;2;6;0;2;15;12 +"277";1767692903;2;1;2;0;1;6;12 +"278";1767693803;1;0;1;0;0;3;12 +"279";1767694703;1;0;1;0;0;3;13 +"280";1767695603;0;0;1;0;0;2;13 +"281";1767696503;0;0;1;0;0;3;14 +"282";1767697403;0;0;0;0;0;1;14 +"283";1767698303;0;0;0;0;0;0;16 +"284";1767699203;0;0;0;0;0;0;17 +"285";1767700103;0;0;0;0;0;1;18 +"286";1767701003;0;0;0;0;0;1;20 +"287";1767701903;0;0;0;0;0;0;22 +"288";1767702803;0;0;0;0;0;1;22 +"289";1767703703;0;0;0;0;0;1;23 +"290";1767704603;0;0;0;0;0;1;23 +"291";1767705503;0;0;0;0;0;1;24 +"292";1767706403;0;0;0;0;0;1;24 +"293";1767707303;0;0;0;0;0;1;24 +"294";1767708203;0;0;0;0;0;1;24 +"295";1767709103;0;0;0;0;0;2;24 +"296";1767710003;0;0;0;0;0;2;24 +"297";1767710903;0;0;1;0;0;2;23 +"298";1767711803;0;0;1;0;0;3;23 +"299";1767712703;0;0;1;0;0;3;23 +"300";1767713603;0;0;2;0;0;3;22 +"301";1767714503;1;0;2;0;1;4;22 +"302";1767715403;2;0;2;0;1;5;22 +"303";1767716303;2;1;3;0;1;6;21 +"304";1767717203;2;1;3;0;1;7;21 +"305";1767718103;3;1;4;0;1;8;20 +"306";1767719003;3;1;4;0;2;10;20 +"307";1767719903;4;2;6;0;2;12;20 +"308";1767720803;6;3;9;1;4;17;20 +"309";1767721703;7;4;12;2;6;21;19 +"310";1767722603;7;5;13;2;7;22;18 +"311";1767723503;7;4;13;2;7;22;18 +"312";1767724403;7;4;13;2;7;22;18 +"313";1767725303;7;5;13;2;7;22;18 +"314";1767726203;7;4;13;2;7;21;17 +"315";1767727103;7;4;13;2;7;21;17 +"316";1767728003;23;23;23;23;23;23;17 +"317";1767728903;24;25;23;23;24;23;16 +"318";1767729803;25;0;23;25;0;23;16 +"319";1767730703;0;0;23;25;0;23;16 +"320";1767731603;0;0;23;25;0;23;16 +"321";1767732503;25;25;23;24;24;23;16 +"322";1767733403;25;0;23;24;0;23;15 +"323";1767734303;0;0;23;0;0;23;15 +"324";1767735203;0;0;23;0;0;23;15 +"325";1767736103;0;0;23;0;0;23;15 +"326";1767737003;0;0;23;0;0;23;15 +"327";1767737903;0;0;23;0;0;23;15 +"328";1767738803;0;0;0;0;0;0;15 +"329";1767739703;0;0;0;0;0;0;14 +"330";1767740603;0;0;0;0;0;23;14 +"331";1767741503;0;0;0;0;0;0;14 +"332";1767742403;0;0;24;0;0;23;14 +"333";1767743303;24;25;24;25;25;23;14 +"334";1767744203;0;0;0;0;0;25;14 +"335";1767745103;0;0;0;0;0;0;14 +"336";1767746003;0;0;0;0;0;0;14 +"337";1767746903;0;0;0;0;0;0;14 +"338";1767747803;25;15;0;6;3;0;14 +"339";1767748703;2;0;0;18;5;0;13 +"340";1767749603;1;10;0;10;23;0;13 +"341";1767750503;23;24;0;11;0;0;13 +"342";1767751403;7;19;0;21;8;0;13 +"343";1767752303;3;23;0;16;16;0;13 +"344";1767753203;21;18;0;17;21;0;13 +"345";1767754103;14;20;0;7;12;0;13 +"346";1767755003;21;6;0;1;18;0;13 +"347";1767755903;23;1;0;6;17;0;13 +"348";1767756803;14;13;0;8;4;0;13 +"349";1767757703;7;3;25;10;14;0;13 +"350";1767758603;0;21;25;10;19;0;13 +"351";1767759503;7;22;19;3;19;0;13 +"352";1767760403;6;15;25;22;6;0;13 +"353";1767761303;19;16;19;22;19;0;12 +"354";1767762203;10;14;23;3;10;24;12 +"355";1767763103;6;11;23;0;0;23;12 +"356";1767764003;20;0;23;0;0;23;12 +"357";1767764903;21;11;23;0;0;23;12 +"358";1767765803;14;25;23;0;0;23;12 +"359";1767766703;19;6;23;0;0;23;12 +"360";1767767603;1;5;23;0;0;23;12 +"361";1767768503;1;11;23;0;0;23;12 +"362";1767769403;7;6;23;0;0;23;12 +"363";1767770303;0;5;23;0;0;23;12 +"364";1767771203;0;2;23;0;0;23;12 +"365";1767772103;0;2;23;0;0;23;12 +"366";1767773003;0;0;23;24;25;23;12 +"367";1767773903;23;22;23;13;23;23;12 +"368";1767774803;10;5;17;20;24;17;12 +"369";1767775703;24;19;4;7;17;8;12 +"370";1767776603;20;7;13;2;6;10;12 +"371";1767777503;13;4;9;1;4;24;12 +"372";1767778403;3;1;5;0;2;12;12 +"373";1767779303;1;18;4;0;2;7;13 +"374";1767780203;0;15;3;0;1;6;13 +"375";1767781103;1;0;2;0;1;6;13 +"376";1767782003;2;1;3;0;1;9;13 +"377";1767782903;1;0;2;0;1;6;13 +"378";1767783803;0;0;1;0;0;4;13 +"379";1767784703;1;0;2;0;1;6;14 +"380";1767785603;1;0;2;0;1;6;14 +"381";1767786503;1;0;2;0;1;6;14 +"382";1767787403;1;0;2;0;1;7;14 +"383";1767788303;1;0;3;0;1;8;14 +"384";1767789203;1;0;2;0;1;6;14 +"385";1767790103;1;0;3;0;1;8;14 +"386";1767791003;2;0;3;0;1;8;14 +"387";1767791903;2;1;4;0;1;10;14 +"388";1767792803;1;0;3;0;1;8;14 +"389";1767793703;2;1;4;0;1;9;14 +"390";1767794603;2;0;4;0;1;9;14 +"391";1767795503;3;1;6;0;2;12;14 +"392";1767796665;4;1;6;1;2;17;14 +"393";1767797565;2;1;4;0;2;12;14 +"394";1767798465;2;1;5;0;2;13;14 +"395";1767799365;2;0;4;0;2;12;14 +"396";1767800265;2;0;4;0;2;12;15 +"397";1767801165;4;1;6;1;3;17;15 +"398";1767802065;4;2;7;1;3;19;15 +"399";1767802965;3;1;6;0;2;16;15 +"400";1767803865;4;2;7;1;3;19;15 +"401";1767804765;7;3;10;1;4;20;15 +"402";1767805665;6;3;10;1;4;20;15 +"403";1767806565;9;4;12;2;6;23;15 +"404";1767807465;11;6;16;3;7;25;15 +"405";1767808365;12;7;18;3;8;0;15 +"406";1767809265;12;7;19;3;8;0;15 +"407";1767810165;12;7;18;3;8;0;15 +"408";1767811065;12;7;19;3;8;0;15 +"409";1767811965;12;7;19;3;8;0;15 +"410";1767812865;6;5;23;20;25;23;14 +"411";1767813765;18;5;23;17;0;23;14 +"412";1767814665;12;5;23;16;25;23;14 +"413";1767815565;24;15;23;20;25;0;14 +"414";1767816465;6;4;23;9;24;23;14 +"415";1767817365;24;14;23;25;25;0;14 +"416";1767818265;12;23;23;18;25;23;14 +"417";1767819165;12;20;23;13;25;23;14 +"418";1767820065;7;15;23;20;24;23;13 +"419";1767820965;0;4;23;20;25;23;13 +"420";1767821865;24;14;23;3;25;23;13 +"421";1767822765;0;20;23;15;25;23;13 +"422";1767823665;0;14;23;20;25;23;13 +"423";1767824565;25;5;23;17;25;23;13 +"424";1767825465;0;3;25;11;24;23;13 +"425";1767826365;18;13;24;17;24;23;13 +"426";1767827265;25;23;24;25;25;23;13 +"427";1767828165;6;13;25;24;25;23;13 +"428";1767829065;25;12;24;24;25;23;13 +"429";1767829965;7;12;25;24;24;23;13 +"430";1767830865;0;23;25;24;25;23;13 +"431";1767831765;18;13;25;25;24;23;13 +"432";1767832665;18;21;24;25;24;23;13 +"433";1767833565;25;23;25;24;24;23;13 +"434";1767834465;12;12;25;11;24;23;13 +"435";1767835365;18;22;25;18;25;23;13 +"436";1767836265;18;23;25;25;25;23;13 +"437";1767837165;14;2;25;17;24;23;13 +"438";1767838065;14;5;25;24;24;23;13 +"439";1767838965;25;22;0;24;24;23;13 +"440";1767839865;8;3;25;17;24;23;13 +"441";1767840765;0;13;24;17;24;23;13 +"442";1767841665;18;14;25;11;25;23;13 +"443";1767842565;12;4;24;24;24;23;13 +"444";1767843465;18;23;24;18;24;23;13 +"445";1767844365;15;13;24;4;24;23;13 +"446";1767845265;18;15;24;24;24;23;13 +"447";1767846165;18;22;24;25;24;23;13 +"448";1767847065;14;4;24;17;24;23;13 +"449";1767847965;0;13;25;18;25;23;13 +"450";1767848865;25;14;23;13;25;23;13 +"451";1767849765;0;15;23;25;25;23;13 +"452";1767850665;25;4;24;11;24;23;13 +"453";1767851565;24;21;25;18;25;24;13 +"454";1767852465;18;11;24;25;25;23;13 +"455";1767853365;25;5;24;25;25;23;13 +"456";1767854265;24;21;23;25;25;23;13 +"457";1767855165;25;14;24;7;25;0;14 +"458";1767856065;24;5;23;20;25;0;14 +"459";1767856965;24;2;24;18;25;0;14 +"460";1767857865;0;20;23;7;25;23;14 +"461";1767858765;0;20;23;13;25;23;14 +"462";1767859665;19;23;23;16;5;23;14 +"463";1767860565;23;7;6;7;23;23;14 +"464";1767861465;1;6;4;17;19;16;14 +"465";1767862365;12;15;5;7;21;19;14 +"466";1767863265;8;5;13;2;6;21;14 +"467";1767864165;6;4;10;1;4;19;14 +"468";1767865065;5;3;9;1;4;20;14 +"469";1767865965;5;3;8;1;3;17;15 +"470";1767866865;5;3;8;1;4;23;15 +"471";1767867765;3;2;5;0;2;14;15 +"472";1767868665;3;2;5;0;2;14;15 +"473";1767869565;2;2;4;0;2;12;15 +"474";1767870465;2;2;4;0;1;11;16 +"475";1767871365;1;2;3;0;1;9;16 +"476";1767872265;2;1;4;0;2;11;16 +"477";1767873165;1;0;3;0;1;8;16 +"478";1767874065;2;0;3;0;1;10;17 +"479";1767874965;2;1;4;0;2;12;17 +"480";1767875865;2;1;4;0;1;11;17 +"481";1767876765;3;1;5;0;2;12;17 +"482";1767877665;1;1;3;0;1;10;17 +"483";1767878565;1;0;2;0;1;8;18 +"484";1767879465;1;2;3;0;1;9;18 +"485";1767880365;2;1;4;0;2;12;18 +"486";1767881265;2;1;4;0;2;12;18 +"487";1767882165;1;0;3;0;1;10;18 +"488";1767883065;1;0;2;0;1;8;18 +"489";1767883965;2;1;4;0;2;12;18 +"490";1767884865;3;1;5;0;2;16;18 +"491";1767885765;2;0;4;0;2;12;18 +"492";1767886665;2;0;4;0;2;12;18 +"493";1767887565;3;1;5;0;2;16;18 +"494";1767888465;4;1;6;1;3;19;18 +"495";1767889365;5;2;8;1;3;22;18 +"496";1767890265;4;2;7;1;3;21;18 +"497";1767891165;6;2;9;1;4;25;18 +"498";1767892065;12;7;22;5;15;4;18 +"499";1767892965;12;7;22;5;15;3;18 +"500";1767893865;16;11;12;13;6;22;18 +"501";1767894765;15;10;12;14;8;22;18 +"502";1767895665;24;25;23;15;19;0;18 +"503";1767896565;24;25;25;20;25;0;17 +"504";1767897465;24;14;25;11;24;0;17 +"505";1767898365;25;15;0;13;0;0;17 +"506";1767899265;25;22;25;6;24;0;17 +"507";1767900165;25;5;24;8;24;0;17 +"508";1767901065;25;15;25;16;25;0;17 +"509";1767901965;24;22;24;2;25;0;17 +"510";1767902865;24;25;24;15;25;0;17 +"511";1767903765;24;16;24;15;25;0;17 +"512";1767904665;24;25;24;7;25;0;17 +"513";1767905565;24;0;23;4;24;0;17 +"514";1767906465;24;8;23;25;25;0;17 +"515";1767907365;24;25;23;7;25;0;16 +"516";1767908265;24;0;23;21;24;0;16 +"517";1767909165;24;25;24;12;25;0;16 +"518";1767910065;25;12;24;13;25;0;16 +"519";1767910965;25;0;23;19;25;0;16 +"520";1767911865;24;5;17;11;24;23;16 +"521";1767912765;25;2;24;11;24;24;16 +"522";1767913665;24;23;24;4;24;24;16 +"523";1767914565;24;21;25;4;24;24;16 +"524";1767915465;24;5;24;16;24;24;16 +"525";1767916365;24;21;18;4;24;24;16 +"526";1767917265;24;22;25;16;24;24;16 +"527";1767918165;25;21;24;4;24;25;16 +"528";1767919065;24;20;24;4;24;24;16 +"529";1767919965;25;21;25;4;24;24;16 +"530";1767920865;24;5;25;11;24;24;16 +"531";1767921765;24;21;25;11;24;24;16 +"532";1767922665;25;4;24;17;24;24;16 +"533";1767923565;24;5;24;4;24;24;16 +"534";1767924465;24;22;25;17;24;24;16 +"535";1767925365;24;6;25;4;24;24;16 +"536";1767926265;25;11;25;4;24;24;16 +"537";1767927165;21;6;24;16;24;23;16 +"538";1767928065;0;4;24;11;24;23;16 +"539";1767928965;0;15;25;23;24;23;16 +"540";1767929865;7;21;25;23;24;23;16 +"541";1767930765;18;19;25;11;24;23;16 +"542";1767931665;0;5;24;23;24;23;16 +"543";1767932565;13;21;24;4;25;23;16 +"544";1767933465;14;14;25;16;24;23;16 +"545";1767934365;25;15;25;23;24;23;16 +"546";1767935265;25;6;23;23;24;23;16 +"547";1767936165;0;6;23;2;24;23;16 +"548";1767937065;0;25;23;12;24;23;16 +"549";1767937965;25;25;23;12;24;23;16 +"550";1767938865;25;0;23;12;25;23;16 +"551";1767939765;25;15;23;1;25;23;16 +"552";1767940665;0;25;23;24;24;23;16 +"553";1767941565;25;6;23;2;24;23;16 +"554";1767942465;25;15;23;7;24;23;16 +"555";1767943365;24;22;23;8;24;23;16 +"556";1767944265;25;6;23;8;24;23;16 +"557";1767945165;25;25;23;7;19;23;16 +"558";1767946065;23;2;23;24;24;23;16 +"559";1767946965;17;19;12;2;19;4;16 +"560";1767947865;4;11;24;5;13;20;16 +"561";1767948765;11;3;11;1;5;7;16 +"562";1767949665;6;2;7;1;3;20;16 +"563";1767950565;9;3;10;1;5;4;16 +"564";1767951465;5;2;8;1;3;21;16 +"565";1767952365;5;2;8;1;4;22;16 +"566";1767953265;4;1;7;1;3;18;16 +"567";1767954165;4;1;6;1;3;18;17 diff --git a/exec/plot_measures.r b/exec/plot_measures.r index 56d70bc..2f2427b 100644 --- a/exec/plot_measures.r +++ b/exec/plot_measures.r @@ -3,11 +3,32 @@ # install.packages("ggplot2") library(ggplot2) +library(dplyr) setwd("~/Documents/PlatformIO/Projects/Robot_Go_West/arduino-photometrics/exec") # solar <- read.csv("../data/solar_pos_data/solar_data_2026-06-01_to_2026-06-15.csv", header=TRUE) -photo <- read.csv("../data/photo_measures/arduino_data_package_auto_20260107_143141.csv", header=TRUE) +# photo <- read.csv("../data/photo_measures/arduino_data_package_auto_20260107_143141.csv", header=TRUE) +# photo2 <- read.csv("../data/photo_measures/arduino_data_package_auto_20260109_102906.csv", header=TRUE) + +chemin <- "../data/photo_measures/" +fichiers <- list.files(path = chemin, pattern = "\\.csv$", full.names = TRUE) + +liste_data <- lapply(fichiers, read.csv, header = TRUE) +summary(liste_data) +print(typeof(liste_data)) + +# partial_list_data <- liste_data[1:2] +partial_list_data <- liste_data[3:6] +photo <- do.call(rbind, partial_list_data) + +max_val_sensor = 254 +photo <- photo %>% + mutate(across(starts_with("Photo_sensor"), ~ { + .x <- sqrt(.x) + # .x <- (.x*-1) + max_val_sensor + # .x <- as.numeric(scale(.x, center = TRUE, scale = TRUE)) + })) photo$time <- as.POSIXct(photo$Epoch) ggplot(data = photo, aes(x = time))+ diff --git a/exec/random_forest_predict.r b/exec/random_forest_predict.r index 8dbee22..30e5484 100644 --- a/exec/random_forest_predict.r +++ b/exec/random_forest_predict.r @@ -9,8 +9,8 @@ library(randomForest) setwd("~/Documents/PlatformIO/Projects/Robot_Go_West/arduino-photometrics/exec") # Load -solar <- read.csv("../data/solar_pos_data/solar_data_2026-01-05_to_2026-01-06.csv", header=TRUE) -photo <- read.csv("../data/arduino_data_package_auto_20260105_151537.csv", header=TRUE) +solar <- read.csv("../data/solar_pos_data/solar_data_2026-01-05_to_2026-01-10.csv", header=TRUE) +photo <- read.csv("../data/photo_measures/merged_photo_data.csv", header=TRUE) # Time type changes photo$time <- as.POSIXct(photo$Epoch) @@ -33,10 +33,11 @@ photo <- photo %>% # Transform data to improve learning during the training phase solar$sin_azimut <- sin(solar$azimut) -# Same +# Same but normalised values are square root to highlight little light variations max_val_sensor = 254 photo <- photo %>% mutate(across(starts_with("Photo_sensor"), ~ { + .x <- sqrt(.x) .x <- (.x*-1) + max_val_sensor .x <- as.numeric(scale(.x, center = TRUE, scale = TRUE)) })) @@ -56,6 +57,7 @@ filtered_solar <- solar %>% remove(solar) + # merge binded <- bind_cols(filtered_solar, photo) @@ -92,10 +94,28 @@ summary(chrono_test_data$azimut) # Model creation nb_tree = 100 -random_features <- random_train_data[, c("sin_day", "sin_hour", "cos_hour", "Photo_sensor0", "Photo_sensor1", "Photo_sensor2", "Photo_sensor4", "Photo_sensor5", "Temp_sensor0")] -random_features <- chrono_train_data[, c("sin_day", "sin_hour", "cos_hour", "Photo_sensor0", "Photo_sensor1", "Photo_sensor2", "Photo_sensor4", "Photo_sensor5", "Temp_sensor0")] + +random_model <- randomForest( + x = random_train_data[, c("sin_day", "sin_hour", "cos_hour", "Photo_sensor0", "Photo_sensor1", "Photo_sensor2", "Photo_sensor4", "Photo_sensor5", "Temp_sensor0")], + y = random_train_data$azimut, + ntree = nb_tree +) + +chrono_model <- randomForest( + x = chrono_train_data[, c("sin_day", "sin_hour", "cos_hour", "Photo_sensor0", "Photo_sensor1", "Photo_sensor2", "Photo_sensor4", "Photo_sensor5", "Temp_sensor0")], + y = chrono_train_data$azimut, + ntree = nb_tree +) + +test_random_predictions <- predict(random_model, newdata = random_test_data) +test_chrono_predictions <- predict(chrono_model, newdata = chrono_test_data) -random_model <- randomForest(azimut ~ random_features, data = random_train_data, ntree = nb_tree) -chrono_model <- randomForest(azimut ~ chrono_features, data = chrono_train_data, ntree = nb_tree) +test_random_results <- random_test_data +test_chrono_results <- chrono_test_data +test_chrono_results$predicted_azimut <- test_chrono_predictions +test_random_results$predicted_azimut <- test_random_predictions + +head(test_random_results[, c("azimut", "predicted_azimut")]) +head(test_chrono_results[, c("azimut", "predicted_azimut")]) diff --git a/exec/sun_pos.r b/exec/sun_pos.r index 8e169a2..0f721c2 100644 --- a/exec/sun_pos.r +++ b/exec/sun_pos.r @@ -9,7 +9,7 @@ lat <- 44.7912 lon <- -0.6078 tz <- "Europe/Paris" d_deb <- "2026-01-05" -d_fin <- "2026-01-06" +d_fin <- "2026-01-10" date_debut <- as.POSIXct(d_deb, tz = tz) date_fin <- as.POSIXct(d_fin, tz = tz) diff --git a/lib/storage/storage_interface.h b/lib/storage/storage_interface.h index eff151c..89acbc2 100644 --- a/lib/storage/storage_interface.h +++ b/lib/storage/storage_interface.h @@ -10,7 +10,7 @@ class Storage_interface private: static constexpr uint8_t OFFSET_MEASURES_SCH = 1, OFFSET_NB_PHOTO_SENSOR = 2, OFFSET_NB_TEMP_SENSOR = 3, OFFSET_PHOTO_MEASURES_SIZE = 4, OFFSET_TEMP_MEASURES_SIZE = 5, OFFSET_NB_MEASURES = 6, OFFSET_NEXT_PACKAGE = 8, OFFSET_START_DATA_MEASURES = 10; // unit in byte - static constexpr uint16_t MEGA_2560_EEPROM_SIZE = 32000; + static constexpr uint16_t MEGA_2560_EEPROM_SIZE = 4000; // bytes void clear_eeprom_at(uint16_t idx); diff --git a/src/main.cpp b/src/main.cpp index e20df17..d5c9720 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,10 +14,11 @@ const long BAUD_RATE = 9600; uint8_t ledPin = 2, alarm_pin = 19, decTemp = 4, nb_average_measure = 10; // nb decimal temperature printing const uint8_t nbPhotoSensor = 6, nbTempSensor = 1; uint8_t analogPin [nbPhotoSensor] = {A0, A1, A2 ,A3 ,A5 ,A6}, schedule = 0, photo_sensor_size = sizeof(uint8_t), temp_sensor_size = sizeof(uint8_t); -int32_t min_res [nbPhotoSensor] = {128, 160, 193, 96, 323, 96}; // Manual measurement of personal sensors +int32_t min_res [nbPhotoSensor] = {128- 30, 160-30, 193-80, 96-10, 323-180, 96-10}; // Manual measurement of personal sensors int32_t max_res [nbPhotoSensor] = {2062273, 5554006, 784809, 4755895, 1939035, 289546}; // Manual measurement of personal sensors uint32_t time_sec_sum; bool winter = true, timestamping = true, photo_sensor = true, temp_sensor = true, awake = true; +static byte state = true; // Communication flag, force the arduino to listen the serial port bool serial_com = false; @@ -71,10 +72,10 @@ void setup() { attachInterrupt(digitalPinToInterrupt(alarm_pin), elapsed_time, FALLING); } pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, state); } void loop() { - static byte state = false; if(awake){ DateTime now; @@ -154,7 +155,7 @@ void loop() { unixTime = myRTC.now().unixtime(); time_sec_sum = sec + min * 60 + hour * 3600 + day * 3600 * 24; - uint8_t delay_bet_measure = 1000; // one second + uint32_t delay_bet_measure = 1000; // one second uint8_t estimated_execution_time = 3; // rough estimation of execution time duration less measurement time : second uint32_t treshold_time = 30; @@ -195,6 +196,9 @@ void loop() { print_named_tab(converted_val_array[0], nbPhotoSensor, "int8_t normalised"); #endif Clock.checkIfAlarm(1); + + state = ~state; + digitalWrite(LED_BUILTIN, state); } #ifdef DEBUG