From 8a5738efed441405a679d00ce8815444c96c5e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Gauthier?= Date: Thu, 8 Jan 2026 21:25:57 +0100 Subject: [PATCH] Minor R script changes and tries, add synch starting time wakeup. --- .gitignore | 1 + exec/plot_measures.r | 2 +- exec/random_forest_predict.r | 17 +++++++---------- src/main.cpp | 23 +++++++++++++++++------ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 43b451b..d8047b5 100755 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ serial *.drawio.bkp data/* .Rhistory +.RData # Created by https://www.toptal.com/developers/gitignore/api/platformio,c++ diff --git a/exec/plot_measures.r b/exec/plot_measures.r index fd1d831..56d70bc 100644 --- a/exec/plot_measures.r +++ b/exec/plot_measures.r @@ -7,7 +7,7 @@ library(ggplot2) 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/arduino_data_package_auto_20260105_151537.csv", header=TRUE) +photo <- read.csv("../data/photo_measures/arduino_data_package_auto_20260107_143141.csv", header=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 08cb28c..8dbee22 100644 --- a/exec/random_forest_predict.r +++ b/exec/random_forest_predict.r @@ -1,4 +1,4 @@ -install.packages('randomForest') +# install.packages('randomForest') library(tidyverse) library(ggplot2) @@ -28,8 +28,6 @@ photo <- photo %>% rad_hour = decimal_hour * (2*pi / 24), sin_hour = sin(rad_hour), cos_hour = cos(rad_hour) - - # TODO: sin of the day in the year ) # Transform data to improve learning during the training phase @@ -73,7 +71,7 @@ set.seed(123) binded <- binded %>% mutate(id = row_number()) random_train_data <- binded %>% sample_frac(0.80) -random_test_data <- anti_join(binded, train_data, by = "id") +random_test_data <- anti_join(binded, random_train_data, by = "id") random_train_data$id <- NULL random_test_data$id <- NULL @@ -94,11 +92,10 @@ summary(chrono_test_data$azimut) # Model creation nb_tree = 100 -yes <- data.frame( - jour = binded$utime, - = binded$Epoch -) -random_model <- randomForest(azimut ~ , data = random_train_data, ntree = nb_tree) -chrono_model <- randomForest(azimut ~ , data = chrono_train_data, ntree = nb_tree) +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(azimut ~ random_features, data = random_train_data, ntree = nb_tree) +chrono_model <- randomForest(azimut ~ chrono_features, data = chrono_train_data, ntree = nb_tree) + diff --git a/src/main.cpp b/src/main.cpp index c2dfe43..e20df17 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,7 @@ RTClib myRTC; DS3231 Clock; void elapsed_time(); -void alarm_timer(); +void alarm_timer(bool b_synch); void setup() { Wire.begin(); @@ -49,8 +49,8 @@ void setup() { s_manager.setup(nbPhotoSensor, analogPin); sto_intrf.add_last_package(timestamping, true, photo_sensor, temp_sensor, schedule, nbPhotoSensor, nbTempSensor, photo_sensor_size, temp_sensor_size); - - alarm_timer(); + bool b_synch = true; + alarm_timer(b_synch); // NOTE : DS3231 lib advise to set the unused alarm to an inaccessible time to avoid unwanted signal (even alarm set off) byte min_alarm2 = 0xFF; // a value that will never match the time @@ -135,8 +135,9 @@ void loop() { delay(10); } } + bool b_synch = false; // Set next weak up - alarm_timer(); + alarm_timer(b_synch); #ifdef DEBUG printDate(Clock, decTemp); @@ -204,14 +205,24 @@ void loop() { LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); } -void alarm_timer(){ +/** +* @brief alarm_timer +* * init next alarm and synchronise alarm at the start of the next hour when b_synch is true +* +* * @param b_synch @c Bool +*/ +void alarm_timer(bool b_synch){ #ifdef DEBUG // Debug deep sleep timer sec = 10; min = 0; hour = 0; day = 0; // Don't set under 5 sec, execution code time duration is around 2 or 3 seconde with prints #endif uint32_t unix_time = RTClib::now().unixtime(); - unix_time += sec + min * 60 + hour * 3600 + day * 24 * 3600; + if(b_synch){ + unix_time += 3600 - (unix_time%3600); + }else{ + unix_time += sec + min * 60 + hour * 3600 + day * 24 * 3600; + } //unix_time += sec + 60*((60*((60*24) + hour)) + min); DateTime alarmDT = DateTime(unix_time);