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 * joergweide84@aol.com (robot12) * 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 * The Idea of this class is a controller wrapped in the wiring * 00024 * with all the plotoptions and so on, just without robot. It * 00025 * seams to be a much better architecture for connecting the controller * 00026 * to a hardware robot or other platforms. * 00027 * * 00028 * * 00029 * $Log: wiredcontroller.h,v $ 00030 * Revision 1.13 2009/08/10 15:36:19 der 00031 * plotoptions can again be added and initialized later 00032 * ctrl-g and -f are working again 00033 * ctrl-n added for neuronviz 00034 * 00035 * Revision 1.12 2009/08/10 07:41:48 guettler 00036 * - uses new BackCaller implementation 00037 * - shortened signature of function plot (removed unnecessary 00038 * parameters) 00039 * 00040 * Revision 1.11 2009/08/05 22:57:09 martius 00041 * use new plotoptionsengine entirely 00042 * wirings provide the sensor and motors such that the entire 00043 * old functionality (and more) is now available with through 00044 * the separate plotoptionsengine. 00045 * 00046 * Revision 1.10 2009/07/21 09:10:22 robot12 00047 * add some comments 00048 * 00049 * Revision 1.9 2009/06/02 09:55:24 robot12 00050 * Splitting of WiredController and PlotOption into WiredController : public PlotOptionEngine and 00051 * PlotOption (used by ga_tools). Further refactorings needed. 00052 * 00053 * Revision 1.8 2009/05/11 17:08:01 martius 00054 * flushing optimized 00055 * 00056 * Revision 1.7 2009/03/25 11:55:32 robot1 00057 * changed minor handling of PlotOptions 00058 * 00059 * Revision 1.6 2008/08/12 11:50:00 guettler 00060 * plug and play update, added some features for the ECBRobotGUI 00061 * 00062 * Revision 1.5 2008/08/01 14:42:04 guettler 00063 * we try the trip to hell! make selforg AVR compatible...good luck (first changes) 00064 * 00065 * Revision 1.4 2008/05/07 16:45:52 martius 00066 * code cosmetics and documentation 00067 * 00068 * Revision 1.3 2008/05/02 17:20:04 martius 00069 * *** empty log message *** 00070 * 00071 * Revision 1.2 2008/04/17 14:54:35 martius 00072 * randomGen added, which is a random generator with long period and an 00073 * internal state. Each Agent has an instance and passed it to the controller 00074 * and the wiring. This is good for 00075 * a) repeatability on agent basis, 00076 * b) parallel execution as done in ode_robots 00077 * 00078 * Revision 1.1 2007/11/06 15:14:41 martius 00079 * new class that composes controller and wiring 00080 * 00081 * * 00082 ***************************************************************************/ 00083 /* 00084 ** Started on Mon Oct 22 10:50:47 2007 Georg Martius 00085 ** Last update Mon Oct 22 10:50:47 2007 Georg Martius 00086 */ 00087 #ifndef WIREDCONTROLLER_H_ 00088 #define WIREDCONTROLLER_H_ 00089 00090 #include "plotoptionengine.h" 00091 #include "backcaller.h" 00092 #include "types.h" 00093 #include "inspectable.h" 00094 #include "randomgenerator.h" 00095 00096 #include <stdio.h> 00097 #include <list> 00098 #include <utility> 00099 #include <string> 00100 00101 00102 class AbstractController; 00103 class AbstractWiring; 00104 class Configurable; 00105 class Callbackable; 00106 class WiredController; 00107 00108 /** The WiredController contains a controller and a wiring, which 00109 connects the controller with the robot. 00110 Additionally there are some ways to keep track of internal information. 00111 You have the possibility to keep track of sensor values, 00112 motor values and internal parameters of the controller with PlotOptions. 00113 The name PlotOptions is a bit missleaded, it should be "OutputOptions", 00114 however you can write the data into a file or send it to 00115 visualisation tools like guilogger or neuronviz. 00116 */ 00117 class WiredController : public Inspectable, public BackCaller { 00118 public: 00119 /** constructor. PlotOption as output setting. 00120 noisefactor is used to set the relative noise strength of this agent 00121 */ 00122 WiredController(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1); 00123 /** constructor. A list of PlotOption can given. 00124 noisefactor is used to set the relative noise strength of this agent 00125 */ 00126 WiredController(const std::list<PlotOption>& plotOptions, double noisefactor = 1); 00127 00128 /** destructor 00129 */ 00130 virtual ~WiredController(); 00131 00132 /** initializes the object with the given controller and wiring 00133 and initializes the output options 00134 It is also possible to provide a random seed, 00135 if not given (0) rand() is used to create one 00136 */ 00137 bool init(AbstractController* controller, AbstractWiring* wiring, 00138 int robotsensornumber, int robotmotornumber, RandGen* randGen=0); 00139 00140 /** Performs an step of the controller, which includes 00141 pushing sensor values through the wiring, 00142 controller step, 00143 pushing controller outputs (= motorcommands) back through the wiring 00144 @param sensors sensors inputs scaled to [-1,1] 00145 @param sensornumber length of the sensor array 00146 @param motors motors outputs. MUST have enough space for motor values! 00147 @param motornumber length of the provided motor array 00148 00149 @param noise Noise strength. 00150 @param time (optional) current simulation time (used for logging) 00151 */ 00152 void step(const sensor* sensors, int sensornumber, 00153 motor* motors, int motornumber, 00154 double noise, double time=-1); 00155 00156 /** adds the PlotOptions to the list of plotoptions 00157 If a plotoption with the same Mode exists, then the old one is deleted first 00158 */ 00159 virtual PlotOption addPlotOption(PlotOption& plotoption); 00160 00161 /** adds a new PlotOption and initializes it 00162 @see addPlotOption 00163 */ 00164 bool addAndInitPlotOption(PlotOption& plotOption); 00165 00166 /** removes the PlotOptions with the given type 00167 @return true if sucessful, false otherwise 00168 */ 00169 virtual bool removePlotOption(PlotMode mode); 00170 00171 /** adds an inspectable object for logging. Must be called before init! 00172 */ 00173 virtual void addInspectable(const Inspectable* inspectable); 00174 00175 /** adds an configureable object for logging. Must be called before init! 00176 */ 00177 virtual void addConfigurable(const Configurable* c); 00178 /** 00179 write comment to output streams (PlotOptions). For instance changes in parameters. 00180 */ 00181 virtual void writePlotComment(const char* cmt); 00182 00183 /** Returns a pointer to the controller. 00184 */ 00185 virtual AbstractController* getController() { return controller;} 00186 00187 /** Returns a pointer to the wiring. 00188 */ 00189 virtual AbstractWiring* getWiring() { return wiring;} 00190 00191 00192 protected: 00193 /** 00194 * Plots controller sensor- and motorvalues and internal controller parameters. 00195 * @param time simulation time 00196 */ 00197 virtual void plot(double time); 00198 00199 00200 AbstractController* controller; 00201 AbstractWiring* wiring; 00202 00203 /// number of sensors of robot 00204 int rsensornumber; 00205 /// number of motors of robot 00206 int rmotornumber; 00207 /// number of sensors of comntroller 00208 int csensornumber; 00209 /// number of motors of comntroller 00210 int cmotornumber; 00211 00212 /// factor that is muliplied with noise stength 00213 double noisefactor; 00214 00215 motor *cmotors; 00216 sensor *csensors; 00217 00218 void internInit(); 00219 00220 protected: 00221 PlotOptionEngine plotEngine; 00222 00223 bool initialised; 00224 00225 std::list<Callbackable* > callbackables; 00226 00227 long int t; 00228 }; 00229 00230 #endif /* !WIREDCONTROLLER_H_ */