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.10 2006/12/21 11:44:17 martius 00024 * commenting style for doxygen //< -> ///< 00025 * FOREACH and FOREACHC are macros for collection iteration 00026 * 00027 * Revision 1.9 2006/12/13 09:13:24 martius 00028 * agents get comments about changed parameter for logfile 00029 * 00030 * Revision 1.8 2006/12/11 18:10:27 martius 00031 * noisefactor and default constructor 00032 * 00033 * Revision 1.7 2006/11/30 10:02:11 robot5 00034 * Added support for Sndchanger (experimental). Startup with argument -s. 00035 * 00036 * Revision 1.6 2006/11/23 13:06:10 martius 00037 * onlyControlRobot is a new function. Useful for ODE simulations where physics runs faster than 00038 * control cycle 00039 * 00040 * Revision 1.5 2006/11/17 13:46:53 martius 00041 * list of configureables to appear in configuration file 00042 * 00043 * Revision 1.4 2006/08/04 15:16:13 martius 00044 * documentation 00045 * 00046 * Revision 1.3 2006/08/02 09:35:09 martius 00047 * LastPlot as a dummy option added 00048 * 00049 * Revision 1.2 2006/07/14 12:23:57 martius 00050 * selforg becomes HEAD 00051 * 00052 * Revision 1.1.2.7 2006/06/25 16:51:35 martius 00053 * configureable has name and revision 00054 * a robot is configureable by default 00055 * 00056 * Revision 1.1.2.6 2006/05/23 21:13:08 martius 00057 * - add virtual destructor 00058 * 00059 * Revision 1.1.2.5 2006/05/15 13:08:34 robot3 00060 * -handling of starting guilogger moved to simulation.cpp 00061 * -CTRL-F now toggles logging to the file (controller stuff) on/off 00062 * -CTRL-G now restarts the GuiLogger 00063 * 00064 * Revision 1.1.2.4 2006/03/30 12:33:53 fhesse 00065 * trackrobot now protected to give OdeAgent access 00066 * 00067 * Revision 1.1.2.3 2006/01/31 16:45:18 martius 00068 * neuronviz plotoption 00069 * 00070 * Revision 1.1.2.2 2005/11/15 12:30:26 martius 00071 * new selforg structure and OdeAgent, OdeRobot ... 00072 * 00073 * Revision 1.1.2.1 2005/11/14 17:37:56 martius 00074 * moved to selforg 00075 * 00076 * Revision 1.9 2005/11/07 17:03:30 martius 00077 * class PlotOption added 00078 * agent can be constructed with a list of PlotOptions 00079 * tracking file gets controller parameters as well 00080 * 00081 * Revision 1.8 2005/10/24 13:32:07 fhesse 00082 * comments adjusted and in doxygen style 00083 * 00084 * Revision 1.7 2005/09/22 12:24:36 martius 00085 * removed global variables 00086 * OdeHandle and GlobalData are used instead 00087 * sensor prepared 00088 * 00089 * Revision 1.6 2005/08/03 20:34:58 martius 00090 * use if Inspectable interface 00091 * 00092 * Revision 1.5 2005/07/26 17:01:47 martius 00093 * flushing every 10 00094 * guilogger is opened with nice -2 00095 * 00096 * Revision 1.4 2005/07/18 10:13:46 martius 00097 * noise moved to wiring 00098 * 00099 * Revision 1.3 2005/07/14 15:57:53 fhesse 00100 * now agent contains controller, robot and wiring, plotting ability included, therefore plotagent can be removed; ono2onewiring replaces one2oneagent 00101 * 00102 * Revision 1.2 2005/06/15 14:02:47 martius 00103 * revised and basicly tested 00104 * * 00105 ***************************************************************************/ 00106 #ifndef __AGENT_H 00107 #define __AGENT_H 00108 00109 #include <stdio.h> 00110 #include <list> 00111 #include <utility> 00112 #include <string> 00113 00114 00115 class AbstractRobot; 00116 class AbstractController; 00117 class AbstractWiring; 00118 class Configurable; 00119 00120 #include "types.h" 00121 #include "trackrobots.h" 00122 00123 class Agent; 00124 00125 /** Output mode for agent. 00126 */ 00127 enum PlotMode { 00128 /// dummy (does nothing) is there for compatibility, might be removed later 00129 NoPlot, 00130 /// write into file 00131 File, 00132 /// plotting with guilogger (gnuplot) 00133 GuiLogger, 00134 /// plotting with guiscreen (gnuplot) in file logging mode 00135 GuiLogger_File, 00136 /// net visualiser 00137 NeuronViz, 00138 00139 /// Acustic output of robotic values via external Sndchanger 00140 SndChanger, 00141 00142 /// dummy used for upper bound of plotmode type 00143 LastPlot 00144 }; 00145 00146 /** Output either sensors from robot or from controller 00147 (there can be a difference depending on the used wiring) 00148 */ 00149 enum PlotSensors {Robot, Controller}; 00150 00151 /** This class contains options for the use of an external plot utility like guilogger or neuronviz 00152 or just simply file output 00153 */ 00154 class PlotOption { 00155 public: 00156 friend class Agent; 00157 00158 PlotOption(){ mode=NoPlot; whichSensors=Controller; interval=1; pipe=0; } 00159 PlotOption( PlotMode mode, PlotSensors whichSensors = Controller, 00160 int interval = 1, std::list<const Configurable*> confs = std::list<const Configurable*>()) 00161 : mode(mode), whichSensors(whichSensors), interval(interval), configureables(confs) { pipe=0; } 00162 00163 virtual ~PlotOption(){} 00164 00165 /// nice predicate function for finding by mode 00166 struct matchMode : public std::unary_function<const PlotOption&, bool> { 00167 matchMode(PlotMode mode) : mode(mode) {} 00168 int mode; 00169 bool operator()(const PlotOption& m) { return m.mode == mode; } 00170 }; 00171 00172 void addConfigurable(const Configurable*); 00173 00174 private: 00175 00176 bool open(); ///< opens the connections to the plot tool 00177 void close();///< closes the connections to the plot tool 00178 00179 FILE* pipe; 00180 long t; 00181 std::string name; 00182 00183 PlotMode mode; 00184 PlotSensors whichSensors; 00185 int interval; 00186 std::list< const Configurable* > configureables; 00187 }; 00188 00189 00190 /** The Agent contains a controller, a robot and a wiring, which connects robot and controller. 00191 Additionally there are some ways to keep track of internal information. 00192 You have the possibility to keep track of sensor values, 00193 motor values and internal parameters of the controller with PlotOptions. 00194 The name PlotOptions is a bit missleaded, it should be "OutputOptions", 00195 however you can write the data into a file or send it to visialisation tools like 00196 guilogger or neuronviz. 00197 00198 If want to log the position, speed and orienation of your robot you can use setTrackOptions(). 00199 */ 00200 class Agent { 00201 public: 00202 /** constructor. PlotOption as output setting. 00203 noisefactor is used to set the relative noise strength of this agent 00204 */ 00205 Agent(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1); 00206 /** constructor. A list of PlotOption can given. 00207 noisefactor is used to set the relative noise strength of this agent 00208 */ 00209 Agent(const std::list<PlotOption>& plotOptions, double noisefactor = 1); 00210 00211 /** destructor 00212 */ 00213 virtual ~Agent(); 00214 00215 /** initializes the object with the given controller, robot and wiring 00216 and initializes the output options 00217 */ 00218 virtual bool init(AbstractController* controller, AbstractRobot* robot, AbstractWiring* wiring); 00219 00220 /** Performs an step of the agent, including sensor reading, pushing sensor values through wiring, 00221 controller step, pushing controller outputs (= motorcommands) back through wiring and sent 00222 resulting motorcommands to robot. 00223 @param noise Noise strength. 00224 */ 00225 virtual void step(double noise); 00226 00227 /** Sends only last motor commands again to robot. */ 00228 virtual void onlyControlRobot(); 00229 00230 /** Returns a pointer to the controller. 00231 */ 00232 virtual AbstractController* getController() { return controller;} 00233 00234 /** Returns a pointer to the robot. 00235 */ 00236 virtual AbstractRobot* getRobot() { return robot;} 00237 00238 /** Returns a pointer to the wiring. 00239 */ 00240 virtual AbstractWiring* getWiring() { return wiring;} 00241 00242 /// sets the trackoptions which enable tracking of a robot 00243 virtual void setTrackOptions(const TrackRobot& trackrobot); 00244 00245 00246 /** adds the PlotOptions to the list of plotoptions 00247 If a plotoption with the same Mode exists, then the old one is deleted first 00248 */ 00249 virtual void addPlotOption(const PlotOption& plotoption); 00250 00251 /** removes the PlotOptions with the given type 00252 @return true if sucessful, false otherwise 00253 */ 00254 virtual bool removePlotOption(PlotMode mode); 00255 00256 /** 00257 write comment to output streams (PlotOptions). For instance changes in parameters. 00258 */ 00259 virtual void writePlotComment(const char* cmt); 00260 00261 protected: 00262 00263 /** 00264 * Plots controller sensor- and motorvalues and internal controller parameters. 00265 * @param rx actual sensorvalues from robot (used for generation of motorcommand in actual timestep) 00266 * @param rsensornumber length of rx 00267 * @param cx actual sensorvalues which are passed to controller (used for generation of motorcommand in actual timestep) 00268 * @param csensornumber length of cx 00269 * @param y actual motorcommand (generated in the actual timestep) 00270 * @param motornumber length of y 00271 */ 00272 virtual void plot(const sensor* rx, int rsensornumber, const sensor* cx, int csensornumber, 00273 const motor* y, int motornumber); 00274 00275 00276 AbstractController* controller; 00277 AbstractRobot* robot; 00278 AbstractWiring* wiring; 00279 00280 /// number of sensors of robot 00281 int rsensornumber; 00282 /// number of motors of robot 00283 int rmotornumber; 00284 /// number of sensors of comntroller 00285 int csensornumber; 00286 /// number of motors of comntroller 00287 int cmotornumber; 00288 00289 /// factor that is muliplied with noise stength 00290 double noisefactor; 00291 00292 sensor *rsensors; 00293 motor *rmotors; 00294 sensor *csensors; 00295 motor *cmotors; 00296 00297 void internInit(); 00298 00299 protected: 00300 TrackRobot trackrobot; 00301 00302 private: 00303 std::list<PlotOption> plotOptions; 00304 00305 int t; 00306 00307 }; 00308 00309 #endif

Generated on Tue Jan 16 02:14:34 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8