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
odeagent.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 __ODEAGENT_H
25 #define __ODEAGENT_H
26 
27 #include <selforg/agent.h>
28 #include <selforg/storeable.h>
29 #include "oderobot.h"
30 #include "osgprimitive.h"
31 #include "primitive.h"
32 #include "operator.h"
33 
34 namespace lpzrobots {
35  class Joint;
36 
37  class TraceDrawer {
38  public:
39  TraceDrawer() : obj(0), initialized(false) {}
44  void init();
45  void close();
46  /// actually write the log files and stuff
47  void track(double time);
48  /// draw the trace
49  void drawTrace(GlobalData& global);
50  protected:
52  std::list<osg::Vec3> pnts;
53  };
54 
55 
56  typedef std::list<PlotOption> PlotOptionList;
57  typedef std::list<Operator*> OperatorList;
58  typedef std::list<TraceDrawer> TraceDrawerList;
59 
60  /** Specialised agent for ode robots
61  */
62  class OdeAgent : public Agent, public Storeable {
63  public:
64 
65  /** @deprecated obsolete provide globaldata, see the other constructors
66  */
67  OdeAgent(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "$ID$") __attribute__ ((deprecated));
68  /** @deprecated obsolete provide globaldata, see the other constructors
69  */
70  OdeAgent(const std::list<PlotOption>& plotOptions, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "$ID$") __attribute__ ((deprecated));
71  /** The plotoptions are taken from globaldata
72  @param noisefactor factor for sensor noise for this agent
73  */
74  OdeAgent(const GlobalData& globalData, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "");
75  /** Provided for convinience. A single plotoption is used as given by plotOption */
76  OdeAgent(const GlobalData& globalData, const PlotOption& plotOption, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "");
77  /** Provided for convinience. The plotoptions are taken from the given plotOptions
78  (and not from globaldata, if you wish to overwrite them)
79  */
80  OdeAgent(const GlobalData& globalData, const PlotOptionList& plotOptions, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "");
81  virtual ~OdeAgent();
82 
83  /** initializes the object with the given controller, robot and wiring
84  and initializes plotoptionengine
85  */
87  long int seed = 0){
88  return Agent::init(controller, robot, wiring, seed);
89  }
90 
91  virtual void step(double noise, double time);
92 
93  /**
94  * Special function for the class Simulation to seperate the step
95  * of the WiredController (plus TrackRobot) and the setting and getting
96  * of the motor- and sensorvalues.
97  * @param noise @see step()
98  * @param time @see step()
99  */
100  virtual void stepOnlyWiredController(double noise, double time);
101 
102  /**
103  * Special function for the class Simulation to seperate the step
104  * of the WiredController (plus TrackRobot) and the setting and getting
105  * of the motor- and sensorvalues.
106  */
107  virtual void setMotorsGetSensors();
108 
109  /** should be called before step() or stepOnlyWiredController()
110  and calls operators and robot->sense()
111  */
112  virtual void beforeStep(GlobalData& global);
113 
114  /**
115  * Returns a pointer to the robot.
116  */
117  virtual OdeRobot* getRobot() { return (OdeRobot*)robot;}
118  /**
119  * Returns a const pointer to the robot.
120  */
121  virtual const OdeRobot* getRobot() const { return (OdeRobot*)robot;}
122 
123  /** @deprecated use TrackRobot parameters */
124  virtual int getTraceLength(){return 0;}
125 
126  /** @deprecated use TrackRobot parameters */
127  virtual bool setTraceLength(int tracelength) {return true;}
128 
129  /** @deprecated use TrackRobot parameters */
130  virtual void setTraceThickness(int tracethickness){ }
131 
132  /// adds tracking for individual primitives
133  virtual void addTracking(unsigned int primitiveIndex,const TrackRobot& trackrobot,
134  const Color& color);
135  virtual void setTrackOptions(const TrackRobot& trackrobot);
136  virtual bool stopTracking();
137 
138 
139  /****** STOREABLE **********/
140  virtual bool store(FILE* f) const;
141  virtual bool restore(FILE* f);
142 
143 
144  /****** OPERATORS *********/
145  /// adds an operator to the agent (the operator is deleted on destruction of the agent!)
146  virtual void addOperator(Operator* o, bool addToConfigurable = true );
147 
148  /** removes the given operator: it is _not_ deleted (memory wise)
149  @return true on success
150  */
151  virtual bool removeOperator(Operator* o);
152  /// removes (and deletes) all operators
153  virtual void removeOperators();
154 
155  /** fixates the given primitive of the robot at its current position to the world
156  for a certain time.
157  Hint: use getRobot()->moveToPosition() to get the robot relocated
158  @param primitiveID if -1 then the main primitive is used, otherwise the primitive with the given index
159  @param time time to fixate in seconds (if ==0 then indefinite)
160  */
161  virtual void fixateRobot(GlobalData& global, int primitiveID=-1, double time = 0);
162  /// release the robot in case it is fixated and turns true in this case
163  virtual bool unfixateRobot(GlobalData& global);
164 
165  protected:
166 
167  /**
168  * continues the trace by one segment
169  */
170  virtual void trace(GlobalData& global);
171 
172  private:
173  void constructor_helper(const GlobalData* globalData);
174 
175  TraceDrawer mainTrace;
176 
177  OperatorList operators;
178 
179  TraceDrawerList segmentTracking;
180  };
181 
182 }
183 
184 #endif
void close()
Definition: odeagent.cpp:42
Interface for objects, that can be stored and restored to/from a file stream (binary).
Definition: storeable.h:33
TrackRobot tracker
Definition: odeagent.h:42
virtual void setTraceThickness(int tracethickness)
Definition: odeagent.h:130
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
virtual bool removeOperator(Operator *o)
removes the given operator: it is not deleted (memory wise)
Definition: odeagent.cpp:302
virtual int getTraceLength()
Definition: odeagent.h:124
This class provides tracking possibilies of a robot.
Definition: trackrobots.h:60
virtual void addOperator(Operator *o, bool addToConfigurable=true)
adds an operator to the agent (the operator is deleted on destruction of the agent!) ...
Definition: odeagent.cpp:292
virtual void setTrackOptions(const TrackRobot &trackrobot)
sets the trackoptions which starts spatial tracking of a robot
Definition: odeagent.cpp:195
AbstractRobot * robot
Definition: agent.h:102
Trackable * obj
Definition: odeagent.h:41
Position lastpos
Definition: odeagent.h:40
virtual bool unfixateRobot(GlobalData &global)
release the robot in case it is fixated and turns true in this case
Definition: odeagent.cpp:273
TrackRobot trackrobot
Definition: agent.h:109
AbstractWiring * wiring
Definition: wiredcontroller.h:154
Abstract class (interface) for trackable objects (used for robots)
Definition: trackable.h:39
virtual void step(double noise, double time)
Performs an step of the agent, including sensor reading, pushing sensor values through the wiring...
Definition: odeagent.cpp:129
iparamkey name
Definition: inspectable.h:251
dummy (does nothing) is there for compatibility, might be removed later
Definition: plotoption.h:42
virtual ~OdeAgent()
Definition: odeagent.cpp:113
std::list< Operator * > OperatorList
Definition: odeagent.h:57
Abstract wiring-object between controller and robot.
Definition: abstractwiring.h:39
void drawTrace(GlobalData &global)
draw the trace
Definition: odeagent.cpp:54
virtual bool stopTracking()
stop tracking (returns true of tracking was on);
Definition: odeagent.cpp:205
Color color
Definition: odeagent.h:43
Definition: position.h:30
void track(double time)
actually write the log files and stuff
Definition: odeagent.cpp:48
virtual void beforeStep(GlobalData &global)
should be called before step() or stepOnlyWiredController() and calls operators and robot->sense() ...
Definition: odeagent.cpp:138
This class contains options for the use of an external plot utility like guilogger or neuronviz or ju...
Definition: plotoption.h:66
virtual void trace(GlobalData &global)
continues the trace by one segment
Definition: odeagent.cpp:188
std::list< PlotOption > PlotOptionList
Definition: odeagent.h:56
virtual void setMotorsGetSensors()
Special function for the class Simulation to seperate the step of the WiredController (plus TrackRobo...
Definition: odeagent.cpp:255
The Agent contains a controller, a robot and a wiring, which connects robot and controller.
Definition: agent.h:52
virtual bool setTraceLength(int tracelength)
Definition: odeagent.h:127
virtual void removeOperators()
removes (and deletes) all operators
Definition: odeagent.cpp:309
Data structure holding all essential global information.
Definition: globaldata.h:57
Specialised agent for ode robots.
Definition: odeagent.h:62
Definition: color.h:32
void init()
Definition: odeagent.cpp:36
std::list< osg::Vec3 > pnts
Definition: odeagent.h:52
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: odeagent.cpp:280
virtual bool init(AbstractController *controller, OdeRobot *robot, AbstractWiring *wiring, long int seed=0)
initializes the object with the given controller, robot and wiring and initializes plotoptionengine ...
Definition: odeagent.h:86
Definition: operator.h:42
TraceDrawer()
Definition: odeagent.h:39
OdeAgent(const PlotOption &plotOption=PlotOption(NoPlot), double noisefactor=1, const std::string &name="OdeAgent", const std::string &revision="$ID$") __attribute__((deprecated))
Definition: odeagent.cpp:86
virtual const OdeRobot * getRobot() const
Returns a const pointer to the robot.
Definition: odeagent.h:121
virtual void stepOnlyWiredController(double noise, double time)
Special function for the class Simulation to seperate the step of the WiredController (plus TrackRobo...
Definition: odeagent.cpp:178
Abstract class for ODE robots.
Definition: oderobot.h:64
AbstractController * controller
Definition: wiredcontroller.h:153
std::list< TraceDrawer > TraceDrawerList
Definition: odeagent.h:58
virtual bool init(AbstractController *controller, AbstractRobot *robot, AbstractWiring *wiring, long int seed=0)
initializes the object with the given controller, robot and wiring and initializes the output options...
Definition: agent.cpp:61
virtual void fixateRobot(GlobalData &global, int primitiveID=-1, double time=0)
fixates the given primitive of the robot at its current position to the world for a certain time...
Definition: odeagent.cpp:267
double noisefactor
factor that is muliplied with noise stength
Definition: wiredcontroller.h:166
virtual bool restore(FILE *f)
loads the object from the given file stream (ASCII preferred).
Definition: odeagent.cpp:285
virtual OdeRobot * getRobot()
Returns a pointer to the robot.
Definition: odeagent.h:117
Definition: odeagent.h:37
bool initialized
Definition: odeagent.h:51
virtual void addTracking(unsigned int primitiveIndex, const TrackRobot &trackrobot, const Color &color)
adds tracking for individual primitives
Definition: odeagent.cpp:233