Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
trackrobots.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __TRACKROBOTS_H
25 #define __TRACKROBOTS_H
26 
27 #include <stdio.h>
28 #include <string>
29 
30 #include <selforg/trackable.h>
31 
32 class AbstractRobot;
33 class Agent;
34 
35 namespace lpzrobots {
36  class OdeAgent;
37  class TraceDrawer;
38 }
39 
41  bool trackPos;
42  bool trackSpeed;
45  double displayTraceDur; ///< duration in second to display the trace
46  double displayTraceThickness; ///< if thickkness is 0 (default) then a line is used otherwise a cylinder
47 
48  bool writeFile; ///< whether to write a log file
49  int interval; ///< every how many control steps a record is written
50  std::string scene; ///< used as part of the filename (used as is (+id), if autoFilename=false)
51  bool autoFilename; ///< whether to create a unique filename with date, scene and robotname
52  int id;
53 };
54 
55 /**
56  This class provides tracking possibilies of a robot.
57  The position, speed, and orientation can be logged.
58  This is used by the agent class, @see Agent::setTrackOptions()
59 */
60 class TrackRobot {
61 public:
62 
63  friend class Agent;
64  friend class lpzrobots::OdeAgent;
65  friend class lpzrobots::TraceDrawer;
66 
67  /// constructor for no tracking at all
69  : conf(conf)
70  {
71  file = 0;
72  cnt = 1;
73  }
74 
77  conf.trackPos = true;
78  conf.trackSpeed = false;
79  conf.trackOrientation = false;
80  conf.displayTrace = false;
81  conf.displayTraceDur = 60;
82  conf.displayTraceThickness = 0.0;
83  conf.interval = 1;
84  conf.writeFile = true;
85  // conf.scene = "";
86  conf.id = -1; // disabled
87  conf.autoFilename = true;
88  return conf;
89  }
90 
91 
92  /** Constructor that allows individial setting of tracking options.
93  The tracked data is written into a file with the current date and time appended by a name given by scene.
94  @param trackPos if true the trace (position vectors) of the robot are logged
95  @param trackSpeed if true the speed vectors (linear and angular) of the robot are logged
96  @param trackOrientation if true the orientation matrices of the robot are logged
97  @param displayTrace if true the trace of the robot should be displayed (used in ODE simulations)
98  @param scene name of the scene (is appended to log file name)
99  @param interval timesteps between consequent logging events (default 1)
100  */
101  TrackRobot(bool trackPos, bool trackSpeed, bool trackOrientation, bool displayTrace,
102  const char* scene = "", int interval = 1)
103  {
104  conf = getDefaultConf();
105  conf.trackPos = trackPos;
106  conf.trackSpeed = trackSpeed;
107  conf.trackOrientation = trackOrientation;
108  conf.displayTrace = displayTrace;
109  conf.interval = interval;
110  conf.scene = scene;
111  conf.id = -1; // whole robot, not individual parts
112  file = 0;
113  cnt = 1;
114  enabledDuringVideo = false;
115  }
116 
118  {
119  }
120 
121  /// returns whether tracing is activated
122  bool isDisplayTrace() const {return conf.displayTrace;};
123 
124  /// returns whether something is to be tracked
125  bool isTrackingSomething() const {
127  };
128 
129  bool isEnabled() {
130  return file!=0 && isTrackingSomething();
131  }
132 
134 
136  protected:
137  bool open(const Trackable* robot);
138  void track(const Trackable* robot, double time);
139  void close();
140 
141  protected:
142  FILE* file;
143  long cnt;
144 
145 
146 };
147 
148 #endif
bool autoFilename
whether to create a unique filename with date, scene and robotname
Definition: trackrobots.h:51
int id
Definition: trackrobots.h:52
std::string scene
used as part of the filename (used as is (+id), if autoFilename=false)
Definition: trackrobots.h:50
bool trackSpeed
Definition: trackrobots.h:42
double displayTraceThickness
if thickkness is 0 (default) then a line is used otherwise a cylinder
Definition: trackrobots.h:46
This class provides tracking possibilies of a robot.
Definition: trackrobots.h:60
int interval
every how many control steps a record is written
Definition: trackrobots.h:49
TrackRobot(TrackRobotConf conf=getDefaultConf())
constructor for no tracking at all
Definition: trackrobots.h:68
FILE * file
Definition: trackrobots.h:142
Abstract class (interface) for trackable objects (used for robots)
Definition: trackable.h:39
bool writeFile
whether to write a log file
Definition: trackrobots.h:48
bool enabledDuringVideo
Definition: trackrobots.h:135
~TrackRobot()
Definition: trackrobots.h:117
bool isEnabled()
Definition: trackrobots.h:129
static TrackRobotConf getDefaultConf()
Definition: trackrobots.h:75
Definition: trackrobots.h:40
The Agent contains a controller, a robot and a wiring, which connects robot and controller.
Definition: agent.h:52
bool isDisplayTrace() const
returns whether tracing is activated
Definition: trackrobots.h:122
bool open(const Trackable *robot)
Definition: trackrobots.cpp:32
Specialised agent for ode robots.
Definition: odeagent.h:62
void close()
Definition: trackrobots.cpp:108
double displayTraceDur
duration in second to display the trace
Definition: trackrobots.h:45
bool trackOrientation
Definition: trackrobots.h:43
bool trackPos
Definition: trackrobots.h:41
void track(const Trackable *robot, double time)
Definition: trackrobots.cpp:77
TrackRobotConf conf
Definition: trackrobots.h:133
TrackRobot(bool trackPos, bool trackSpeed, bool trackOrientation, bool displayTrace, const char *scene="", int interval=1)
Constructor that allows individial setting of tracking options.
Definition: trackrobots.h:101
Definition: odeagent.h:37
bool isTrackingSomething() const
returns whether something is to be tracked
Definition: trackrobots.h:125
Abstract class (interface) for robot in general.
Definition: abstractrobot.h:41
long cnt
Definition: trackrobots.h:143
bool displayTrace
Definition: trackrobots.h:44