Robot Simulator of the Robotics Group for Self-Organization of Control: trackrobots.h Source File

# trackrobots.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __TRACKROBOTS_H
    00025 #define __TRACKROBOTS_H
    00026
    00027 #include <stdio.h>
    00028 #include <string>
    00029
    00030 #include <selforg/trackable.h>
    00031
    00032 class AbstractRobot;
    00033 class Agent;
    00034
    00035 namespace lpzrobots {
    00036   class OdeAgent;
    00037   class TraceDrawer;
    00038 }
    00039
    00040 struct TrackRobotConf {
    00041   bool   trackPos;
    00042   bool   trackSpeed;
    00043   bool   trackOrientation;
    00044   bool   displayTrace;
    00045   double displayTraceDur;       ///< duration in second to display the trace
    00046   double displayTraceThickness;
    00047   bool   writeFile;             ///< whether to write a log file
    00048
    00049   int interval;
    00050   std::string scene;
    00051   int id;
    00052 };
    00053
    00054 /**
    00055    This class provides tracking possibilies of a robot.
    00056    The position, speed, and orientation can be logged.
    00057    This is used by the agent class, @see Agent::setTrackOptions()
    00058 */
    00059 class TrackRobot {
    00060 public:
    00061
    00062   friend class Agent;
    00063   friend class lpzrobots::OdeAgent;
    00064   friend class lpzrobots::TraceDrawer;
    00065
    00066   /// constructor for no tracking at all
    00067   TrackRobot(TrackRobotConf conf = getDefaultConf())
    00068     : conf(conf)
    00069   {
    00070     file              = 0;
    00071     cnt               = 1;
    00072   }
    00073
    00074   static TrackRobotConf getDefaultConf(){
    00075     TrackRobotConf conf;
    00076     conf.trackPos              = true;
    00077     conf.trackSpeed            = false;
    00078     conf.trackOrientation      = false;
    00079     conf.displayTrace          = false;
    00080     conf.displayTraceDur       = 60;
    00081     conf.displayTraceThickness = 0.05;
    00082     conf.interval              = 1;
    00083     conf.writeFile             = true;
    00084     //    conf.scene           = "";
    00085     conf.id                    = -1; // disabled
    00086     return conf;
    00087   }
    00088
    00089
    00090   /** Constructor that allows individial setting of tracking options.
    00091       The tracked data is written into a file with the current date and time appended by a name given by scene.
    00092       @param trackPos if true the trace (position vectors) of the robot are logged
    00093       @param trackSpeed if true the speed vectors (linear and angular) of the robot are logged
    00094       @param trackOrientation if true the orientation matrices  of the robot are logged
    00095       @param displayTrace if true the trace of the robot should be displayed (used in ODE simulations)
    00096       @param scene name of the scene (is appended to log file name)
    00097       @param interval timesteps between consequent logging events (default 1)
    00098    */
    00099   TrackRobot(bool trackPos, bool trackSpeed, bool trackOrientation, bool displayTrace,
    00100              const char* scene = "", int interval = 1)
    00101   {
    00102     conf = getDefaultConf();
    00103     conf.trackPos         = trackPos;
    00104     conf.trackSpeed       = trackSpeed;
    00105     conf.trackOrientation = trackOrientation;
    00106     conf.displayTrace     = displayTrace;
    00107     conf.interval         = interval;
    00108     conf.scene            = scene;
    00109     conf.id               = 0;
    00110     file = 0;
    00111     cnt  = 1;
    00112   }
    00113
    00114   // TrackRobot(const TrackRobot &rhs)
    00115   // {
    00116   //   deepcopy(*this, rhs);
    00117   // }
    00118
    00119   // const TrackRobot& operator=(const TrackRobot &rhs)
    00120   // {
    00121   //   if ( this != &rhs )
    00122   //   {
    00123   //     if (file)
    00124   //       fclose(file);
    00125   //     file=0;
    00126
    00127   //     deepcopy(*this, rhs);
    00128   //   }
    00129
    00130   //   return *this;
    00131   // }
    00132
    00133   ~TrackRobot()
    00134   {
    00135     // if (file)
    00136     //   fclose(file);
    00137     // file = 0;
    00138   }
    00139
    00140   /// returns whether tracing is activated
    00141   bool isDisplayTrace() const {return conf.displayTrace;};
    00142
    00143   /// returns whether something is to be tracked
    00144   bool isTrackingSomething() const {
    00145     return conf.trackPos || conf.trackOrientation || conf.trackSpeed;
    00146   };
    00147
    00148   TrackRobotConf conf;
    00149
    00150  protected:
    00151   bool open(const Trackable* robot);
    00152   void track(const Trackable* robot, double time);
    00153   void close();
    00154
    00155  protected:
    00156   FILE* file;
    00157   long cnt;
    00158
    00159  // private:
    00160  //   static void deepcopy (TrackRobot &lhs, const TrackRobot &rhs);
    00161
    00162 };
    00163
    00164 #endif