mirror of
https://gitlab.com/Luci_/arduino-photometrics.git
synced 2026-04-03 03:25:36 +02:00
Minor R script changes and tries, add synch starting time wakeup.
This commit is contained in:
parent
e1e48bdb44
commit
8a5738efed
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -10,6 +10,7 @@ serial
|
|||
*.drawio.bkp
|
||||
data/*
|
||||
.Rhistory
|
||||
.RData
|
||||
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/platformio,c++
|
||||
|
|
|
|||
|
|
@ -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))+
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
21
src/main.cpp
21
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();
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue