mirror of
https://gitlab.com/Luci_/arduino-photometrics.git
synced 2026-04-03 11:35:37 +02:00
generation of solar data file in R and some changes are applied for average measurement
This commit is contained in:
parent
f7adfbe25f
commit
f9cc9679cc
|
|
@ -1,17 +0,0 @@
|
||||||
Epoch,Photo_sensor0,Photo_sensor1,Photo_sensor2,Photo_sensor3,Photo_sensor4,Photo_sensor5,Temp_sensor0
|
|
||||||
1765972042,5,2,15,2,5,36,21
|
|
||||||
1765972052,6,2,15,2,6,37,21
|
|
||||||
1765972062,5,2,15,2,5,35,21
|
|
||||||
1765972072,5,2,15,2,5,35,21
|
|
||||||
1765972082,5,2,15,2,5,35,21
|
|
||||||
1765972092,5,2,15,2,5,36,21
|
|
||||||
1765972102,5,2,15,2,5,36,21
|
|
||||||
1765972112,5,2,15,2,5,36,21
|
|
||||||
1765972122,5,2,15,2,5,36,21
|
|
||||||
1765972132,5,2,15,2,6,36,21
|
|
||||||
1765972142,5,2,15,2,6,36,21
|
|
||||||
1765972152,5,2,15,2,6,37,21
|
|
||||||
1765972162,6,2,15,2,6,37,21
|
|
||||||
1765972172,6,2,16,2,6,38,21
|
|
||||||
1765972182,6,2,15,2,6,38,21
|
|
||||||
1765972192,6,2,16,2,6,38,21
|
|
||||||
|
39
exec/sun_pos.r
Normal file
39
exec/sun_pos.r
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# install.packages("suntools")
|
||||||
|
# install.packages("lubridate")
|
||||||
|
|
||||||
|
library(suntools)
|
||||||
|
library(lubridate)
|
||||||
|
|
||||||
|
lat <- 44.7912
|
||||||
|
lon <- -0.6078
|
||||||
|
tz <- "Europe/Paris"
|
||||||
|
d_deb <- "2026-06-01"
|
||||||
|
d_fin <- "2026-06-15"
|
||||||
|
date_debut <- as.POSIXct(d_deb, tz = tz)
|
||||||
|
date_fin <- as.POSIXct(d_fin, tz = tz)
|
||||||
|
|
||||||
|
sequence_temps <- seq(from = date_debut, to = date_fin, by = "15 min")
|
||||||
|
|
||||||
|
coords <- matrix(c(lon, lat), nrow = 1)
|
||||||
|
|
||||||
|
positions <- solarpos(coords, sequence_temps)
|
||||||
|
|
||||||
|
df_soleil <- data.frame(
|
||||||
|
timestamp = sequence_temps,
|
||||||
|
azimut = positions[, 1],
|
||||||
|
elevation = positions[, 2]
|
||||||
|
)
|
||||||
|
|
||||||
|
csv_name <-c("solar_data_", d_deb ,"_to_", d_fin ,".csv")
|
||||||
|
csv_name <-paste(csv_name, collapse = "")
|
||||||
|
print(csv_name)
|
||||||
|
|
||||||
|
store_path <- "../data/solar_pos_data/"
|
||||||
|
csv_path_name <- paste(c(store_path, csv_name), collapse = "")
|
||||||
|
print(csv_path_name)
|
||||||
|
|
||||||
|
write.csv(df_soleil, csv_path_name, row.names = FALSE)
|
||||||
|
|
||||||
|
print(paste(csv_name,"succesfully generated"))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -335,18 +335,22 @@ void Storage_interface::add_last_package(bool timestamp, bool is_final_set, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// The function check if the stored measure structure match with the header
|
// The function check if the stored measure structure match with the header
|
||||||
|
// TODO: write an cleaner version of the add measure (check again if template can be used)
|
||||||
void Storage_interface::add_measure(uint8_t* array_photo_val, uint8_t* array_temp_val, uint32_t timestamp, uint8_t nb_photo, uint8_t nb_temp){
|
void Storage_interface::add_measure(uint8_t* array_photo_val, uint8_t* array_temp_val, uint32_t timestamp, uint8_t nb_photo, uint8_t nb_temp){
|
||||||
uint16_t p_last_header, free_space, idx, next_free_space, nb_measure;
|
uint16_t p_last_header, free_space, idx, next_free_space, nb_measure;
|
||||||
|
|
||||||
|
|
||||||
get_last_header_nbpackage(&p_last_header);
|
get_last_header_nbpackage(&p_last_header);
|
||||||
|
|
||||||
get_next_package(p_last_header, &free_space);
|
get_next_package(p_last_header, &free_space);
|
||||||
get_nb_measures(p_last_header, &nb_measure);
|
get_nb_measures(p_last_header, &nb_measure);
|
||||||
nb_measure++;
|
nb_measure++;
|
||||||
set_nb_measures(p_last_header, &nb_measure);
|
set_nb_measures(p_last_header, &nb_measure);
|
||||||
if(free_space > (MEGA_2560_EEPROM_SIZE - 11)) // avoid EEPROM overflow
|
|
||||||
|
// TODO: Adapt to storage size need by the current add_measure
|
||||||
|
uint8_t timestamp_byte_size = 4;
|
||||||
|
if(free_space > (MEGA_2560_EEPROM_SIZE - (timestamp_byte_size + nb_photo + nb_measure))) // avoid EEPROM overflow
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EEPROM.put(free_space, timestamp);
|
EEPROM.put(free_space, timestamp);
|
||||||
idx = free_space + sizeof(uint32_t);
|
idx = free_space + sizeof(uint32_t);
|
||||||
for(int i = 0; i < nb_photo; i++, idx += sizeof(uint8_t)){
|
for(int i = 0; i < nb_photo; i++, idx += sizeof(uint8_t)){
|
||||||
|
|
|
||||||
18
src/main.cpp
18
src/main.cpp
|
|
@ -16,6 +16,7 @@ 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);
|
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, 160, 193, 96, 323, 96}; // Manual measurement of personal sensors
|
||||||
int32_t max_res [nbPhotoSensor] = {2062273, 5554006, 784809, 4755895, 1939035, 289546}; // 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;
|
bool winter = true, timestamping = true, photo_sensor = true, temp_sensor = true, awake = true;
|
||||||
|
|
||||||
// Communication flag, force the arduino to listen the serial port
|
// Communication flag, force the arduino to listen the serial port
|
||||||
|
|
@ -143,6 +144,7 @@ void loop() {
|
||||||
s_manager.print_min_max_res();
|
s_manager.print_min_max_res();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// average measurement part
|
||||||
int32_t res_array[nb_average_measure][nbPhotoSensor];
|
int32_t res_array[nb_average_measure][nbPhotoSensor];
|
||||||
uint32_t unixTime;
|
uint32_t unixTime;
|
||||||
int16_t mapped_val_array[nb_average_measure][nbPhotoSensor];
|
int16_t mapped_val_array[nb_average_measure][nbPhotoSensor];
|
||||||
|
|
@ -150,12 +152,23 @@ void loop() {
|
||||||
|
|
||||||
unixTime = myRTC.now().unixtime();
|
unixTime = myRTC.now().unixtime();
|
||||||
|
|
||||||
|
time_sec_sum = sec + min * 60 + hour * 3600 + day * 3600 * 24;
|
||||||
|
uint8_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;
|
||||||
|
|
||||||
|
// average calculation time between measurement to adapt classical exec and debug exec delays
|
||||||
|
if(time_sec_sum < treshold_time){
|
||||||
|
delay_bet_measure = ((time_sec_sum - estimated_execution_time) / nb_average_measure) * 1000; // conversion sec to milli sec
|
||||||
|
}
|
||||||
|
|
||||||
temp[0] = (uint8_t) Clock.getTemperature();
|
temp[0] = (uint8_t) Clock.getTemperature();
|
||||||
for(int i = 0; i < nb_average_measure; i++){
|
for(int i = 0; i < nb_average_measure; i++){
|
||||||
s_manager.get_resistances(res_array[i], nbPhotoSensor);
|
s_manager.get_resistances(res_array[i], nbPhotoSensor);
|
||||||
|
|
||||||
tr.map_r(min_res, max_res, res_array[i], mapped_val_array[i], nbPhotoSensor);
|
tr.map_r(min_res, max_res, res_array[i], mapped_val_array[i], nbPhotoSensor);
|
||||||
tr.res_value_int32_to_uint8(mapped_val_array[i], converted_val_array[i], nbPhotoSensor);
|
tr.res_value_int32_to_uint8(mapped_val_array[i], converted_val_array[i], nbPhotoSensor);
|
||||||
|
delay(delay_bet_measure);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 1; i < nb_average_measure; i++){
|
for(int i = 1; i < nb_average_measure; i++){
|
||||||
|
|
@ -166,11 +179,12 @@ void loop() {
|
||||||
for(int y = 0; y < nbPhotoSensor; y++){
|
for(int y = 0; y < nbPhotoSensor; y++){
|
||||||
converted_val_array[0][y] = converted_val_array[0][y] / nb_average_measure;
|
converted_val_array[0][y] = converted_val_array[0][y] / nb_average_measure;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("Readed values from sensors:");
|
Serial.println("Readed values from sensors:");
|
||||||
print_named_tab(converted_val_array[0], nbPhotoSensor, "int8_t normalised");
|
print_named_tab(converted_val_array[0], nbPhotoSensor, "int8_t normalised");
|
||||||
#endif
|
#endif
|
||||||
|
// TODO : apply same change of max limit to avoid EEPROM overflow
|
||||||
sto_intrf.add_measure(converted_val_array[0], temp, unixTime, nbPhotoSensor, nbTempSensor);
|
sto_intrf.add_measure(converted_val_array[0], temp, unixTime, nbPhotoSensor, nbTempSensor);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
@ -193,7 +207,7 @@ void loop() {
|
||||||
void alarm_timer(){
|
void alarm_timer(){
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Debug deep sleep timer
|
// Debug deep sleep timer
|
||||||
sec = 10; min = 0; hour = 0; day = 0; // Don't set under 4 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();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue