Minor R script changes and tries, add synch starting time wakeup.

This commit is contained in:
Aurélien Gauthier 2026-01-08 21:25:57 +01:00
parent e1e48bdb44
commit 8a5738efed
4 changed files with 26 additions and 17 deletions

1
.gitignore vendored
View file

@ -10,6 +10,7 @@ serial
*.drawio.bkp *.drawio.bkp
data/* data/*
.Rhistory .Rhistory
.RData
# Created by https://www.toptal.com/developers/gitignore/api/platformio,c++ # Created by https://www.toptal.com/developers/gitignore/api/platformio,c++

View file

@ -7,7 +7,7 @@ library(ggplot2)
setwd("~/Documents/PlatformIO/Projects/Robot_Go_West/arduino-photometrics/exec") 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) # 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) photo$time <- as.POSIXct(photo$Epoch)
ggplot(data = photo, aes(x = time))+ ggplot(data = photo, aes(x = time))+

View file

@ -1,4 +1,4 @@
install.packages('randomForest') # install.packages('randomForest')
library(tidyverse) library(tidyverse)
library(ggplot2) library(ggplot2)
@ -28,8 +28,6 @@ photo <- photo %>%
rad_hour = decimal_hour * (2*pi / 24), rad_hour = decimal_hour * (2*pi / 24),
sin_hour = sin(rad_hour), sin_hour = sin(rad_hour),
cos_hour = cos(rad_hour) cos_hour = cos(rad_hour)
# TODO: sin of the day in the year
) )
# Transform data to improve learning during the training phase # Transform data to improve learning during the training phase
@ -73,7 +71,7 @@ set.seed(123)
binded <- binded %>% mutate(id = row_number()) binded <- binded %>% mutate(id = row_number())
random_train_data <- binded %>% sample_frac(0.80) 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_train_data$id <- NULL
random_test_data$id <- NULL random_test_data$id <- NULL
@ -94,11 +92,10 @@ summary(chrono_test_data$azimut)
# Model creation # Model creation
nb_tree = 100 nb_tree = 100
yes <- data.frame( random_features <- random_train_data[, c("sin_day", "sin_hour", "cos_hour", "Photo_sensor0", "Photo_sensor1", "Photo_sensor2", "Photo_sensor4", "Photo_sensor5", "Temp_sensor0")]
jour = binded$utime, random_features <- chrono_train_data[, c("sin_day", "sin_hour", "cos_hour", "Photo_sensor0", "Photo_sensor1", "Photo_sensor2", "Photo_sensor4", "Photo_sensor5", "Temp_sensor0")]
= 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_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)

View file

@ -37,7 +37,7 @@ RTClib myRTC;
DS3231 Clock; DS3231 Clock;
void elapsed_time(); void elapsed_time();
void alarm_timer(); void alarm_timer(bool b_synch);
void setup() { void setup() {
Wire.begin(); Wire.begin();
@ -49,8 +49,8 @@ void setup() {
s_manager.setup(nbPhotoSensor, analogPin); 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); sto_intrf.add_last_package(timestamping, true, photo_sensor, temp_sensor, schedule, nbPhotoSensor, nbTempSensor, photo_sensor_size, temp_sensor_size);
bool b_synch = true;
alarm_timer(); 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) // 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 byte min_alarm2 = 0xFF; // a value that will never match the time
@ -135,8 +135,9 @@ void loop() {
delay(10); delay(10);
} }
} }
bool b_synch = false;
// Set next weak up // Set next weak up
alarm_timer(); alarm_timer(b_synch);
#ifdef DEBUG #ifdef DEBUG
printDate(Clock, decTemp); printDate(Clock, decTemp);
@ -204,14 +205,24 @@ void loop() {
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 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 #ifdef DEBUG
// Debug deep sleep timer // 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 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 #endif
uint32_t unix_time = RTClib::now().unixtime(); 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); //unix_time += sec + 60*((60*((60*24) + hour)) + min);
DateTime alarmDT = DateTime(unix_time); DateTime alarmDT = DateTime(unix_time);