Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Control Logging #55

Open
wants to merge 2 commits into
base: indigo-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion src/autopilot/ControlNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,56 @@ void ControlNode::publishCommand(std::string c)

void ControlNode::toogleLogging()
{
// logging has yet to be integrated.
// first: always check for /log dir
struct stat st;
if(stat((packagePath+std::string("/logs")).c_str(),&st) != 0)
mkdir((packagePath+std::string("/logs")).c_str(),S_IXGRP | S_IXOTH | S_IXUSR | S_IRWXU | S_IRWXG | S_IROTH);

char buf[200];
bool quitLogging = false;
if(logfileControl == 0)
{
currentLogID = ((long)time(0))*100+(getMS()%100); // time(0) + ms
startedLogClock = getMS();
ROS_INFO("\n\nENABLED LOGGING to %s/logs/%ld\n\n\n",packagePath.c_str(),currentLogID);
sprintf(buf,"%s/logs/%ld",packagePath.c_str(),currentLogID);
mkdir(buf, S_IXGRP | S_IXOTH | S_IXUSR | S_IRWXU | S_IRWXG | S_IROTH);


sprintf(buf,"u l ENABLED LOGGING to %s/logs/%ld",packagePath.c_str(),currentLogID);
publishCommand(buf);
}
else
quitLogging = true;



// IMU
pthread_mutex_lock(&logControl_CS);
if(logfileControl == 0)
{
logfileControl = new std::ofstream();
sprintf(buf,"%s/logs/%ld/logControl.txt",packagePath.c_str(),currentLogID);
logfileControl->open (buf);
}
else
{
logfileControl->flush();
logfileControl->close();
delete logfileControl;
logfileControl = NULL;
}
pthread_mutex_unlock(&logControl_CS);


if(quitLogging)
{
printf("\n\nDISABLED LOGGING (logged %ld sec)\n\n\n",(getMS()-startedLogClock+500)/1000);
char buf2[200];
sprintf(buf,"%s/logs/%ld",packagePath.c_str(),currentLogID);
sprintf(buf2,"%s/logs/%ld-%lds",packagePath.c_str(),currentLogID,(getMS()-startedLogClock+500)/1000);
rename(buf,buf2);
}
}

void ControlNode::sendControlToDrone(ControlCommand cmd)
Expand Down
3 changes: 3 additions & 0 deletions src/autopilot/ControlNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "tum_ardrone/SetStayWithinDistance.h"
#include "tum_ardrone/SetStayTime.h"
#include "std_srvs/Empty.h"
#include <fstream>

class DroneKalmanFilter;
class MapView;
Expand Down Expand Up @@ -146,6 +147,8 @@ struct ControlNode
// logging stuff
std::ofstream* logfileControl;
static pthread_mutex_t logControl_CS;
long currentLogID;
long startedLogClock;
void toogleLogging(); // switches logging on or off.

// other internals
Expand Down
14 changes: 14 additions & 0 deletions src/autopilot/DroneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ ControlCommand DroneController::update(tum_ardrone::filter_stateConstPtr state)
ROS_WARN("Warning: no valid target, sending hover.");
}

if(node->logfileControl != NULL)
{
pthread_mutex_lock(&node->logControl_CS);
if(node->logfileControl != NULL)
{
(*(node->logfileControl)) << lastTimeStamp << " ";

for( int i = 0; i < logInfo.size(); i++)
(*(node->logfileControl)) << logInfo[i] << " ";

(*(node->logfileControl)) << "\n";
}
pthread_mutex_unlock(&node->logControl_CS);
}
last_err = new_err;
return lastSentControl;
}
Expand Down