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.h,v $ 00023 * Revision 1.10 2009/08/04 14:55:22 jhoffmann 00024 * Remove two memory leaks, but fix needs review for the open file pointers 00025 * 00026 * Revision 1.9 2008/09/12 10:22:28 martius 00027 * set cnt to 1 to have round times in log file when using interval >1 00028 * 00029 * Revision 1.8 2008/04/18 09:49:41 guettler 00030 * Added the OdeAgent as a friend class 00031 * 00032 * Revision 1.7 2007/08/29 11:33:20 martius 00033 * simulation time enters logfile 00034 * 00035 * Revision 1.6 2007/06/21 16:18:57 martius 00036 * do not free scene -> Segfault 00037 * 00038 * Revision 1.5 2007/04/05 15:14:15 martius 00039 * angular speed tracking 00040 * 00041 * Revision 1.4 2006/08/04 15:16:13 martius 00042 * documentation 00043 * 00044 * Revision 1.3 2006/08/02 09:33:21 martius 00045 * Todo updated 00046 * 00047 * Revision 1.2 2006/07/14 12:24:02 martius 00048 * selforg becomes HEAD 00049 * 00050 * Revision 1.1.2.3 2006/03/31 16:18:32 fhesse 00051 * tracing in oderagent via trackrobots 00052 * 00053 * Revision 1.1.2.2 2006/03/30 12:33:15 fhesse 00054 * trace via trackrobot 00055 * 00056 * Revision 1.1.2.1 2005/11/16 11:24:27 martius 00057 * moved to selforg 00058 * 00059 * Revision 1.4 2005/11/10 09:08:26 martius 00060 * trace has a name 00061 * 00062 * Revision 1.3 2005/11/09 13:31:51 martius 00063 * GPL'ised 00064 * 00065 ***************************************************************************/ 00066 #ifndef __TRACKROBOTS_H 00067 #define __TRACKROBOTS_H 00068 00069 #include <stdio.h> 00070 #include <string.h> 00071 00072 class AbstractRobot; 00073 class Agent; 00074 00075 namespace lpzrobots { 00076 class OdeAgent; 00077 } 00078 00079 /** 00080 This class provides tracking possibilies of a robot. 00081 The position, speed, and orientation can be logged. 00082 */ 00083 class TrackRobot { 00084 public: 00085 00086 friend class Agent; 00087 friend class lpzrobots::OdeAgent; 00088 00089 /// constructor for no tracking at all 00090 TrackRobot() 00091 { 00092 trackPos = false; 00093 trackSpeed = false; 00094 trackOrientation = false; 00095 displayTrace = false; 00096 interval = 1; 00097 scene = 0; 00098 file = 0; 00099 cnt = 1; 00100 memset(filename, 0, 256); 00101 00102 } 00103 00104 /** Constructor that allows individial setting of tracking options. 00105 The tracked data is written into a file with the current date and time appended by a name given by scene. 00106 @param trackPos if true the trace (position vectors) of the robot are logged 00107 @param trackSpeed if true the speed vectors (linear and angular) of the robot are logged 00108 @param trackOrientation if true the orientation matrices of the robot are logged 00109 @param displayTrace if true the trace of the robot should be displayed (used in ODE simulations) 00110 @param scene name of the scene (is appended to log file name) 00111 @param interval timesteps between consequent logging events (default 1) 00112 */ 00113 TrackRobot(bool trackPos, bool trackSpeed, bool trackOrientation, bool displayTrace, 00114 const char* scene = "", int interval = 1) 00115 { 00116 this->trackPos = trackPos; 00117 this->trackSpeed = trackSpeed; 00118 this->trackOrientation = trackOrientation; 00119 this->displayTrace = displayTrace; 00120 this->interval = interval; 00121 this->scene = strdup(scene); 00122 file = 0; 00123 cnt = 1; 00124 memset(filename, 0, 256); 00125 } 00126 00127 00128 TrackRobot(const TrackRobot &rhs) 00129 { 00130 deepcopy(*this, rhs); 00131 } 00132 00133 const TrackRobot& operator=(const TrackRobot &rhs) 00134 { 00135 if ( this != &rhs ) 00136 { 00137 if (scene) 00138 free(scene); 00139 scene = 0; 00140 00141 if (file) 00142 fclose(file); 00143 file=0; 00144 00145 deepcopy(*this, rhs); 00146 } 00147 00148 return *this; 00149 } 00150 00151 ~TrackRobot() 00152 { 00153 if (file) 00154 fclose(file); 00155 file = 0; 00156 00157 //Something goes wrong here, but what? -> also with copy constructor no improvement, see above 00158 if (scene) 00159 free(scene); 00160 scene = 0; 00161 } 00162 00163 /// returns whether tracing is activated 00164 bool isDisplayTrace() const {return displayTrace;}; 00165 00166 protected: 00167 bool open(const AbstractRobot* robot); 00168 void track(AbstractRobot* robot, double time); 00169 void close(); 00170 00171 protected: 00172 bool trackPos; 00173 bool trackSpeed; 00174 bool trackOrientation; 00175 bool displayTrace; 00176 00177 int interval; 00178 FILE* file; 00179 char* scene; 00180 long cnt; 00181 00182 private: 00183 char filename[256]; 00184 static void deepcopy (TrackRobot &lhs, const TrackRobot &rhs); 00185 00186 }; 00187 00188 #endif