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

# odeagent.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 __ODEAGENT_H
    00025 #define __ODEAGENT_H
    00026
    00027 #include <selforg/agent.h>
    00028 #include <selforg/storeable.h>
    00029 #include "oderobot.h"
    00030 #include "osgprimitive.h"
    00031 #include "primitive.h"
    00032 #include "operator.h"
    00033
    00034 namespace lpzrobots {
    00035   class Joint;
    00036
    00037   class TraceDrawer {
    00038   public:
    00039     TraceDrawer() : obj(0){}
    00040     Position lastpos;
    00041     Trackable* obj;
    00042     TrackRobot tracker;
    00043     Color color;
    00044     void init();
    00045     void close();
    00046     /// actually write the log files and stuff
    00047     void track(double time);
    00048     /// draw the trace
    00049     void drawTrace(GlobalData& global);
    00050   protected:
    00051     bool initialized;
    00052   };
    00053
    00054
    00055   typedef std::list<PlotOption> PlotOptionList;
    00056   typedef std::list<Operator*> OperatorList;
    00057   typedef std::list<TraceDrawer> TraceDrawerList;
    00058
    00059   /** Specialised agent for ode robots
    00060    */
    00061   class OdeAgent : public Agent, public Storeable {
    00062   public:
    00063
    00064     /** @deprecated obsolete provide globaldata, see the other constructors
    00065      */
    00066     OdeAgent(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "$ID$") __attribute__ ((deprecated));
    00067     /** @deprecated obsolete provide globaldata, see the other constructors
    00068      */
    00069     OdeAgent(const std::list<PlotOption>& plotOptions, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "$ID$") __attribute__ ((deprecated));
    00070     /** The plotoptions are taken from globaldata
    00071         @param noisefactor factor for sensor noise for this agent
    00072      */
    00073     OdeAgent(const GlobalData& globalData, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "");
    00074     /** Provided for convinience. A single plotoption is used as given by plotOption */
    00075     OdeAgent(const GlobalData& globalData, const PlotOption& plotOption, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "");
    00076     /** Provided for convinience. The plotoptions are taken from the given plotOptions
    00077         (and not from globaldata, if you wish to overwrite them)
    00078     */
    00079     OdeAgent(const GlobalData& globalData, const PlotOptionList& plotOptions, double noisefactor = 1, const std::string& name = "OdeAgent", const std::string& revision = "");
    00080     virtual ~OdeAgent();
    00081
    00082     /** initializes the object with the given controller, robot and wiring
    00083         and initializes plotoptionengine
    00084     */
    00085     virtual bool init(AbstractController* controller, OdeRobot* robot, AbstractWiring* wiring,
    00086                       long int seed = 0){
    00087       return Agent::init(controller, robot, wiring, seed);
    00088     }
    00089
    00090     virtual void step(double noise, double time);
    00091
    00092     /**
    00093      * Special function for the class Simulation to seperate the step
    00094      * of the WiredController (plus TrackRobot) and the setting and getting
    00095      * of the motor- and sensorvalues.
    00096      * @param noise @see step()
    00097      * @param time @see step()
    00098      */
    00099     virtual void stepOnlyWiredController(double noise, double time);
    00100
    00101     /**
    00102      * Special function for the class Simulation to seperate the step
    00103      * of the WiredController (plus TrackRobot) and the setting and getting
    00104      * of the motor- and sensorvalues.
    00105      */
    00106     virtual void setMotorsGetSensors();
    00107
    00108     /** should be called before step() or stepOnlyWiredController()
    00109         and calls operators and robot->sense()
    00110     */
    00111     virtual void beforeStep(GlobalData& global);
    00112
    00113     /** Enables the motor babbling mode.
    00114         The robot is move into the air and is fixed by a fixed joint if fixRobot==true
    00115         See WiredController::startMotorBabblingMode().
    00116     */
    00117     virtual void startMotorBabblingMode (int steps,
    00118                                          AbstractController* babblecontroller = 0,
    00119                                          bool fixRobot=true);
    00120
    00121     /** stops the motor babbling mode. */
    00122     virtual void stopMotorBabblingMode ();
    00123
    00124     /**
    00125      * Returns a pointer to the robot.
    00126      */
    00127     virtual OdeRobot* getRobot() { return (OdeRobot*)robot;}
    00128     /**
    00129      * Returns a const pointer to the robot.
    00130      */
    00131     virtual const OdeRobot* getRobot() const { return (OdeRobot*)robot;}
    00132
    00133     /** @deprecated use TrackRobot parameters */
    00134     virtual int getTraceLength(){return 0;}
    00135
    00136     /** @deprecated use TrackRobot parameters */
    00137     virtual bool setTraceLength(int tracelength) {return true;}
    00138
    00139     /** @deprecated use TrackRobot parameters */
    00140     virtual void setTraceThickness(int tracethickness){ }
    00141
    00142     /// adds tracking for individual primitives
    00143     virtual void addTracking(unsigned int primitiveIndex,const TrackRobot& trackrobot,
    00144                              const Color& color);
    00145     virtual void setTrackOptions(const TrackRobot& trackrobot);
    00146
    00147     /****** STOREABLE **********/
    00148     virtual bool store(FILE* f) const;
    00149     virtual bool restore(FILE* f);
    00150
    00151
    00152     /****** OPERATORS *********/
    00153     /// adds an operator to the agent (the operator is deleted on destruction of the agent!)
    00154     virtual void addOperator(Operator* o, bool addToConfigurable = true );
    00155
    00156     /** removes the given operator: it is _not_ deleted (memory wise)
    00157         @return true on success
    00158      */
    00159     virtual bool removeOperator(Operator* o);
    00160     /// removes (and deletes) all operators
    00161     virtual void removeOperators();
    00162
    00163   protected:
    00164
    00165     /**
    00166      * continues the trace by one segment
    00167      */
    00168     virtual void trace(GlobalData& global);
    00169
    00170     /** tries to fixate the robot at fixatingPos */
    00171     virtual void tryFixateRobot();
    00172
    00173   private:
    00174     void constructor_helper(const GlobalData* globalData);
    00175
    00176     TraceDrawer mainTrace;
    00177     Pos fixatingPos;
    00178     bool fixateRobot;
    00179     Joint* fixedJoint;
    00180
    00181     OperatorList operators;
    00182
    00183     TraceDrawerList segmentTracking;
    00184   };
    00185
    00186 }
    00187
    00188 #endif