00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 LpzRobots development team * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00005 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00006 * Ralf Der <ralfder at mis dot mpg dot de> * 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 ***************************************************************************/ 00024 #ifndef __ABSTRACTCONTROLLER_H 00025 #define __ABSTRACTCONTROLLER_H 00026 00027 #ifndef AVR 00028 00029 #include <stdio.h> 00030 #include "configurable.h" 00031 #include "inspectable.h" 00032 #include "storeable.h" 00033 #include "randomgenerator.h" 00034 00035 /** 00036 * Abstract class (interface) for robot controller. 00037 * The controller gets a number of input sensor values each timestep 00038 * and has to generate a number of output motor values. 00039 * 00040 * Interface assumes the following usage: 00041 * - init() is called first to initialise the dimension of sensor- and motor space 00042 * - each time step 00043 * either step() or stepNoLearning() is called to ask the controller for motor values. 00044 */ 00045 class AbstractController : public Configurable, public Inspectable, public Storeable { 00046 public: 00047 typedef double sensor; 00048 typedef double motor; 00049 00050 /// contructor (hint: use $ID$ for revision) 00051 AbstractController(const std::string& name, const std::string& revision) 00052 : Configurable(name, revision), Inspectable(name) {} 00053 00054 /** initialisation of the controller with the given sensor/ motornumber 00055 Must be called before use. The random generator is optional. 00056 */ 00057 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0; 00058 00059 /** @return Number of sensors the controller 00060 was initialised with or 0 if not initialised */ 00061 virtual int getSensorNumber() const= 0; 00062 00063 /** @return Number of motors the controller 00064 was initialised with or 0 if not initialised */ 00065 virtual int getMotorNumber() const= 0; 00066 00067 /** performs one step (includes learning). 00068 Calculates motor commands from sensor inputs. 00069 @param sensors sensors inputs scaled to [-1,1] 00070 @param sensornumber length of the sensor array 00071 @param motors motors outputs. MUST have enough space for motor values! 00072 @param motornumber length of the provided motor array 00073 */ 00074 virtual void step(const sensor* sensors, int sensornumber, 00075 motor* motors, int motornumber)= 0; 00076 /** performs one step without learning. 00077 @see step 00078 */ 00079 virtual void stepNoLearning(const sensor* , int number_sensors, 00080 motor* , int number_motors)= 0; 00081 00082 /** called in motor babbling phase. 00083 the motor values are given (by babbling controller) and 00084 this controller can learn the basic relations from observed sensors/motors 00085 */ 00086 virtual void motorBabblingStep(const sensor* , int number_sensors, 00087 const motor* , int number_motors) {}; 00088 }; 00089 00090 #else /* AVR */ 00091 00092 #include "configurable.h" 00093 #include "inspectable.h" 00094 #include "storeable.h" 00095 #include "randomgenerator.h" 00096 00097 /** 00098 * Abstract class (interface) for robot controller. 00099 * The controller gets a number of input sensor values each timestep 00100 * and has to generate a number of output motor values. 00101 * 00102 * Interface assumes the following usage: 00103 * - init() is called first to initialise the dimension of sensor- and motor space 00104 * - each time step 00105 * either step() or stepNoLearning() is called to ask the controller for motor values. 00106 */ 00107 class AbstractController : public Configurable, public Inspectable, public Storeable { 00108 public: 00109 typedef double sensor; 00110 typedef double motor; 00111 00112 /// contructor (hint: use $ID$ for revision) 00113 AbstractController(const std::string& name, const std::string& revision) 00114 : Configurable(name, revision) {} 00115 00116 /** initialisation of the controller with the given sensor/ motornumber 00117 Must be called before use. The random generator is optional. 00118 */ 00119 virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0)= 0; 00120 00121 /** @return Number of sensors the controller 00122 was initialised with or 0 if not initialised */ 00123 virtual int getSensorNumber() const= 0; 00124 00125 /** @return Number of motors the controller 00126 was initialised with or 0 if not initialised */ 00127 virtual int getMotorNumber() const= 0; 00128 00129 /** performs one step (includes learning). 00130 Calculates motor commands from sensor inputs. 00131 @param sensors sensors inputs scaled to [-1,1] 00132 @param sensornumber length of the sensor array 00133 @param motors motors outputs. MUST have enough space for motor values! 00134 @param motornumber length of the provided motor array 00135 */ 00136 virtual void step(const sensor* sensors, int sensornumber, 00137 motor* motors, int motornumber)= 0; 00138 /** performs one step without learning. 00139 @see step 00140 */ 00141 virtual void stepNoLearning(const sensor* , int number_sensors, 00142 motor* , int number_motors)= 0; 00143 00144 }; 00145 00146 #endif /* !AVR */ 00147 00148 #endif