Robotsystem of the Robot Group Leipzig: agent.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# agent.h

Go to the documentation of this file.

    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: agent.h,v $
    00023  *   Revision 1.19  2008/04/17 14:54:01  martius
    00024  *   randomGen added, which is a random generator with long period and an
    00025  *    internal state. Each Agent has an instance and passed it to the controller
    00026  *    and the wiring. This is good for
    00027  *   a) repeatability on agent basis,
    00028  *   b) parallel execution as done in ode_robots
    00029  *
    00030  *   Revision 1.18  2007/11/06 14:58:58  martius
    00031  *   major change!
    00032  *   agent is now a robot with a wired controller,
    00033  *   most code moved to wiredcontroller class
    00034  *
    00035  *   Revision 1.17  2007/08/29 11:33:20  martius
    00036  *   simulation time enters logfile
    00037  *
    00038  *   Revision 1.16  2007/06/21 16:22:17  martius
    00039  *   indentation
    00040  *
    00041  *   Revision 1.15  2007/05/07 20:58:21  robot3
    00042  *   added support for Interface Callbackable (to find in selforg/utils)
    00043  *   classes can now register at agent to get a callback every step
    00044  *
    00045  *   Revision 1.14  2007/03/28 11:36:53  robot3
    00046  *   Moved int t from private to protected area because the OdeAgent needs access
    00047  *   to it.
    00048  *
    00049  *   Revision 1.13  2007/03/05 17:52:14  martius
    00050  *   plotoptions hav optional string parameter
    00051  *
    00052  *   Revision 1.12  2007/02/27 12:00:05  robot5
    00053  *   Minor changes for SoundMan functionalities.
    00054  *
    00055  *   Revision 1.11  2007/02/01 15:53:08  martius
    00056  *   inspectables list. Robot is added in case it is derived from Inspectable
    00057  *
    00058  *   Revision 1.10  2006/12/21 11:44:17  martius
    00059  *   commenting style for doxygen //< -> ///<
    00060  *   FOREACH and FOREACHC are macros for collection iteration
    00061  *
    00062  *   Revision 1.9  2006/12/13 09:13:24  martius
    00063  *   agents get comments about changed parameter for logfile
    00064  *
    00065  *   Revision 1.8  2006/12/11 18:10:27  martius
    00066  *   noisefactor and default constructor
    00067  *
    00068  *   Revision 1.7  2006/11/30 10:02:11  robot5
    00069  *   Added support for Sndchanger (experimental). Startup with argument -s.
    00070  *
    00071  *   Revision 1.6  2006/11/23 13:06:10  martius
    00072  *   onlyControlRobot is a new function. Useful for ODE simulations where physics runs faster than
    00073  *   control cycle
    00074  *
    00075  *   Revision 1.5  2006/11/17 13:46:53  martius
    00076  *   list of configureables to appear in configuration file
    00077  *
    00078  *   Revision 1.4  2006/08/04 15:16:13  martius
    00079  *   documentation
    00080  *
    00081  *   Revision 1.3  2006/08/02 09:35:09  martius
    00082  *   LastPlot as a dummy option added
    00083  *
    00084  *   Revision 1.2  2006/07/14 12:23:57  martius
    00085  *   selforg becomes HEAD
    00086  *
    00087  *   Revision 1.1.2.7  2006/06/25 16:51:35  martius
    00088  *   configureable has name and revision
    00089  *   a robot is configureable by default
    00090  *
    00091  *   Revision 1.1.2.6  2006/05/23 21:13:08  martius
    00092  *   - add virtual destructor
    00093  *
    00094  *   Revision 1.1.2.5  2006/05/15 13:08:34  robot3
    00095  *   -handling of starting guilogger moved to simulation.cpp
    00096  *   -CTRL-F now toggles logging to the file (controller stuff) on/off
    00097  *   -CTRL-G now restarts the GuiLogger
    00098  *
    00099  *   Revision 1.1.2.4  2006/03/30 12:33:53  fhesse
    00100  *   trackrobot now protected to give OdeAgent access
    00101  *
    00102  *   Revision 1.1.2.3  2006/01/31 16:45:18  martius
    00103  *   neuronviz plotoption
    00104  *
    00105  *   Revision 1.1.2.2  2005/11/15 12:30:26  martius
    00106  *   new selforg structure and OdeAgent, OdeRobot ...
    00107  *
    00108  *   Revision 1.1.2.1  2005/11/14 17:37:56  martius
    00109  *   moved to selforg
    00110  *
    00111  *   Revision 1.9  2005/11/07 17:03:30  martius
    00112  *   class PlotOption added
    00113  *   agent can be constructed with a list of PlotOptions
    00114  *   tracking file gets controller parameters as well
    00115  *
    00116  *   Revision 1.8  2005/10/24 13:32:07  fhesse
    00117  *   comments adjusted and in doxygen style
    00118  *
    00119  *   Revision 1.7  2005/09/22 12:24:36  martius
    00120  *   removed global variables
    00121  *   OdeHandle and GlobalData are used instead
    00122  *   sensor prepared
    00123  *
    00124  *   Revision 1.6  2005/08/03 20:34:58  martius
    00125  *   use if Inspectable interface
    00126  *
    00127  *   Revision 1.5  2005/07/26 17:01:47  martius
    00128  *   flushing every 10
    00129  *   guilogger is opened with nice -2
    00130  *
    00131  *   Revision 1.4  2005/07/18 10:13:46  martius
    00132  *   noise moved to wiring
    00133  *
    00134  *   Revision 1.3  2005/07/14 15:57:53  fhesse
    00135  *   now agent contains controller, robot and wiring, plotting ability included, therefore plotagent can be removed; ono2onewiring replaces one2oneagent
    00136  *
    00137  *   Revision 1.2  2005/06/15 14:02:47  martius
    00138  *   revised and basicly tested
    00139  *                                                                 *
    00140  ***************************************************************************/
    00141 #ifndef __AGENT_H
    00142 #define __AGENT_H
    00143
    00144 #include <stdio.h>
    00145 #include <list>
    00146 #include <string>
    00147
    00148 #include "wiredcontroller.h"
    00149 #include "randomgenerator.h"
    00150
    00151 class AbstractRobot;
    00152
    00153 #include "types.h"
    00154 #include "trackrobots.h"
    00155
    00156 /** The Agent contains a controller, a robot and a wiring, which connects robot and controller.
    00157     Additionally there are some ways to keep track of internal information.
    00158     You have the possibility to keep track of sensor values,
    00159      motor values and internal parameters of the controller with PlotOptions.
    00160     The name PlotOptions is a bit missleaded, it should be "OutputOptions",
    00161      however you can write the data into a file or send it to visialisation tools like
    00162      guilogger or neuronviz.
    00163
    00164     If want to log the position, speed and orienation of your robot
    00165     you can use setTrackOptions().
    00166     Please be aware that the Agent inherits from WiredController. You
    00167      might also find useful functions there.
    00168  */
    00169 class Agent : public WiredController {
    00170 public:
    00171   /** constructor. PlotOption as output setting.
    00172       noisefactor is used to set the relative noise strength of this agent
    00173    */
    00174   Agent(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1);
    00175   /** constructor. A list of PlotOption can given.
    00176       noisefactor is used to set the relative noise strength of this agent
    00177    */
    00178   Agent(const std::list<PlotOption>& plotOptions, double noisefactor = 1);
    00179
    00180   /** destructor
    00181    */
    00182   virtual ~Agent();
    00183
    00184   /** initializes the object with the given controller, robot and wiring
    00185       and initializes the output options.
    00186       It is also possible to provide a random seed,
    00187        if not given (0) rand() is used to create one
    00188   */
    00189   virtual bool init(AbstractController* controller, AbstractRobot* robot,
    00190                     AbstractWiring* wiring, long int seed=0);
    00191
    00192   /** Performs an step of the agent, including sensor reading, pushing sensor values through the wiring,
    00193       controller step, pushing controller outputs (= motorcommands) back through the wiring and sent
    00194       resulting motorcommands to robot.
    00195       @param noise Noise strength.
    00196       @param time (optional) current simulation time (used for logging)
    00197   */
    00198   virtual void step(double noise, double time=-1);
    00199
    00200   /** Sends only last motor commands again to robot.  */
    00201   virtual void onlyControlRobot();
    00202
    00203   /** Returns a pointer to the robot.
    00204    */
    00205   virtual AbstractRobot* getRobot() { return robot;}
    00206
    00207   /// sets the trackoptions which enable tracking of a robot
    00208   virtual void setTrackOptions(const TrackRobot& trackrobot);
    00209
    00210   /** adds the PlotOptions to the list of plotoptions
    00211       If a plotoption with the same Mode exists, then the old one is
    00212       deleted first (overwritten from WiredController, to add robot)
    00213    */
    00214   virtual void addPlotOption(const PlotOption& plotoption);
    00215
    00216 protected:
    00217
    00218   AbstractRobot* robot;
    00219
    00220   sensor *rsensors;
    00221   motor  *rmotors;
    00222
    00223   RandGen randGen; // random generator for this agent
    00224 protected:
    00225   TrackRobot trackrobot;
    00226   int t; // access to this variable is needed from OdeAgent
    00227
    00228 };
    00229
    00230 #endif