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