00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <stdlib.h>
00037 #include <time.h>
00038 #include <sys/stat.h>
00039
00040 #include "trackrobots.h"
00041 #include "abstractrobot.h"
00042
00043
00044 bool TrackRobot::open(const AbstractRobot* robot){
00045
00046 if(!robot) return false;
00047 if(trackPos || trackSpeed || trackOrientation){
00048
00049 if(file){
00050 fclose(file);
00051 }
00052
00053 char filename[100];
00054 char filename2[100];
00055 time_t t = time(0);
00056 struct stat filestat;
00057 strftime(filename, 50, "%F_%H-%M-%S_", localtime(&t));
00058 if(scene){
00059 strcat(filename,scene);
00060 strcat(filename,"_");
00061 }
00062 strcat(filename,robot->getName().c_str());
00063 sprintf(filename2, "%s.log", filename);
00064
00065 for(int i=1; i< 20; i++){
00066 if(stat(filename2, &filestat) == -1){
00067 break;
00068 }else{
00069 sprintf(filename2, "%s%i.log", filename, i );
00070 }
00071 }
00072
00073 file = fopen(filename2,"w");
00074
00075 if(!file) return false;
00076 fprintf(file, "#C t ");
00077 if(trackPos) fprintf(file, "x y z ");
00078 if(trackSpeed) fprintf(file, "vx vy vz ");
00079 if( trackOrientation) fprintf(file," Not Implemented");
00080 fprintf(file,"\n");
00081 }
00082 return true;
00083 }
00084
00085 void TrackRobot::track(AbstractRobot* robot) {
00086 if(!file || !robot) return;
00087 if(cnt % interval==0){
00088 fprintf(file, "%li ", cnt);
00089 if(trackPos){
00090 Position p = robot->getPosition();
00091 fprintf(file, "%g %g %g ", p.x, p.y, p.z);
00092 }
00093 if(trackSpeed){
00094 fprintf(stderr," SpeedTracking is not implemented yet");
00095 }
00096 if( trackOrientation){
00097 fprintf(stderr," OrientationTracking is not implemented yet");
00098 }
00099 fprintf(file, "\n");
00100 }
00101 cnt++;
00102 }
00103
00104 void TrackRobot::close() {
00105 if(file) fclose(file);
00106 file=0;
00107 }