33 #include <Rcs_macros.h> 34 #include <Rcs_VecNd.h> 62 std::unique_lock<std::recursive_mutex> lock(
mutex);
64 RLOG(1,
"Already running!");
70 std::time_t t = std::time(
nullptr);
71 std::tm* now = std::localtime(&t);
72 std::ostringstream os;
73 os << (now->tm_year + 1900) <<
'-' << std::setfill(
'0') << std::setw(2) << (now->tm_mon + 1) <<
'-' <<
74 std::setfill(
'0') << std::setw(2) << now->tm_mday <<
'_' << (
fileCounter++) <<
".csv";
82 for (
auto& name : observationSpace->
getNames()) {
88 output <<
"\"" << std::endl;
91 buffer = MatNd_create(maxStepCount + 1, observationSpace->
getNames().size() + actionSpace->
getNames().size());
94 std::cout <<
"Logging started!" << std::endl;;
100 std::unique_lock<std::recursive_mutex> lock(
mutex);
107 for (
unsigned int row = 0; row <=
currentStep; ++row) {
112 for (
unsigned int col = 0; col <
buffer->n; ++col) {
126 std::cout <<
"Logging stopped!" << std::endl;;
132 std::unique_lock<std::recursive_mutex> lock(
mutex, std::try_to_lock);
133 if (!lock.owns_lock() || !
running) {
141 VecNd_copy(&lineBuffer[0], observation->ele, observation->m);
142 double nanAction[action->m];
143 for (
unsigned int i = 0; i < action->m; i++) {
146 VecNd_copy(&lineBuffer[observation->m], nanAction, action->m);
154 VecNd_copy(&lineBuffer[0], observation->ele, observation->m);
155 VecNd_copy(&lineBuffer[observation->m], action->ele, action->m);
unsigned int currentStep
Step counter in current logging run.
std::recursive_mutex mutex
void start(const BoxSpace *observationSpace, const BoxSpace *actionSpace, unsigned int maxStepCount)
MatNd * buffer
Buffer to avoid writing on realtime main thread.
unsigned int fileCounter
Automatic log file naming.
std::ofstream output
Current output stream.
volatile bool running
Flag if the logger is currently recording.
void record(const MatNd *observation, const MatNd *action)
const std::vector< std::string > & getNames() const