Robotsystem from Robot Group Leipzig: trackrobots.cpp Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# trackrobots.cpp

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  *                                                                         *
    00022  *   $Log: trackrobots.cpp,v $
    00023  *   Revision 1.1.2.2  2006/01/31 15:48:37  martius
    00024  *   *** empty log message ***
    00025  *
    00026  *   Revision 1.1.2.1  2005/11/16 11:24:27  martius
    00027  *   moved to selforg
    00028  *
    00029  *   Revision 1.4  2005/11/10 09:08:16  martius
    00030  *   trace has a name
    00031  *
    00032  *   Revision 1.3  2005/11/09 13:31:51  martius
    00033  *   GPL'ised
    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     // try to stat file and if it exists then try to append a number
    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 }