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: abstractcontroller.h,v $ 00023 * Revision 1.19 2008/08/01 14:42:04 guettler 00024 * we try the trip to hell! make selforg AVR compatible...good luck (first changes) 00025 * 00026 * Revision 1.18 2008/04/17 14:54:44 martius 00027 * randomGen added, which is a random generator with long period and an 00028 * internal state. Each Agent has an instance and passed it to the controller 00029 * and the wiring. This is good for 00030 * a) repeatability on agent basis, 00031 * b) parallel execution as done in ode_robots 00032 * 00033 * Revision 1.17 2007/10/12 16:02:17 martius 00034 * asserts in init() for sensor and motor number 00035 * 00036 * Revision 1.16 2006/08/04 15:16:13 martius 00037 * documentation 00038 * 00039 * Revision 1.15 2006/07/20 17:14:34 martius 00040 * removed std namespace from matrix.h 00041 * storable interface 00042 * abstract model and invertablemodel as superclasses for networks 00043 * 00044 * Revision 1.14 2006/07/14 12:23:57 martius 00045 * selforg becomes HEAD 00046 * 00047 * Revision 1.12.6.4 2006/06/25 21:56:06 martius 00048 * configureable has name and revision 00049 * 00050 * Revision 1.12.6.3 2006/03/30 12:35:12 martius 00051 * documentation updated 00052 * 00053 * Revision 1.12.6.2 2006/01/18 16:48:10 martius 00054 * configurables can be stored and reloaded 00055 * 00056 * Revision 1.12.6.1 2006/01/17 16:58:39 martius 00057 * loading and storing 00058 * 00059 * Revision 1.12 2005/08/06 20:47:54 martius 00060 * Commented 00061 * 00062 * Revision 1.11 2005/08/03 20:28:57 martius 00063 * inspectable interface 00064 * 00065 * Revision 1.10 2005/06/21 15:31:11 martius 00066 * getSensorNumber and getMotorMumber added controller interface 00067 * 00068 * Revision 1.9 2005/06/20 09:04:16 martius 00069 * init function added to controller-interface 00070 * 00071 * Revision 1.8 2005/06/17 10:45:22 martius 00072 * GPL added 00073 * * 00074 ***************************************************************************/ 00075 #ifndef __ABSTRACTCONTROLLER_H 00076 #define __ABSTRACTCONTROLLER_H 00077 00078 #ifndef AVR 00079 00080 #include <stdio.h> 00081 #include "configurable.h" 00082 #include "inspectable.h" 00083 #include "storeable.h" 00084 #include "randomgenerator.h" 00085 00086 /** 00087 * Abstract class (interface) for robot controller. 00088 * The controller gets a number of input sensor values each timestep 00089 * and has to generate a number of output motor values. 00090 * 00091 * Interface assumes the following usage: 00092 * - init() is called first to initialise the dimension of sensor- and motor space 00093 * - each time step 00094 * either step() or stepNoLearning() is called to ask the controller for motor values. 00095 */ 00096 class AbstractController : public Configurable, public Inspectable, public Storeable { 00097 public: 00098 typedef double sensor; 00099 typedef double motor; 00100 00101 /// contructor (hint: use $ID$ for revision) 00102 AbstractController(const std::string& name, const std::string& revision) 00103 : Configurable(name, revision) {} 00104 00105 /** initialisation of the controller with the given sensor/ motornumber 00106 Must be called before use. The random generator is optional. 00107 */ 00108 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0; 00109 00110 /** @return Number of sensors the controller 00111 was initialised with or 0 if not initialised */ 00112 virtual int getSensorNumber() const= 0; 00113 00114 /** @return Number of motors the controller 00115 was initialised with or 0 if not initialised */ 00116 virtual int getMotorNumber() const= 0; 00117 00118 /** performs one step (includes learning). 00119 Calculates motor commands from sensor inputs. 00120 @param sensors sensors inputs scaled to [-1,1] 00121 @param sensornumber length of the sensor array 00122 @param motors motors outputs. MUST have enough space for motor values! 00123 @param motornumber length of the provided motor array 00124 */ 00125 virtual void step(const sensor* sensors, int sensornumber, 00126 motor* motors, int motornumber)= 0; 00127 /** performs one step without learning. 00128 @see step 00129 */ 00130 virtual void stepNoLearning(const sensor* , int number_sensors, 00131 motor* , int number_motors)= 0; 00132 00133 }; 00134 00135 #else /* AVR */ 00136 00137 #include "configurable.h" 00138 #include "inspectable.h" 00139 #include "storeable.h" 00140 #include "randomgenerator.h" 00141 00142 /** 00143 * Abstract class (interface) for robot controller. 00144 * The controller gets a number of input sensor values each timestep 00145 * and has to generate a number of output motor values. 00146 * 00147 * Interface assumes the following usage: 00148 * - init() is called first to initialise the dimension of sensor- and motor space 00149 * - each time step 00150 * either step() or stepNoLearning() is called to ask the controller for motor values. 00151 */ 00152 class AbstractController : public Configurable, public Inspectable, public Storeable { 00153 public: 00154 typedef double sensor; 00155 typedef double motor; 00156 00157 /// contructor (hint: use $ID$ for revision) 00158 AbstractController(const std::string& name, const std::string& revision) 00159 : Configurable(name, revision) {} 00160 00161 /** initialisation of the controller with the given sensor/ motornumber 00162 Must be called before use. The random generator is optional. 00163 */ 00164 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0; 00165 00166 /** @return Number of sensors the controller 00167 was initialised with or 0 if not initialised */ 00168 virtual int getSensorNumber() const= 0; 00169 00170 /** @return Number of motors the controller 00171 was initialised with or 0 if not initialised */ 00172 virtual int getMotorNumber() const= 0; 00173 00174 /** performs one step (includes learning). 00175 Calculates motor commands from sensor inputs. 00176 @param sensors sensors inputs scaled to [-1,1] 00177 @param sensornumber length of the sensor array 00178 @param motors motors outputs. MUST have enough space for motor values! 00179 @param motornumber length of the provided motor array 00180 */ 00181 virtual void step(const sensor* sensors, int sensornumber, 00182 motor* motors, int motornumber)= 0; 00183 /** performs one step without learning. 00184 @see step 00185 */ 00186 virtual void stepNoLearning(const sensor* , int number_sensors, 00187 motor* , int number_motors)= 0; 00188 00189 }; 00190 00191 #endif /* !AVR */ 00192 00193 #endif