To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 3c25f047 authored by remartin's avatar remartin
Browse files

Nanosecond precision timestamps for logging both pan DMX and intensity values to .txt files.

parent 49c2e8df
......@@ -46,6 +46,7 @@
#include <cmath>
#include <sstream>
#include <ctime>
#include <chrono>
#include <iostream>
#include <termios.h> //For serial communication
......@@ -89,7 +90,7 @@ public:
void testPTupdater();
// saves applied pan values in a file, along with a timestamp
void lineWithLogging(int panWidth, int brightness, int zoom , double speed);
void lineWithLogging(int panWidth, int brightness, int zoom , double speed, bool loadTimeToSynchro);
......
# Copyright (C) 2018, ETH Zurich, D-dddITET
# Martin Reinhard remartin @ee.ethz.ch
#
# This file is part of D-FaLL-System.
#
# D-FaLL-System is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# D-FaLL-System is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with D-FaLL-System. If not, see <http://www.gnu.org/licenses/>.
#
#
# ----------------------------------------------------------------------------------
# DDDD FFFFF L L SSSS Y Y SSSS TTTTT EEEEE M M
# D D F aaa L L S Y Y S T E MM MM
# D D --- FFFF a a L L --- SSS Y SSS T EEE M M M
# D D F a aa L L S Y S T E M M
# DDDD F aa a LLLL LLLL SSSS Y SSSS T EEEEE M M
#
#
# DESCRIPTION:
# Compiles the spotlight files only. Used for testing purposes.
# Run with 'bash customCooker.sh'.
#
# ----------------------------------------------------------------------------------
rm intensityLogger
g++ -std=c++11 intensityLogger.cpp -o intensityLogger
./intensityLogger
......@@ -33,5 +33,5 @@
rm uwb_light
g++ ../../src/spotlightManager.cpp ../../src/SerialLight.cpp UWBL_testing_main.cpp -o uwb_light
g++ -std=c++11 ../../src/spotlightManager.cpp ../../src/SerialLight.cpp UWBL_testing_main.cpp -o uwb_light
./uwb_light
......@@ -22,35 +22,44 @@ void intensityLogger::run(){
ofstream intensityLog;
intensityLog.open("loggedIntensityValues.txt", ofstream::out | ofstream::trunc);
intensityLog << "Stuff detected by the light sensor. \n";
intensityLog << "time\tNormed Intensity\n";
intensityLog.flush();
printf("In detection mode. \n");
bool parsing = false;
string storing = "";
int something;
string storing;
char hua;
long timestamp;
std::chrono::high_resolution_clock::time_point startTime; // = std::chrono::high_resolution_clock::now();
while(_isConnected){
something = read(tty_fd, &hua, 1);
if(something){
if(read(tty_fd, &hua, 1) > 0){
//printf("Received something: %c \n", hua);
if(!parsing && hua == 'G'){
parsing = true;
//printf("Got something. \n");
//printf("Starting to save stuff. \n");
}else if(parsing){ // receiving good stuff
if(hua == 'G'){
if(hua == 'G'){ // save.
chrono::high_resolution_clock::time_point cbTime = chrono::high_resolution_clock::now();
timestamp = chrono::duration_cast<chrono::nanoseconds>(cbTime-startTime).count();
// writing to log
//std::chrono::high_resolution_clock::time_point cbTime = std::chrono::high_resolution_clock::now();
//timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(cbTime - 0).count();
//timestamp =
intensityLog << time(0) << "\t" << storing << "\n";
intensityLog << timestamp << "\t" << storing << "\n";
intensityLog.flush();
storing = "";
parsing = false;
//printf("Ending saving procedure. \n");
}else{
storing += hua;
if(isdigit(hua)){// avoid being out of sync ('between' flags).
storing.push_back(hua);
}else{
printf("Was out of sync. Correcting that. \n");
storing = "";
parsing = false;
}
}
}else{ // Rubbish received.
}
......
......@@ -15,6 +15,7 @@
#include <string>
#include <vector>
#include <ctime>
#include <chrono>
#include <fstream>
......
......@@ -506,11 +506,12 @@ void spotlightManager::testPTupdater(){
}
// saves applied pan values in a file, along with a timestamp
void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, double speed){
void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, double speed, bool loadTimeToSynchro){
ofstream panLog;
panLog.open("loggedPanValues.txt", ofstream::out | ofstream::trunc);
panLog << "Dataset with " << brightness << " brightness, " << zoom << " zoom, " << speed << " speed. \n";
panLog << "time\tDMX pan\t"<<"Dataset with " << brightness << " brightness, " << zoom << " zoom, " << speed << " speed. \n";
panLog.flush();
setPTmanually(false);
......@@ -527,15 +528,43 @@ void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, d
bool bumerang = true;
double precisePan = dmxValues[3] + dmxValues[4]/255.0;
int coarse;
long timestamp;
std::chrono::high_resolution_clock::time_point startTime;
/*
if(loadTimeToSynchro){
// thanks to https://stackoverflow.com/questions/36963373/saving-and-loading-stdchronotime-point-to-file
ifstream ifs;
ifs.open("synchroFile.txt", std::ios::in | std::ios::binary);
time_t file_time;
ifs >> file_time;
ifs.close();
//std::cout << std::ctime(&file_time);
//auto cache_valid_time = std::chrono::system_clock::from_time_t(file_time);
startTime = chrono::high_resolution_clock::from_time_t(file_time);
}else{
startTime = std::chrono::high_resolution_clock::now();
}
*/
while(true){
// one pass
for(int mm = 0; mm < steps; mm++){
if(bumerang){precisePan+=panStep;}else{precisePan-=panStep;}
// logging
panLog << time(0) << "\t" << precisePan << "\n";
//std::chrono::high_resolution_clock::time_point cbTime = std::chrono::high_resolution_clock::now();
//timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(cbTime - 0).count();
//timestamp =
chrono::high_resolution_clock::time_point cbTime = chrono::high_resolution_clock::now();
timestamp = chrono::duration_cast<chrono::nanoseconds>(cbTime-startTime).count();
panLog << timestamp << "\t" << precisePan << "\n";
// panLog << time(0) << "\t" << precisePan << "\n";
panLog.flush();
// sending
coarse = floor(precisePan);
dmxValues[3] = coarse;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment